| ... | ... | @@ -22,10 +22,9 @@ pub fn main() !void { |
| 22 | 22 | var thread_safe_arena: std.heap.ThreadSafeAllocator = .{ |
| 23 | 23 | .child_allocator = single_threaded_arena.allocator(), |
| 24 | 24 | }; |
| 25 | | const allocator = thread_safe_arena.allocator(); |
| 25 | const arena = thread_safe_arena.allocator(); |
| 26 | 26 | |
| 27 | | var args = try process.argsAlloc(allocator); |
| 28 | | defer process.argsFree(allocator, args); |
| 27 | var args = try process.argsAlloc(arena); |
| 29 | 28 | |
| 30 | 29 | // skip my own exe name |
| 31 | 30 | var arg_idx: usize = 1; |
| ... | ... | @@ -65,7 +64,7 @@ pub fn main() !void { |
| 65 | 64 | }; |
| 66 | 65 | |
| 67 | 66 | var cache: std.Build.Cache = .{ |
| 68 | | .gpa = allocator, |
| 67 | .gpa = arena, |
| 69 | 68 | .manifest_dir = try local_cache_directory.handle.makeOpenPath("h", .{}), |
| 70 | 69 | }; |
| 71 | 70 | cache.addPrefix(.{ .path = null, .handle = std.fs.cwd() }); |
| ... | ... | @@ -75,7 +74,7 @@ pub fn main() !void { |
| 75 | 74 | cache.hash.addBytes(builtin.zig_version_string); |
| 76 | 75 | |
| 77 | 76 | const builder = try std.Build.create( |
| 78 | | allocator, |
| 77 | arena, |
| 79 | 78 | zig_exe, |
| 80 | 79 | build_root_directory, |
| 81 | 80 | local_cache_directory, |
| ... | ... | @@ -85,9 +84,9 @@ pub fn main() !void { |
| 85 | 84 | ); |
| 86 | 85 | defer builder.destroy(); |
| 87 | 86 | |
| 88 | | var targets = ArrayList([]const u8).init(allocator); |
| 89 | | var debug_log_scopes = ArrayList([]const u8).init(allocator); |
| 90 | | var thread_pool_options: std.Thread.Pool.Options = .{ .allocator = allocator }; |
| 87 | var targets = ArrayList([]const u8).init(arena); |
| 88 | var debug_log_scopes = ArrayList([]const u8).init(arena); |
| 89 | var thread_pool_options: std.Thread.Pool.Options = .{ .allocator = arena }; |
| 91 | 90 | |
| 92 | 91 | const stderr_stream = io.getStdErr().writer(); |
| 93 | 92 | const stdout_stream = io.getStdOut().writer(); |
| ... | ... | @@ -274,6 +273,7 @@ pub fn main() !void { |
| 274 | 273 | usageAndErr(builder, true, stderr_stream); |
| 275 | 274 | |
| 276 | 275 | runStepNames( |
| 276 | arena, |
| 277 | 277 | builder, |
| 278 | 278 | targets.items, |
| 279 | 279 | main_progress_node, |
| ... | ... | @@ -286,30 +286,32 @@ pub fn main() !void { |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | fn runStepNames( |
| 289 | arena: std.mem.Allocator, |
| 289 | 290 | b: *std.Build, |
| 290 | 291 | step_names: []const []const u8, |
| 291 | 292 | parent_prog_node: *std.Progress.Node, |
| 292 | 293 | thread_pool_options: std.Thread.Pool.Options, |
| 293 | 294 | ttyconf: std.debug.TTY.Config, |
| 294 | 295 | ) !void { |
| 295 | | var step_stack = ArrayList(*Step).init(b.allocator); |
| 296 | | defer step_stack.deinit(); |
| 296 | const gpa = b.allocator; |
| 297 | var step_stack: std.AutoArrayHashMapUnmanaged(*Step, void) = .{}; |
| 298 | defer step_stack.deinit(gpa); |
| 297 | 299 | |
| 298 | 300 | if (step_names.len == 0) { |
| 299 | | try step_stack.append(b.default_step); |
| 301 | try step_stack.put(gpa, b.default_step, {}); |
| 300 | 302 | } else { |
| 301 | | try step_stack.resize(step_names.len); |
| 302 | | |
| 303 | | for (step_names, 0..) |step_name, i| { |
| 303 | try step_stack.ensureUnusedCapacity(gpa, step_names.len); |
| 304 | for (0..step_names.len) |i| { |
| 305 | const step_name = step_names[step_names.len - i - 1]; |
| 304 | 306 | const s = b.top_level_steps.get(step_name) orelse { |
| 305 | 307 | std.debug.print("no step named '{s}'. Access the help menu with 'zig build -h'\n", .{step_name}); |
| 306 | 308 | process.exit(1); |
| 307 | 309 | }; |
| 308 | | step_stack.items[step_names.len - i - 1] = &s.step; |
| 310 | step_stack.putAssumeCapacity(&s.step, {}); |
| 309 | 311 | } |
| 310 | 312 | } |
| 311 | 313 | |
| 312 | | const starting_steps = try b.allocator.dupe(*Step, step_stack.items); |
| 314 | const starting_steps = try arena.dupe(*Step, step_stack.keys()); |
| 313 | 315 | for (starting_steps) |s| { |
| 314 | 316 | checkForDependencyLoop(b, s, &step_stack) catch |err| switch (err) { |
| 315 | 317 | error.DependencyLoopDetected => return error.UncleanExit, |
| ... | ... | @@ -324,7 +326,7 @@ fn runStepNames( |
| 324 | 326 | { |
| 325 | 327 | defer parent_prog_node.end(); |
| 326 | 328 | |
| 327 | | var step_prog = parent_prog_node.start("run steps", step_stack.items.len); |
| 329 | var step_prog = parent_prog_node.start("run steps", step_stack.count()); |
| 328 | 330 | defer step_prog.end(); |
| 329 | 331 | |
| 330 | 332 | var wait_group: std.Thread.WaitGroup = .{}; |
| ... | ... | @@ -333,10 +335,9 @@ fn runStepNames( |
| 333 | 335 | // Here we spawn the initial set of tasks with a nice heuristic - |
| 334 | 336 | // dependency order. Each worker when it finishes a step will then |
| 335 | 337 | // check whether it should run any dependants. |
| 336 | | var i = step_stack.items.len; |
| 337 | | while (i > 0) { |
| 338 | | i -= 1; |
| 339 | | const step = step_stack.items[i]; |
| 338 | const steps_slice = step_stack.keys(); |
| 339 | for (0..steps_slice.len) |i| { |
| 340 | const step = steps_slice[steps_slice.len - i - 1]; |
| 340 | 341 | |
| 341 | 342 | wait_group.start(); |
| 342 | 343 | thread_pool.spawn(workerMakeOneStep, .{ |
| ... | ... | @@ -350,7 +351,7 @@ fn runStepNames( |
| 350 | 351 | var pending_count: usize = 0; |
| 351 | 352 | var total_compile_errors: usize = 0; |
| 352 | 353 | |
| 353 | | for (step_stack.items) |s| { |
| 354 | for (step_stack.keys()) |s| { |
| 354 | 355 | switch (s.state) { |
| 355 | 356 | .precheck_unstarted => unreachable, |
| 356 | 357 | .precheck_started => unreachable, |
| ... | ... | @@ -404,7 +405,7 @@ fn runStepNames( |
| 404 | 405 | |
| 405 | 406 | // Finally, render compile errors at the bottom of the terminal. |
| 406 | 407 | if (total_compile_errors > 0) { |
| 407 | | for (step_stack.items) |s| { |
| 408 | for (step_stack.keys()) |s| { |
| 408 | 409 | if (s.result_error_bundle.errorMessageCount() > 0) { |
| 409 | 410 | s.result_error_bundle.renderToStdErr(ttyconf); |
| 410 | 411 | } |
| ... | ... | @@ -498,7 +499,7 @@ fn printTreeStep( |
| 498 | 499 | fn checkForDependencyLoop( |
| 499 | 500 | b: *std.Build, |
| 500 | 501 | s: *Step, |
| 501 | | step_stack: *ArrayList(*Step), |
| 502 | step_stack: *std.AutoArrayHashMapUnmanaged(*Step, void), |
| 502 | 503 | ) !void { |
| 503 | 504 | switch (s.state) { |
| 504 | 505 | .precheck_started => { |
| ... | ... | @@ -508,8 +509,9 @@ fn checkForDependencyLoop( |
| 508 | 509 | .precheck_unstarted => { |
| 509 | 510 | s.state = .precheck_started; |
| 510 | 511 | |
| 512 | try step_stack.ensureUnusedCapacity(b.allocator, s.dependencies.items.len); |
| 511 | 513 | for (s.dependencies.items) |dep| { |
| 512 | | try step_stack.append(dep); |
| 514 | try step_stack.put(b.allocator, dep, {}); |
| 513 | 515 | try dep.dependants.append(b.allocator, s); |
| 514 | 516 | checkForDependencyLoop(b, dep, step_stack) catch |err| { |
| 515 | 517 | if (err == error.DependencyLoopDetected) { |