| ... | @@ -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 directory | 4013 | \\ --cache-dir [path] Override path to local Zig cache directory |
| 4014 | \\ --global-cache-dir [path] Override path to global Zig cache directory | 4014 | \\ --global-cache-dir [path] Override path to global Zig cache directory |
| 4015 | \\ --zig-lib-dir [arg] Override path to Zig lib directory | 4015 | \\ --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 read | 4017 | \\ --prominent-compile-errors Output compile errors formatted for a human to read |
| 4017 | \\ -h, --help Print this help and exit | 4018 | \\ -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(); |
| 4199 | | 4206 | |
| 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 | }; |
| 4204 | | 4230 | |
| 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 }; |