authorgravatar for 19855629+SuperAuguste@users.noreply.github.comAuguste Rame <19855629+SuperAuguste@users.noreply.github.com> 2023-03-01 13:20:01-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-03-01 13:20:01-05:00
log25b83188d06d4cc760c723db0f6ec65db96373f5
treeeb3e4705642a71d9f278c67404ca6f782b7d109f
parenta7a709aaa974c394c001f6d7d9be138cc44fd22d
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Add --build-runner `zig build` option (#14742)


2 files changed, 31 insertions(+), 4 deletions(-)

lib/build_runner.zig+1
......@@ -362,6 +362,7 @@ fn usage(builder: *std.Build, already_ran_build: bool, out_stream: anytype) !voi
362362 \\ --cache-dir [path] Override path to local Zig cache directory
363363 \\ --global-cache-dir [path] Override path to global Zig cache directory
364364 \\ --zig-lib-dir [arg] Override path to Zig lib directory
365 \\ --build-runner [file] Override path to build runner
365366 \\ --debug-log [scope] Enable debugging the compiler
366367 \\ --verbose-link Enable compiler debug output for linking
367368 \\ --verbose-air Enable compiler debug output for Zig AIR
src/main.zig+30-4
......@@ -4013,6 +4013,7 @@ pub const usage_build =
40134013 \\ --cache-dir [path] Override path to local Zig cache directory
40144014 \\ --global-cache-dir [path] Override path to global Zig cache directory
40154015 \\ --zig-lib-dir [arg] Override path to Zig lib directory
4016 \\ --build-runner [file] Override path to build runner
40164017 \\ --prominent-compile-errors Output compile errors formatted for a human to read
40174018 \\ -h, --help Print this help and exit
40184019 \\
......@@ -4031,6 +4032,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
40314032 var override_lib_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LIB_DIR");
40324033 var override_global_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_GLOBAL_CACHE_DIR");
40334034 var override_local_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LOCAL_CACHE_DIR");
4035 var override_build_runner: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_BUILD_RUNNER");
40344036 var child_argv = std.ArrayList([]const u8).init(arena);
40354037 var reference_trace: ?u32 = null;
40364038 var debug_compile_errors = false;
......@@ -4065,6 +4067,11 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
40654067 override_lib_dir = args[i];
40664068 try child_argv.appendSlice(&[_][]const u8{ arg, args[i] });
40674069 continue;
4070 } else if (mem.eql(u8, arg, "--build-runner")) {
4071 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
4072 i += 1;
4073 override_build_runner = args[i];
4074 continue;
40684075 } else if (mem.eql(u8, arg, "--cache-dir")) {
40694076 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
40704077 i += 1;
......@@ -4197,10 +4204,29 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
41974204 try thread_pool.init(gpa);
41984205 defer thread_pool.deinit();
41994206
4200 var main_pkg: Package = .{
4201 .root_src_directory = zig_lib_directory,
4202 .root_src_path = "build_runner.zig",
4203 };
4207 var cleanup_build_runner_dir: ?fs.Dir = null;
4208 defer if (cleanup_build_runner_dir) |*dir| dir.close();
4209
4210 var main_pkg: Package = if (override_build_runner) |build_runner_path|
4211 .{
4212 .root_src_directory = blk: {
4213 if (std.fs.path.dirname(build_runner_path)) |dirname| {
4214 const dir = fs.cwd().openDir(dirname, .{}) catch |err| {
4215 fatal("unable to open directory to build runner from argument 'build-runner', '{s}': {s}", .{ dirname, @errorName(err) });
4216 };
4217 cleanup_build_runner_dir = dir;
4218 break :blk .{ .path = dirname, .handle = dir };
4219 }
4220
4221 break :blk .{ .path = null, .handle = fs.cwd() };
4222 },
4223 .root_src_path = std.fs.path.basename(build_runner_path),
4224 }
4225 else
4226 .{
4227 .root_src_directory = zig_lib_directory,
4228 .root_src_path = "build_runner.zig",
4229 };
42044230
42054231 if (!build_options.omit_pkg_fetching_code) {
42064232 var http_client: std.http.Client = .{ .allocator = gpa };