| author | |
| committer | |
| log | aec708ce25409f7e5aa9f39568cdf6281e857742 |
| tree | 105348ef6edb7cbea239fdcee31a121d3b42c60f |
| parent | 1dc82c13280ae327faf9448dcaf69960f5f5cad4 |
not needed:
* zig exe path
* zig lib dir
* build root
* local cache root
* global cache root5 files changed, 40 insertions(+), 135 deletions(-)
lib/compiler/Maker/Step/Run.zig+4-1| ... | ... | @@ -189,7 +189,10 @@ pub fn make( |
| 189 | 189 | |
| 190 | 190 | man.hash.add(conf_run.flags.test_runner_mode); |
| 191 | 191 | if (conf_run.flags.test_runner_mode) { |
| 192 | try argv_list.ensureUnusedCapacity(gpa, 2); | |
| 192 | const cache_dir_string = try convertPathArg(run_index, maker, .{ .root_dir = cache_root }); | |
| 193 | ||
| 194 | try argv_list.ensureUnusedCapacity(gpa, 3); | |
| 195 | argv_list.appendAssumeCapacity(try allocPrint(arena, "--cache-dir={s}", .{cache_dir_string})); | |
| 193 | 196 | argv_list.appendAssumeCapacity(try allocPrint(arena, "--seed=0x{x}", .{graph.random_seed})); |
| 194 | 197 | argv_list.appendAssumeCapacity("--listen=-"); |
| 195 | 198 | } |
lib/compiler/configurer.zig+7-59| ... | ... | @@ -39,44 +39,10 @@ pub fn main(init: process.Init.Minimal) !void { |
| 39 | 39 | |
| 40 | 40 | const args = try init.args.toSlice(arena); |
| 41 | 41 | |
| 42 | // Skip own executable name. | |
| 43 | var arg_idx: usize = 1; | |
| 44 | ||
| 45 | const zig_exe = expectArgOrFatal(args, &arg_idx, "--zig"); | |
| 46 | const zig_lib_dir = expectArgOrFatal(args, &arg_idx, "--zig-lib-dir"); | |
| 47 | const build_root = expectArgOrFatal(args, &arg_idx, "--build-root"); | |
| 48 | const local_cache_root = expectArgOrFatal(args, &arg_idx, "--local-cache"); | |
| 49 | const global_cache_root = expectArgOrFatal(args, &arg_idx, "--global-cache"); | |
| 50 | ||
| 51 | const cwd: Io.Dir = .cwd(); | |
| 52 | ||
| 53 | const zig_lib_directory: std.Build.Cache.Directory = .{ | |
| 54 | .path = zig_lib_dir, | |
| 55 | .handle = try cwd.openDir(io, zig_lib_dir, .{}), | |
| 56 | }; | |
| 57 | ||
| 58 | const build_root_directory: std.Build.Cache.Directory = .{ | |
| 59 | .path = build_root, | |
| 60 | .handle = try cwd.openDir(io, build_root, .{}), | |
| 61 | }; | |
| 62 | ||
| 63 | const local_cache_directory: std.Build.Cache.Directory = .{ | |
| 64 | .path = local_cache_root, | |
| 65 | .handle = try cwd.createDirPathOpen(io, local_cache_root, .{}), | |
| 66 | }; | |
| 67 | ||
| 68 | const global_cache_directory: std.Build.Cache.Directory = .{ | |
| 69 | .path = global_cache_root, | |
| 70 | .handle = try cwd.createDirPathOpen(io, global_cache_root, .{}), | |
| 71 | }; | |
| 72 | ||
| 73 | 42 | var graph: std.Build.Graph = .{ |
| 74 | 43 | .io = io, |
| 75 | 44 | .arena = arena, |
| 76 | .zig_exe = zig_exe, | |
| 77 | 45 | .environ_map = try init.environ.createMap(arena), |
| 78 | .global_cache_root = global_cache_directory, | |
| 79 | .zig_lib_directory = zig_lib_directory, | |
| 80 | 46 | // TODO get this from parent process instead |
| 81 | 47 | .host = .{ |
| 82 | 48 | .query = .{}, |
| ... | ... | @@ -96,12 +62,7 @@ pub fn main(init: process.Init.Minimal) !void { |
| 96 | 62 | assert(try graph.wip_configuration.addString("") == .empty); |
| 97 | 63 | assert(try graph.wip_configuration.addString("root") == .root); |
| 98 | 64 | |
| 99 | const builder = try std.Build.create( | |
| 100 | &graph, | |
| 101 | build_root_directory, | |
| 102 | local_cache_directory, | |
| 103 | dependencies.root_deps, | |
| 104 | ); | |
| 65 | const builder = try std.Build.create(&graph, dependencies.root_deps); | |
| 105 | 66 | |
| 106 | 67 | var error_style: ErrorStyle = .verbose; |
| 107 | 68 | var multiline_errors: MultilineErrors = .indent; |
| ... | ... | @@ -119,7 +80,9 @@ pub fn main(init: process.Init.Minimal) !void { |
| 119 | 80 | } |
| 120 | 81 | } |
| 121 | 82 | |
| 122 | while (nextArg(args, &arg_idx)) |arg| { | |
| 83 | var arg_i: usize = 1; // Skip own executable name. | |
| 84 | ||
| 85 | while (nextArg(args, &arg_i)) |arg| { | |
| 123 | 86 | if (mem.cutPrefix(u8, arg, "-D")) |option_contents| { |
| 124 | 87 | if (option_contents.len == 0) |
| 125 | 88 | fatalWithHint("expected option name after '-D'", .{}); |
| ... | ... | @@ -145,7 +108,7 @@ pub fn main(init: process.Init.Minimal) !void { |
| 145 | 108 | }); |
| 146 | 109 | }; |
| 147 | 110 | } else if (mem.eql(u8, arg, "--color")) { |
| 148 | const next_arg = nextArg(args, &arg_idx) orelse | |
| 111 | const next_arg = nextArg(args, &arg_i) orelse | |
| 149 | 112 | fatalWithHint("expected [auto|on|off] after {q}", .{arg}); |
| 150 | 113 | color = std.meta.stringToEnum(Color, next_arg) orelse { |
| 151 | 114 | fatalWithHint("expected [auto|on|off] after {q}, found {q}", .{ |
| ... | ... | @@ -153,13 +116,13 @@ pub fn main(init: process.Init.Minimal) !void { |
| 153 | 116 | }); |
| 154 | 117 | }; |
| 155 | 118 | } else if (mem.eql(u8, arg, "--error-style")) { |
| 156 | const next_arg = nextArg(args, &arg_idx) orelse | |
| 119 | const next_arg = nextArg(args, &arg_i) orelse | |
| 157 | 120 | fatalWithHint("expected style after {q}", .{arg}); |
| 158 | 121 | error_style = std.meta.stringToEnum(ErrorStyle, next_arg) orelse { |
| 159 | 122 | fatalWithHint("expected style after {q}, found {q}", .{ arg, next_arg }); |
| 160 | 123 | }; |
| 161 | 124 | } else if (mem.eql(u8, arg, "--multiline-errors")) { |
| 162 | const next_arg = nextArg(args, &arg_idx) orelse | |
| 125 | const next_arg = nextArg(args, &arg_i) orelse | |
| 163 | 126 | fatalWithHint("expected style after {q}", .{arg}); |
| 164 | 127 | multiline_errors = std.meta.stringToEnum(MultilineErrors, next_arg) orelse { |
| 165 | 128 | fatalWithHint("expected style after {q}, found {q}", .{ arg, next_arg }); |
| ... | ... | @@ -169,8 +132,6 @@ pub fn main(init: process.Init.Minimal) !void { |
| 169 | 132 | // but it is handled by the parent process. The build runner |
| 170 | 133 | // only sees this flag. |
| 171 | 134 | graph.system_package_mode = true; |
| 172 | } else if (mem.eql(u8, arg, "--have-run-args")) { | |
| 173 | graph.have_run_args = true; | |
| 174 | 135 | } else { |
| 175 | 136 | fatalWithHint("unrecognized argument: {q}", .{arg}); |
| 176 | 137 | } |
| ... | ... | @@ -1112,19 +1073,6 @@ fn nextArg(args: []const [:0]const u8, idx: *usize) ?[:0]const u8 { |
| 1112 | 1073 | return args[idx.*]; |
| 1113 | 1074 | } |
| 1114 | 1075 | |
| 1115 | fn nextArgOrFatal(args: []const [:0]const u8, idx: *usize) [:0]const u8 { | |
| 1116 | return nextArg(args, idx) orelse { | |
| 1117 | fatalWithHint("expected argument after: {s}", .{args[idx.* - 1]}); | |
| 1118 | }; | |
| 1119 | } | |
| 1120 | ||
| 1121 | fn expectArgOrFatal(args: []const [:0]const u8, index_ptr: *usize, first: []const u8) []const u8 { | |
| 1122 | const next_arg = nextArg(args, index_ptr) orelse fatal("missing {q} argument", .{first}); | |
| 1123 | if (!mem.eql(u8, first, next_arg)) fatal("expected {q} instead of {q}", .{ first, next_arg }); | |
| 1124 | const arg = nextArg(args, index_ptr) orelse fatal("expected argument after {q}", .{first}); | |
| 1125 | return arg; | |
| 1126 | } | |
| 1127 | ||
| 1128 | 1076 | const ErrorStyle = enum { |
| 1129 | 1077 | verbose, |
| 1130 | 1078 | minimal, |
lib/std/Build.zig+7-27| ... | ... | @@ -36,9 +36,6 @@ invalid_user_input: bool, |
| 36 | 36 | default_step: *Step, |
| 37 | 37 | top_level_steps: std.StringArrayHashMapUnmanaged(*Step.TopLevel), |
| 38 | 38 | install_prefix: []const u8, |
| 39 | /// Path to the directory containing build.zig. | |
| 40 | build_root: Cache.Directory, | |
| 41 | cache_root: Cache.Directory, | |
| 42 | 39 | debug_log_scopes: []const []const u8 = &.{}, |
| 43 | 40 | /// Number of stack frames captured when a `StackTrace` is recorded for debug purposes, |
| 44 | 41 | /// in particular at `Step` creation. |
| ... | ... | @@ -83,10 +80,7 @@ pub const Graph = struct { |
| 83 | 80 | arena: Allocator, |
| 84 | 81 | system_integration_options: std.StringArrayHashMapUnmanaged(SystemLibraryMode) = .empty, |
| 85 | 82 | system_package_mode: bool = false, |
| 86 | zig_exe: []const u8, | |
| 87 | 83 | environ_map: process.Environ.Map, |
| 88 | global_cache_root: Cache.Directory, | |
| 89 | zig_lib_directory: Cache.Directory, | |
| 90 | 84 | needed_lazy_dependencies: std.StringArrayHashMapUnmanaged(void) = .empty, |
| 91 | 85 | /// Information about the native target. Computed before build() is invoked. |
| 92 | 86 | host: ResolvedTarget, |
| ... | ... | @@ -97,10 +91,6 @@ pub const Graph = struct { |
| 97 | 91 | /// respects the '--color' flag. |
| 98 | 92 | stderr_mode: ?Io.Terminal.Mode = null, |
| 99 | 93 | release_mode: ReleaseMode = .off, |
| 100 | /// Whether the user passed in "--" arguments. They can be added to a child | |
| 101 | /// process via `Step.Run` API but cannot be observed in the configure | |
| 102 | /// phase. | |
| 103 | have_run_args: bool = false, | |
| 104 | 94 | |
| 105 | 95 | /// Indexes correspond to `Configuration.GeneratedFileIndex`. |
| 106 | 96 | generated_files: std.ArrayList(*Step), |
| ... | ... | @@ -230,8 +220,6 @@ const TypeId = enum { |
| 230 | 220 | |
| 231 | 221 | pub fn create( |
| 232 | 222 | graph: *Graph, |
| 233 | build_root: Cache.Directory, | |
| 234 | cache_root: Cache.Directory, | |
| 235 | 223 | available_deps: AvailableDeps, |
| 236 | 224 | ) error{OutOfMemory}!*Build { |
| 237 | 225 | const arena = graph.arena; |
| ... | ... | @@ -239,8 +227,6 @@ pub fn create( |
| 239 | 227 | const b = try arena.create(Build); |
| 240 | 228 | b.* = .{ |
| 241 | 229 | .graph = graph, |
| 242 | .build_root = build_root, | |
| 243 | .cache_root = cache_root, | |
| 244 | 230 | .invalid_user_input = false, |
| 245 | 231 | .allocator = arena, |
| 246 | 232 | .user_input_options = UserInputOptionsMap.init(arena), |
| ... | ... | @@ -280,7 +266,6 @@ pub fn create( |
| 280 | 266 | fn createChild( |
| 281 | 267 | parent: *Build, |
| 282 | 268 | dep_name: []const u8, |
| 283 | build_root: Cache.Directory, | |
| 284 | 269 | pkg_hash: []const u8, |
| 285 | 270 | pkg_deps: AvailableDeps, |
| 286 | 271 | user_input_options: UserInputOptionsMap, |
| ... | ... | @@ -312,8 +297,6 @@ fn createChild( |
| 312 | 297 | .invalid_user_input = false, |
| 313 | 298 | .default_step = undefined, |
| 314 | 299 | .top_level_steps = .{}, |
| 315 | .build_root = build_root, | |
| 316 | .cache_root = parent.cache_root, | |
| 317 | 300 | .debug_log_scopes = parent.debug_log_scopes, |
| 318 | 301 | .enable_darling = parent.enable_darling, |
| 319 | 302 | .enable_qemu = parent.enable_qemu, |
| ... | ... | @@ -2036,15 +2019,12 @@ fn dependencyInner( |
| 2036 | 2019 | |
| 2037 | 2020 | const build_root: std.Build.Cache.Directory = .{ |
| 2038 | 2021 | .path = build_root_string, |
| 2039 | .handle = Io.Dir.cwd().openDir(io, build_root_string, .{}) catch |err| { | |
| 2040 | std.debug.print("unable to open '{s}': {s}\n", .{ | |
| 2041 | build_root_string, @errorName(err), | |
| 2042 | }); | |
| 2043 | process.exit(1); | |
| 2044 | }, | |
| 2022 | .handle = Io.Dir.cwd().openDir(io, build_root_string, .{}) catch |err| | |
| 2023 | process.fatal("unable to open {s}: {t}", .{ build_root_string, err }), | |
| 2045 | 2024 | }; |
| 2046 | 2025 | |
| 2047 | const sub_builder = b.createChild(name, build_root, pkg_hash, pkg_deps, user_input_options) catch @panic("unhandled error"); | |
| 2026 | const sub_builder = b.createChild(name, build_root, pkg_hash, pkg_deps, user_input_options) catch | |
| 2027 | @panic("unhandled error"); | |
| 2048 | 2028 | if (build_zig) |bz| { |
| 2049 | 2029 | sub_builder.runBuild(bz) catch @panic("unhandled error"); |
| 2050 | 2030 | |
| ... | ... | @@ -2330,9 +2310,9 @@ pub const InstallDir = union(enum) { |
| 2330 | 2310 | } |
| 2331 | 2311 | }; |
| 2332 | 2312 | |
| 2333 | /// Creates a path leading to a directory inside "tmp" subdirectory of | |
| 2334 | /// `cache_root` which is created on demand and cleaned up by the build runner | |
| 2335 | /// upon success. | |
| 2313 | /// Creates a path leading to a directory inside "tmp" subdirectory of local | |
| 2314 | /// cache which is created on demand and cleaned up by the build runner upon | |
| 2315 | /// success. | |
| 2336 | 2316 | pub fn tmpPath(b: *Build) LazyPath { |
| 2337 | 2317 | const wf = b.addTempFiles(); |
| 2338 | 2318 | return wf.getDirectory(); |
lib/std/Build/Step/Run.zig-2| ... | ... | @@ -215,9 +215,7 @@ pub fn setName(run: *Run, name: []const u8) void { |
| 215 | 215 | |
| 216 | 216 | pub fn enableTestRunnerMode(run: *Run) void { |
| 217 | 217 | if (run.test_runner_mode) return; |
| 218 | const b = run.step.owner; | |
| 219 | 218 | run.stdio = .zig_test; |
| 220 | run.addPrefixedDirectoryArg("--cache-dir=", .{ .cwd_relative = b.cache_root.path orelse "." }); | |
| 221 | 219 | run.test_runner_mode = true; |
| 222 | 220 | } |
| 223 | 221 |
src/main.zig+22-46| ... | ... | @@ -4976,43 +4976,27 @@ fn cmdBuild( |
| 4976 | 4976 | try configure_argv.ensureUnusedCapacity(arena, 16); |
| 4977 | 4977 | try make_argv.ensureUnusedCapacity(arena, 16); |
| 4978 | 4978 | |
| 4979 | _ = configure_argv.addOneAssumeCapacity(); | |
| 4980 | _ = make_argv.addOneAssumeCapacity(); | |
| 4981 | ||
| 4982 | configure_argv.appendAssumeCapacity("--zig"); | |
| 4983 | configure_argv.appendAssumeCapacity(self_exe_path); | |
| 4984 | ||
| 4985 | make_argv.appendAssumeCapacity("--zig"); | |
| 4986 | make_argv.appendAssumeCapacity(self_exe_path); | |
| 4987 | ||
| 4988 | configure_argv.appendAssumeCapacity("--zig-lib-dir"); | |
| 4989 | make_argv.appendAssumeCapacity("--zig-lib-dir"); | |
| 4990 | const argv_index_zig_lib_dir = configure_argv.items.len; | |
| 4991 | _ = configure_argv.addOneAssumeCapacity(); | |
| 4992 | _ = make_argv.addOneAssumeCapacity(); | |
| 4993 | ||
| 4994 | configure_argv.appendAssumeCapacity("--build-root"); | |
| 4995 | make_argv.appendAssumeCapacity("--build-root"); | |
| 4996 | const argv_index_build_file = configure_argv.items.len; | |
| 4997 | _ = configure_argv.addOneAssumeCapacity(); | |
| 4998 | _ = make_argv.addOneAssumeCapacity(); | |
| 4999 | ||
| 5000 | configure_argv.appendAssumeCapacity("--local-cache"); | |
| 5001 | make_argv.appendAssumeCapacity("--local-cache"); | |
| 5002 | const argv_index_cache_dir = configure_argv.items.len; | |
| 5003 | _ = configure_argv.addOneAssumeCapacity(); | |
| 5004 | _ = make_argv.addOneAssumeCapacity(); | |
| 5005 | ||
| 5006 | configure_argv.appendAssumeCapacity("--global-cache"); | |
| 5007 | make_argv.appendAssumeCapacity("--global-cache"); | |
| 5008 | const argv_index_global_cache_dir = configure_argv.items.len; | |
| 5009 | _ = configure_argv.addOneAssumeCapacity(); | |
| 5010 | _ = make_argv.addOneAssumeCapacity(); | |
| 5011 | ||
| 5012 | make_argv.appendSliceAssumeCapacity(&.{ "--configuration", undefined }); | |
| 4979 | _ = configure_argv.addOneAssumeCapacity(); // configurer executable | |
| 4980 | _ = make_argv.addOneAssumeCapacity(); // maker executable | |
| 4981 | ||
| 4982 | make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--zig", self_exe_path }; | |
| 4983 | ||
| 4984 | make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--zig-lib-dir", undefined }; | |
| 4985 | const argv_index_zig_lib_dir = make_argv.items.len - 1; | |
| 4986 | ||
| 4987 | make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--build-root", undefined }; | |
| 4988 | const argv_index_build_file = make_argv.items.len - 1; | |
| 4989 | ||
| 4990 | make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--local-cache", undefined }; | |
| 4991 | const argv_index_cache_dir = make_argv.items.len - 1; | |
| 4992 | ||
| 4993 | make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--global-cache", undefined }; | |
| 4994 | const argv_index_global_cache_dir = make_argv.items.len - 1; | |
| 4995 | ||
| 4996 | make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--configuration", undefined }; | |
| 5013 | 4997 | const argv_index_configuration_file = make_argv.items.len - 1; |
| 5014 | 4998 | |
| 5015 | make_argv.appendSliceAssumeCapacity(&.{ "--seed", default_seed }); | |
| 4999 | make_argv.addManyAsArrayAssumeCapacity(2).* = .{ "--seed", default_seed }; | |
| 5016 | 5000 | const argv_index_seed = make_argv.items.len - 1; |
| 5017 | 5001 | |
| 5018 | 5002 | var color: Color = .auto; |
| ... | ... | @@ -5147,13 +5131,10 @@ fn cmdBuild( |
| 5147 | 5131 | try configure_argv.appendSlice(arena, &.{ arg, args[i] }); |
| 5148 | 5132 | continue; |
| 5149 | 5133 | } else if (mem.cutPrefix(u8, arg, "-j")) |str| { |
| 5150 | const num = std.fmt.parseUnsigned(u32, str, 10) catch |err| { | |
| 5151 | fatal("unable to parse jobs count '{s}': {s}", .{ | |
| 5152 | str, @errorName(err), | |
| 5153 | }); | |
| 5154 | }; | |
| 5134 | const num = std.fmt.parseUnsigned(u32, str, 10) catch |err| | |
| 5135 | fatal("unable to parse jobs count {s}: {t}", .{ str, err }); | |
| 5155 | 5136 | if (num < 1) { |
| 5156 | fatal("number of jobs must be at least 1\n", .{}); | |
| 5137 | fatal("number of jobs must be at least 1", .{}); | |
| 5157 | 5138 | } |
| 5158 | 5139 | n_jobs = num; |
| 5159 | 5140 | } else if (mem.eql(u8, arg, "--seed")) { |
| ... | ... | @@ -5287,11 +5268,6 @@ fn cmdBuild( |
| 5287 | 5268 | } }); |
| 5288 | 5269 | defer _ = make_runner_task.cancel(io) catch {}; |
| 5289 | 5270 | |
| 5290 | configure_argv.items[argv_index_zig_lib_dir] = dirs.zig_lib.path orelse cwd_path; | |
| 5291 | configure_argv.items[argv_index_build_file] = build_root.directory.path orelse cwd_path; | |
| 5292 | configure_argv.items[argv_index_global_cache_dir] = dirs.global_cache.path orelse cwd_path; | |
| 5293 | configure_argv.items[argv_index_cache_dir] = dirs.local_cache.path orelse cwd_path; | |
| 5294 | ||
| 5295 | 5271 | make_argv.items[argv_index_zig_lib_dir] = dirs.zig_lib.path orelse cwd_path; |
| 5296 | 5272 | make_argv.items[argv_index_build_file] = build_root.directory.path orelse cwd_path; |
| 5297 | 5273 | make_argv.items[argv_index_global_cache_dir] = dirs.global_cache.path orelse cwd_path; |