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...@@ -362,6 +362,7 @@ fn usage(builder: *std.Build, already_ran_build: bool, out_stream: anytype) !voi
362 \\ --cache-dir [path] Override path to local Zig cache directory362 \\ --cache-dir [path] Override path to local Zig cache directory
363 \\ --global-cache-dir [path] Override path to global Zig cache directory363 \\ --global-cache-dir [path] Override path to global Zig cache directory
364 \\ --zig-lib-dir [arg] Override path to Zig lib directory364 \\ --zig-lib-dir [arg] Override path to Zig lib directory
365 \\ --build-runner [file] Override path to build runner
365 \\ --debug-log [scope] Enable debugging the compiler366 \\ --debug-log [scope] Enable debugging the compiler
366 \\ --verbose-link Enable compiler debug output for linking367 \\ --verbose-link Enable compiler debug output for linking
367 \\ --verbose-air Enable compiler debug output for Zig AIR368 \\ --verbose-air Enable compiler debug output for Zig AIR
src/main.zig+30-4
...@@ -4013,6 +4013,7 @@ pub const usage_build =...@@ -4013,6 +4013,7 @@ pub const usage_build =
4013 \\ --cache-dir [path] Override path to local Zig cache directory4013 \\ --cache-dir [path] Override path to local Zig cache directory
4014 \\ --global-cache-dir [path] Override path to global Zig cache directory4014 \\ --global-cache-dir [path] Override path to global Zig cache directory
4015 \\ --zig-lib-dir [arg] Override path to Zig lib directory4015 \\ --zig-lib-dir [arg] Override path to Zig lib directory
4016 \\ --build-runner [file] Override path to build runner
4016 \\ --prominent-compile-errors Output compile errors formatted for a human to read4017 \\ --prominent-compile-errors Output compile errors formatted for a human to read
4017 \\ -h, --help Print this help and exit4018 \\ -h, --help Print this help and exit
4018 \\4019 \\
...@@ -4031,6 +4032,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -4031,6 +4032,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
4031 var override_lib_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LIB_DIR");4032 var override_lib_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LIB_DIR");
4032 var override_global_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_GLOBAL_CACHE_DIR");4033 var override_global_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_GLOBAL_CACHE_DIR");
4033 var override_local_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LOCAL_CACHE_DIR");4034 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");
4034 var child_argv = std.ArrayList([]const u8).init(arena);4036 var child_argv = std.ArrayList([]const u8).init(arena);
4035 var reference_trace: ?u32 = null;4037 var reference_trace: ?u32 = null;
4036 var debug_compile_errors = false;4038 var debug_compile_errors = false;
...@@ -4065,6 +4067,11 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -4065,6 +4067,11 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
4065 override_lib_dir = args[i];4067 override_lib_dir = args[i];
4066 try child_argv.appendSlice(&[_][]const u8{ arg, args[i] });4068 try child_argv.appendSlice(&[_][]const u8{ arg, args[i] });
4067 continue;4069 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;
4068 } else if (mem.eql(u8, arg, "--cache-dir")) {4075 } else if (mem.eql(u8, arg, "--cache-dir")) {
4069 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});4076 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
4070 i += 1;4077 i += 1;
...@@ -4197,10 +4204,29 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -4197,10 +4204,29 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
4197 try thread_pool.init(gpa);4204 try thread_pool.init(gpa);
4198 defer thread_pool.deinit();4205 defer thread_pool.deinit();
41994206
4200 var main_pkg: Package = .{4207 var cleanup_build_runner_dir: ?fs.Dir = null;
4201 .root_src_directory = zig_lib_directory,4208 defer if (cleanup_build_runner_dir) |*dir| dir.close();
4202 .root_src_path = "build_runner.zig",4209
4203 };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
4205 if (!build_options.omit_pkg_fetching_code) {4231 if (!build_options.omit_pkg_fetching_code) {
4206 var http_client: std.http.Client = .{ .allocator = gpa };4232 var http_client: std.http.Client = .{ .allocator = gpa };