| ... | @@ -17,7 +17,7 @@ const process = std.process; | ... | @@ -17,7 +17,7 @@ const process = std.process; |
| 17 | | 17 | |
| 18 | const Fuzz = @import("maker/Fuzz.zig"); | 18 | const Fuzz = @import("maker/Fuzz.zig"); |
| 19 | const Graph = @import("maker/Graph.zig"); | 19 | const Graph = @import("maker/Graph.zig"); |
| 20 | const Step = void; // @import("maker/Step.zig"); | 20 | const Step = @import("maker/Step.zig"); |
| 21 | const Watch = @import("maker/Watch.zig"); | 21 | const Watch = @import("maker/Watch.zig"); |
| 22 | const WebServer = @import("maker/WebServer.zig"); | 22 | const WebServer = @import("maker/WebServer.zig"); |
| 23 | | 23 | |
| ... | @@ -100,8 +100,8 @@ pub fn main(init: process.Init.Minimal) !void { | ... | @@ -100,8 +100,8 @@ pub fn main(init: process.Init.Minimal) !void { |
| 100 | graph.cache.addPrefix(global_cache_directory); | 100 | graph.cache.addPrefix(global_cache_directory); |
| 101 | graph.cache.hash.addBytes(builtin.zig_version_string); | 101 | graph.cache.hash.addBytes(builtin.zig_version_string); |
| 102 | | 102 | |
| 103 | var targets = std.array_list.Managed([]const u8).init(arena); | 103 | var step_names: std.ArrayList([]const u8) = .empty; |
| 104 | var debug_log_scopes = std.array_list.Managed([]const u8).init(arena); | 104 | var debug_log_scopes: std.ArrayList([]const u8) = .empty; |
| 105 | var help_menu = false; | 105 | var help_menu = false; |
| 106 | var steps_menu = false; | 106 | var steps_menu = false; |
| 107 | var print_configuration = false; | 107 | var print_configuration = false; |
| ... | @@ -151,29 +151,6 @@ pub fn main(init: process.Init.Minimal) !void { | ... | @@ -151,29 +151,6 @@ pub fn main(init: process.Init.Minimal) !void { |
| 151 | } | 151 | } |
| 152 | } | 152 | } |
| 153 | | 153 | |
| 154 | const scanned_config: ScannedConfig = sc: { | | |
| 155 | const configuration = c: { | | |
| 156 | var file = cwd.openFile(io, configure_path, .{}) catch |err| | | |
| 157 | fatal("failed to open configuration file {s}: {t}", .{ configure_path, err }); | | |
| 158 | defer file.close(io); | | |
| 159 | break :c Configuration.loadFile(arena, io, file) catch |err| | | |
| 160 | fatal("failed to load configuration file {s}: {t}", .{ configure_path, err }); | | |
| 161 | }; | | |
| 162 | var top_level_steps: std.ArrayList(Configuration.Step.Index) = .empty; | | |
| 163 | for (configuration.steps, 0..) |*conf_step, step_index| { | | |
| 164 | const flags: Configuration.Step.Flags = @bitCast(configuration.extra[conf_step.extra_index]); | | |
| 165 | if (flags.tag == .top_level) { | | |
| 166 | try top_level_steps.append(arena, @enumFromInt(step_index)); | | |
| 167 | } | | |
| 168 | } | | |
| 169 | break :sc .{ | | |
| 170 | .configuration = configuration, | | |
| 171 | .top_level_steps = top_level_steps.items, | | |
| 172 | }; | | |
| 173 | }; | | |
| 174 | | | |
| 175 | log.err("TODO handle user -D options", .{}); | | |
| 176 | | | |
| 177 | while (nextArg(args, &arg_idx)) |arg| { | 154 | while (nextArg(args, &arg_idx)) |arg| { |
| 178 | if (mem.startsWith(u8, arg, "-")) { | 155 | if (mem.startsWith(u8, arg, "-")) { |
| 179 | if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) { | 156 | if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) { |
| ... | @@ -291,7 +268,7 @@ pub fn main(init: process.Init.Minimal) !void { | ... | @@ -291,7 +268,7 @@ pub fn main(init: process.Init.Minimal) !void { |
| 291 | }; | 268 | }; |
| 292 | } else if (mem.eql(u8, arg, "--debug-log")) { | 269 | } else if (mem.eql(u8, arg, "--debug-log")) { |
| 293 | const next_arg = nextArgOrFatal(args, &arg_idx); | 270 | const next_arg = nextArgOrFatal(args, &arg_idx); |
| 294 | try debug_log_scopes.append(next_arg); | 271 | try debug_log_scopes.append(arena, next_arg); |
| 295 | } else if (mem.eql(u8, arg, "--debug-pkg-config")) { | 272 | } else if (mem.eql(u8, arg, "--debug-pkg-config")) { |
| 296 | debug_pkg_config = true; | 273 | debug_pkg_config = true; |
| 297 | } else if (mem.eql(u8, arg, "--debug-rt")) { | 274 | } else if (mem.eql(u8, arg, "--debug-rt")) { |
| ... | @@ -395,7 +372,7 @@ pub fn main(init: process.Init.Minimal) !void { | ... | @@ -395,7 +372,7 @@ pub fn main(init: process.Init.Minimal) !void { |
| 395 | fatalWithHint("unrecognized argument: '{s}'", .{arg}); | 372 | fatalWithHint("unrecognized argument: '{s}'", .{arg}); |
| 396 | } | 373 | } |
| 397 | } else { | 374 | } else { |
| 398 | try targets.append(arg); | 375 | try step_names.append(arena, arg); |
| 399 | } | 376 | } |
| 400 | } | 377 | } |
| 401 | | 378 | |
| ... | @@ -408,6 +385,29 @@ pub fn main(init: process.Init.Minimal) !void { | ... | @@ -408,6 +385,29 @@ pub fn main(init: process.Init.Minimal) !void { |
| 408 | .off => .no_color, | 385 | .off => .no_color, |
| 409 | }; | 386 | }; |
| 410 | | 387 | |
| | 388 | const scanned_config: ScannedConfig = sc: { |
| | 389 | const configuration = c: { |
| | 390 | var file = cwd.openFile(io, configure_path, .{}) catch |err| |
| | 391 | fatal("failed to open configuration file {s}: {t}", .{ configure_path, err }); |
| | 392 | defer file.close(io); |
| | 393 | break :c Configuration.loadFile(arena, io, file) catch |err| |
| | 394 | fatal("failed to load configuration file {s}: {t}", .{ configure_path, err }); |
| | 395 | }; |
| | 396 | var top_level_steps: std.StringArrayHashMapUnmanaged(Configuration.Step.Index) = .empty; |
| | 397 | for (configuration.steps, 0..) |*conf_step, step_index_usize| { |
| | 398 | const step_index: Configuration.Step.Index = @enumFromInt(step_index_usize); |
| | 399 | const flags: Configuration.Step.Flags = @bitCast(configuration.extra[conf_step.extra_index]); |
| | 400 | if (flags.tag == .top_level) { |
| | 401 | const name = step_index.ptr(&configuration).name.slice(&configuration); |
| | 402 | try top_level_steps.put(arena, name, step_index); |
| | 403 | } |
| | 404 | } |
| | 405 | break :sc .{ |
| | 406 | .configuration = configuration, |
| | 407 | .top_level_steps = top_level_steps, |
| | 408 | }; |
| | 409 | }; |
| | 410 | |
| 411 | if (help_menu) { | 411 | if (help_menu) { |
| 412 | var w = initStdoutWriter(io); | 412 | var w = initStdoutWriter(io); |
| 413 | scanned_config.printUsage(&graph, w) catch |err| switch (err) { | 413 | scanned_config.printUsage(&graph, w) catch |err| switch (err) { |
| ... | @@ -467,10 +467,17 @@ pub fn main(init: process.Init.Minimal) !void { | ... | @@ -467,10 +467,17 @@ pub fn main(init: process.Init.Minimal) !void { |
| 467 | .sub_path = cwd_relative, | 467 | .sub_path = cwd_relative, |
| 468 | } else try install_prefix_path.join(arena, "include"); | 468 | } else try install_prefix_path.join(arena, "include"); |
| 469 | | 469 | |
| 470 | if (true) @panic("TODO"); | | |
| 471 | | | |
| 472 | var run: Run = .{ | 470 | var run: Run = .{ |
| 473 | .gpa = gpa, | 471 | .gpa = gpa, |
| | 472 | .graph = &graph, |
| | 473 | .scanned_config = &scanned_config, |
| | 474 | .install_paths = .{ |
| | 475 | .prefix = install_prefix_path, |
| | 476 | .lib = install_lib_path, |
| | 477 | .bin = install_bin_path, |
| | 478 | .include = install_include_path, |
| | 479 | }, |
| | 480 | .steps = try arena.alloc(Step, scanned_config.configuration.steps.len), |
| 474 | | 481 | |
| 475 | .available_rss = max_rss, | 482 | .available_rss = max_rss, |
| 476 | .max_rss_is_default = false, | 483 | .max_rss_is_default = false, |
| ... | @@ -486,13 +493,6 @@ pub fn main(init: process.Init.Minimal) !void { | ... | @@ -486,13 +493,6 @@ pub fn main(init: process.Init.Minimal) !void { |
| 486 | .error_style = error_style, | 493 | .error_style = error_style, |
| 487 | .multiline_errors = multiline_errors, | 494 | .multiline_errors = multiline_errors, |
| 488 | .summary = summary orelse if (watch or webui_listen != null) .line else .failures, | 495 | .summary = summary orelse if (watch or webui_listen != null) .line else .failures, |
| 489 | | | |
| 490 | .install_paths = .{ | | |
| 491 | .prefix = install_prefix_path, | | |
| 492 | .lib = install_lib_path, | | |
| 493 | .bin = install_bin_path, | | |
| 494 | .include = install_include_path, | | |
| 495 | }, | | |
| 496 | }; | 496 | }; |
| 497 | defer { | 497 | defer { |
| 498 | run.memory_blocked_steps.deinit(gpa); | 498 | run.memory_blocked_steps.deinit(gpa); |
| ... | @@ -504,17 +504,16 @@ pub fn main(init: process.Init.Minimal) !void { | ... | @@ -504,17 +504,16 @@ pub fn main(init: process.Init.Minimal) !void { |
| 504 | run.max_rss_is_default = true; | 504 | run.max_rss_is_default = true; |
| 505 | } | 505 | } |
| 506 | | 506 | |
| 507 | prepare(arena, &graph, targets.items, &run) catch |err| switch (err) { | 507 | run.prepare(step_names.items) catch |err| switch (err) { |
| 508 | error.DependencyLoopDetected, error.InsufficientMemory => { | 508 | error.DependencyLoopDetected, error.InsufficientMemory => { |
| 509 | // Perhaps in the future there could be an Advanced Options flag | | |
| 510 | // such as --debug-build-runner-leaks which would make this code | | |
| 511 | // return instead of calling exit. | | |
| 512 | _ = io.lockStderr(&.{}, graph.stderr_mode) catch {}; | 509 | _ = io.lockStderr(&.{}, graph.stderr_mode) catch {}; |
| 513 | process.exit(1); | 510 | process.exit(1); |
| 514 | }, | 511 | }, |
| 515 | else => |e| return e, | 512 | else => |e| return e, |
| 516 | }; | 513 | }; |
| 517 | | 514 | |
| | 515 | if (true) @panic("TODO"); |
| | 516 | |
| 518 | var w: Watch = w: { | 517 | var w: Watch = w: { |
| 519 | if (!watch) break :w undefined; | 518 | if (!watch) break :w undefined; |
| 520 | if (!Watch.have_impl) fatal("--watch not yet implemented for {t}", .{builtin.os.tag}); | 519 | if (!Watch.have_impl) fatal("--watch not yet implemented for {t}", .{builtin.os.tag}); |
| ... | @@ -547,7 +546,7 @@ pub fn main(init: process.Init.Minimal) !void { | ... | @@ -547,7 +546,7 @@ pub fn main(init: process.Init.Minimal) !void { |
| 547 | }) { | 546 | }) { |
| 548 | if (run.web_server) |*ws| ws.startBuild(); | 547 | if (run.web_server) |*ws| ws.startBuild(); |
| 549 | | 548 | |
| 550 | try runStepNames(graph, targets.items, main_progress_node, &run, fuzz); | 549 | try run.makeStepNames(step_names, main_progress_node, fuzz); |
| 551 | | 550 | |
| 552 | if (run.web_server) |*web_server| { | 551 | if (run.web_server) |*web_server| { |
| 553 | if (fuzz) |mode| if (mode != .forever) fatal( | 552 | if (fuzz) |mode| if (mode != .forever) fatal( |
| ... | @@ -628,6 +627,10 @@ fn countSubProcesses(all_steps: []const *Step) usize { | ... | @@ -628,6 +627,10 @@ fn countSubProcesses(all_steps: []const *Step) usize { |
| 628 | | 627 | |
| 629 | const Run = struct { | 628 | const Run = struct { |
| 630 | gpa: Allocator, | 629 | gpa: Allocator, |
| | 630 | graph: *Graph, |
| | 631 | install_paths: InstallPaths, |
| | 632 | scanned_config: *const ScannedConfig, |
| | 633 | steps: []Step, |
| 631 | | 634 | |
| 632 | available_rss: usize, | 635 | available_rss: usize, |
| 633 | max_rss_is_default: bool, | 636 | max_rss_is_default: bool, |
| ... | @@ -637,309 +640,331 @@ const Run = struct { | ... | @@ -637,309 +640,331 @@ const Run = struct { |
| 637 | watch: bool, | 640 | watch: bool, |
| 638 | web_server: if (!builtin.single_threaded) ?WebServer else ?noreturn, | 641 | web_server: if (!builtin.single_threaded) ?WebServer else ?noreturn, |
| 639 | /// Allocated into `gpa`. | 642 | /// Allocated into `gpa`. |
| 640 | memory_blocked_steps: std.ArrayList(*Step), | 643 | memory_blocked_steps: std.ArrayList(Configuration.Step.Index), |
| 641 | /// Allocated into `gpa`. | 644 | /// Allocated into `gpa`. |
| 642 | step_stack: std.AutoArrayHashMapUnmanaged(*Step, void), | 645 | step_stack: std.AutoArrayHashMapUnmanaged(Configuration.Step.Index, void), |
| 643 | | 646 | |
| 644 | error_style: ErrorStyle, | 647 | error_style: ErrorStyle, |
| 645 | multiline_errors: MultilineErrors, | 648 | multiline_errors: MultilineErrors, |
| 646 | summary: Summary, | 649 | summary: Summary, |
| 647 | }; | | |
| 648 | | 650 | |
| 649 | fn prepare(graph: *Graph, step_names: []const []const u8, run: *Run) !void { | 651 | const InstallPaths = struct { |
| 650 | const arena = graph.arena; | 652 | prefix: Path, |
| 651 | const seed: u32 = graph.random_seed; | 653 | lib: Path, |
| 652 | const gpa = run.gpa; | 654 | bin: Path, |
| 653 | const step_stack = &run.step_stack; | 655 | include: Path, |
| | 656 | }; |
| 654 | | 657 | |
| 655 | if (step_names.len == 0) { | 658 | fn stepByIndex(run: *const Run, i: Configuration.Step.Index) *Step { |
| 656 | try step_stack.put(gpa, graph.configuration.default_step, {}); | 659 | return &run.steps[@intFromEnum(i)]; |
| 657 | } else { | | |
| 658 | try step_stack.ensureUnusedCapacity(gpa, step_names.len); | | |
| 659 | for (0..step_names.len) |i| { | | |
| 660 | const step_name = step_names[step_names.len - i - 1]; | | |
| 661 | const s = run.top_level_steps.get(step_name) orelse { | | |
| 662 | log.info("access the help menu with 'zig build -h'", .{}); | | |
| 663 | fatal("no such step: {s}", .{step_name}); | | |
| 664 | }; | | |
| 665 | step_stack.putAssumeCapacity(&s.step, {}); | | |
| 666 | } | | |
| 667 | } | 660 | } |
| 668 | | 661 | |
| 669 | const starting_steps = try arena.dupe(*Step, step_stack.keys()); | 662 | fn prepare(run: *Run, step_names: []const []const u8) !void { |
| | 663 | const gpa = run.gpa; |
| | 664 | const graph = run.graph; |
| | 665 | const arena = graph.arena; |
| | 666 | const seed: u32 = graph.random_seed; |
| | 667 | const step_stack = &run.step_stack; |
| | 668 | const c = &run.scanned_config.configuration; |
| 670 | | 669 | |
| 671 | var rng = std.Random.DefaultPrng.init(seed); | 670 | @memset(run.steps, .{}); |
| 672 | const rand = rng.random(); | | |
| 673 | rand.shuffle(*Step, starting_steps); | | |
| 674 | | 671 | |
| 675 | for (starting_steps) |s| { | 672 | if (step_names.len == 0) { |
| 676 | try constructGraphAndCheckForDependencyLoop(gpa, s, &run.step_stack, rand); | 673 | try step_stack.put(gpa, c.default_step, {}); |
| 677 | } | 674 | } else { |
| | 675 | try step_stack.ensureUnusedCapacity(gpa, step_names.len); |
| | 676 | for (0..step_names.len) |i| { |
| | 677 | const step_name = step_names[step_names.len - i - 1]; |
| | 678 | const s = run.scanned_config.top_level_steps.get(step_name) orelse { |
| | 679 | log.info("to list available steps: zig build -l", .{}); |
| | 680 | fatal("no such step: {s}", .{step_name}); |
| | 681 | }; |
| | 682 | step_stack.putAssumeCapacity(s, {}); |
| | 683 | } |
| | 684 | } |
| 678 | | 685 | |
| 679 | { | 686 | const starting_steps = try arena.dupe(Configuration.Step.Index, step_stack.keys()); |
| 680 | // Check that we have enough memory to complete the build. | 687 | |
| 681 | var any_problems = false; | 688 | var rng = std.Random.DefaultPrng.init(seed); |
| 682 | var max_needed: usize = 0; | 689 | const rand = rng.random(); |
| 683 | for (step_stack.keys()) |s| { | 690 | rand.shuffle(Configuration.Step.Index, starting_steps); |
| 684 | if (s.max_rss == 0) continue; | 691 | |
| 685 | max_needed = @max(max_needed, s.max_rss); | 692 | for (starting_steps) |s| { |
| 686 | if (s.max_rss > run.available_rss) { | 693 | try constructGraphAndCheckForDependencyLoop(gpa, c, run.steps, s, &run.step_stack, rand); |
| 687 | if (run.skip_oom_steps) { | 694 | } |
| 688 | s.state = .skipped_oom; | 695 | |
| 689 | for (s.dependants.items) |dependant| { | 696 | { |
| 690 | dependant.pending_deps -= 1; | 697 | // Check that we have enough memory to complete the build. |
| | 698 | var any_problems = false; |
| | 699 | var max_needed: usize = 0; |
| | 700 | for (step_stack.keys()) |step_index| { |
| | 701 | const make_step = run.stepByIndex(step_index); |
| | 702 | const conf_step = step_index.ptr(c); |
| | 703 | const max_rss = conf_step.max_rss.toBytes(); |
| | 704 | if (max_rss == 0) continue; |
| | 705 | max_needed = @max(max_needed, max_rss); |
| | 706 | if (max_rss > run.available_rss) { |
| | 707 | if (run.skip_oom_steps) { |
| | 708 | make_step.state = .skipped_oom; |
| | 709 | for (make_step.dependants.items) |dependant| { |
| | 710 | dependant.pending_deps -= 1; |
| | 711 | } |
| | 712 | } else { |
| | 713 | log.err("{s}{s}: this step declares an upper bound of {d} bytes of memory, exceeding the available {d} bytes of memory", .{ |
| | 714 | conf_step.owner.depPrefixSlice(c), |
| | 715 | conf_step.name.slice(c), |
| | 716 | max_rss, |
| | 717 | run.available_rss, |
| | 718 | }); |
| | 719 | any_problems = true; |
| 691 | } | 720 | } |
| 692 | } else { | | |
| 693 | std.log.err("{s}{s}: this step declares an upper bound of {d} bytes of memory, exceeding the available {d} bytes of memory", .{ | | |
| 694 | s.owner.dep_prefix, s.name, s.max_rss, run.available_rss, | | |
| 695 | }); | | |
| 696 | any_problems = true; | | |
| 697 | } | 721 | } |
| 698 | } | 722 | } |
| 699 | } | 723 | if (any_problems) { |
| 700 | if (any_problems) { | 724 | if (run.max_rss_is_default) { |
| 701 | if (run.max_rss_is_default) { | 725 | std.log.info("use --maxrss {d} to proceed, risking system memory exhaustion", .{ |
| 702 | std.log.info("use --maxrss {d} to proceed, risking system memory exhaustion", .{ | 726 | max_needed, |
| 703 | max_needed, | 727 | }); |
| 704 | }); | 728 | } |
| | 729 | return error.InsufficientMemory; |
| 705 | } | 730 | } |
| 706 | return error.InsufficientMemory; | | |
| 707 | } | 731 | } |
| 708 | } | 732 | } |
| 709 | } | | |
| 710 | | 733 | |
| 711 | fn runStepNames( | 734 | fn makeStepNames( |
| 712 | graph: *Graph, | 735 | run: *Run, |
| 713 | step_names: []const []const u8, | 736 | step_names: []const []const u8, |
| 714 | parent_prog_node: std.Progress.Node, | 737 | parent_prog_node: std.Progress.Node, |
| 715 | run: *Run, | 738 | fuzz: ?Fuzz.Mode, |
| 716 | fuzz: ?Fuzz.Mode, | 739 | ) !void { |
| 717 | ) !void { | 740 | const graph = run.graph; |
| 718 | const gpa = run.gpa; | 741 | const gpa = run.gpa; |
| 719 | const io = graph.io; | 742 | const io = graph.io; |
| 720 | const step_stack = &run.step_stack; | 743 | const step_stack = &run.step_stack; |
| | 744 | const top_level_steps = &run.scanned_config.top_level_steps; |
| 721 | | 745 | |
| 722 | { | 746 | { |
| 723 | // Collect the initial set of tasks (those with no outstanding dependencies) into a buffer, | 747 | // Collect the initial set of tasks (those with no outstanding dependencies) into a buffer, |
| 724 | // then spawn them. The buffer is so that we don't race with `makeStep` and end up thinking | 748 | // then spawn them. The buffer is so that we don't race with `makeStep` and end up thinking |
| 725 | // a step is initial when it actually became ready due to an earlier initial step. | 749 | // a step is initial when it actually became ready due to an earlier initial step. |
| 726 | var initial_set: std.ArrayList(*Step) = .empty; | 750 | var initial_set: std.ArrayList(*Step) = .empty; |
| 727 | defer initial_set.deinit(gpa); | 751 | defer initial_set.deinit(gpa); |
| 728 | try initial_set.ensureUnusedCapacity(gpa, step_stack.count()); | 752 | try initial_set.ensureUnusedCapacity(gpa, step_stack.count()); |
| 729 | for (step_stack.keys()) |s| { | 753 | for (step_stack.keys()) |s| { |
| 730 | if (s.state == .precheck_done and s.pending_deps == 0) { | 754 | if (s.state == .precheck_done and s.pending_deps == 0) { |
| 731 | initial_set.appendAssumeCapacity(s); | 755 | initial_set.appendAssumeCapacity(s); |
| | 756 | } |
| 732 | } | 757 | } |
| 733 | } | | |
| 734 | | 758 | |
| 735 | const step_prog = parent_prog_node.start("steps", step_stack.count()); | 759 | const step_prog = parent_prog_node.start("steps", step_stack.count()); |
| 736 | defer step_prog.end(); | 760 | defer step_prog.end(); |
| 737 | | 761 | |
| 738 | var group: Io.Group = .init; | 762 | var group: Io.Group = .init; |
| 739 | defer group.cancel(io); | 763 | defer group.cancel(io); |
| 740 | // Start working on all of the initial steps... | 764 | // Start working on all of the initial steps... |
| 741 | for (initial_set.items) |s| try stepReady(&group, s, step_prog, run); | 765 | for (initial_set.items) |s| try stepReady(&group, s, step_prog, run); |
| 742 | // ...and `makeStep` will trigger every other step when their last dependency finishes. | 766 | // ...and `makeStep` will trigger every other step when their last dependency finishes. |
| 743 | try group.await(io); | 767 | try group.await(io); |
| 744 | } | 768 | } |
| 745 | | 769 | |
| 746 | assert(run.memory_blocked_steps.items.len == 0); | 770 | assert(run.memory_blocked_steps.items.len == 0); |
| 747 | | 771 | |
| 748 | var test_pass_count: usize = 0; | 772 | var test_pass_count: usize = 0; |
| 749 | var test_skip_count: usize = 0; | 773 | var test_skip_count: usize = 0; |
| 750 | var test_fail_count: usize = 0; | 774 | var test_fail_count: usize = 0; |
| 751 | var test_crash_count: usize = 0; | 775 | var test_crash_count: usize = 0; |
| 752 | var test_timeout_count: usize = 0; | 776 | var test_timeout_count: usize = 0; |
| 753 | | 777 | |
| 754 | var test_count: usize = 0; | 778 | var test_count: usize = 0; |
| 755 | | 779 | |
| 756 | var success_count: usize = 0; | 780 | var success_count: usize = 0; |
| 757 | var skipped_count: usize = 0; | 781 | var skipped_count: usize = 0; |
| 758 | var failure_count: usize = 0; | 782 | var failure_count: usize = 0; |
| 759 | var pending_count: usize = 0; | 783 | var pending_count: usize = 0; |
| 760 | var total_compile_errors: usize = 0; | 784 | var total_compile_errors: usize = 0; |
| 761 | | 785 | |
| 762 | var cleanup_task = io.async(cleanTmpFiles, .{ io, step_stack.keys() }); | 786 | var cleanup_task = io.async(cleanTmpFiles, .{ io, step_stack.keys() }); |
| 763 | defer cleanup_task.await(io); | 787 | defer cleanup_task.await(io); |
| 764 | | 788 | |
| 765 | for (step_stack.keys()) |s| { | 789 | for (step_stack.keys()) |s| { |
| 766 | test_pass_count += s.test_results.passCount(); | 790 | test_pass_count += s.test_results.passCount(); |
| 767 | test_skip_count += s.test_results.skip_count; | 791 | test_skip_count += s.test_results.skip_count; |
| 768 | test_fail_count += s.test_results.fail_count; | 792 | test_fail_count += s.test_results.fail_count; |
| 769 | test_crash_count += s.test_results.crash_count; | 793 | test_crash_count += s.test_results.crash_count; |
| 770 | test_timeout_count += s.test_results.timeout_count; | 794 | test_timeout_count += s.test_results.timeout_count; |
| 771 | | 795 | |
| 772 | test_count += s.test_results.test_count; | 796 | test_count += s.test_results.test_count; |
| 773 | | 797 | |
| 774 | switch (s.state) { | 798 | switch (s.state) { |
| 775 | .precheck_unstarted => unreachable, | 799 | .precheck_unstarted => unreachable, |
| 776 | .precheck_started => unreachable, | 800 | .precheck_started => unreachable, |
| 777 | .precheck_done => unreachable, | 801 | .precheck_done => unreachable, |
| 778 | .dependency_failure => pending_count += 1, | 802 | .dependency_failure => pending_count += 1, |
| 779 | .success => success_count += 1, | 803 | .success => success_count += 1, |
| 780 | .skipped, .skipped_oom => skipped_count += 1, | 804 | .skipped, .skipped_oom => skipped_count += 1, |
| 781 | .failure => { | 805 | .failure => { |
| 782 | failure_count += 1; | 806 | failure_count += 1; |
| 783 | const compile_errors_len = s.result_error_bundle.errorMessageCount(); | 807 | const compile_errors_len = s.result_error_bundle.errorMessageCount(); |
| 784 | if (compile_errors_len > 0) { | 808 | if (compile_errors_len > 0) { |
| 785 | total_compile_errors += compile_errors_len; | 809 | total_compile_errors += compile_errors_len; |
| 786 | } | 810 | } |
| 787 | }, | 811 | }, |
| 788 | } | 812 | } |
| 789 | } | | |
| 790 | | | |
| 791 | if (fuzz) |mode| blk: { | | |
| 792 | switch (builtin.os.tag) { | | |
| 793 | // Current implementation depends on two things that need to be ported to Windows: | | |
| 794 | // * Memory-mapping to share data between the fuzzer and build runner. | | |
| 795 | // * COFF/PE support added to `std.debug.Info` (it needs a batching API for resolving | | |
| 796 | // many addresses to source locations). | | |
| 797 | .windows => fatal("--fuzz not yet implemented for {t}", .{builtin.os.tag}), | | |
| 798 | else => {}, | | |
| 799 | } | | |
| 800 | if (@bitSizeOf(usize) != 64) { | | |
| 801 | // Current implementation depends on posix.mmap()'s second parameter, `length: usize`, | | |
| 802 | // being compatible with file system's u64 return value. This is not the case | | |
| 803 | // on 32-bit platforms. | | |
| 804 | // Affects or affected by issues #5185, #22523, and #22464. | | |
| 805 | fatal("--fuzz not yet implemented on {d}-bit platforms", .{@bitSizeOf(usize)}); | | |
| 806 | } | 813 | } |
| 807 | | 814 | |
| 808 | switch (mode) { | 815 | if (fuzz) |mode| blk: { |
| 809 | .forever => break :blk, | 816 | switch (builtin.os.tag) { |
| 810 | .limit => {}, | 817 | // Current implementation depends on two things that need to be ported to Windows: |
| 811 | } | 818 | // * Memory-mapping to share data between the fuzzer and build runner. |
| | 819 | // * COFF/PE support added to `std.debug.Info` (it needs a batching API for resolving |
| | 820 | // many addresses to source locations). |
| | 821 | .windows => fatal("--fuzz not yet implemented for {t}", .{builtin.os.tag}), |
| | 822 | else => {}, |
| | 823 | } |
| | 824 | if (@bitSizeOf(usize) != 64) { |
| | 825 | // Current implementation depends on posix.mmap()'s second parameter, `length: usize`, |
| | 826 | // being compatible with file system's u64 return value. This is not the case |
| | 827 | // on 32-bit platforms. |
| | 828 | // Affects or affected by issues #5185, #22523, and #22464. |
| | 829 | fatal("--fuzz not yet implemented on {d}-bit platforms", .{@bitSizeOf(usize)}); |
| | 830 | } |
| 812 | | 831 | |
| 813 | assert(mode == .limit); | 832 | switch (mode) { |
| 814 | var f = Fuzz.init( | 833 | .forever => break :blk, |
| 815 | gpa, | 834 | .limit => {}, |
| 816 | io, | 835 | } |
| 817 | step_stack.keys(), | | |
| 818 | parent_prog_node, | | |
| 819 | mode, | | |
| 820 | ) catch |err| fatal("failed to start fuzzer: {t}", .{err}); | | |
| 821 | defer f.deinit(); | | |
| 822 | | | |
| 823 | f.start(); | | |
| 824 | try f.waitAndPrintReport(); | | |
| 825 | } | | |
| 826 | | 836 | |
| 827 | // Every test has a state | 837 | assert(mode == .limit); |
| 828 | assert(test_pass_count + test_skip_count + test_fail_count + test_crash_count + test_timeout_count == test_count); | 838 | var f = Fuzz.init( |
| | 839 | gpa, |
| | 840 | io, |
| | 841 | step_stack.keys(), |
| | 842 | parent_prog_node, |
| | 843 | mode, |
| | 844 | ) catch |err| fatal("failed to start fuzzer: {t}", .{err}); |
| | 845 | defer f.deinit(); |
| | 846 | |
| | 847 | f.start(); |
| | 848 | try f.waitAndPrintReport(); |
| | 849 | } |
| 829 | | 850 | |
| 830 | if (failure_count == 0) { | 851 | // Every test has a state |
| 831 | std.Progress.setStatus(.success); | 852 | assert(test_pass_count + test_skip_count + test_fail_count + test_crash_count + test_timeout_count == test_count); |
| 832 | } else { | | |
| 833 | std.Progress.setStatus(.failure); | | |
| 834 | } | | |
| 835 | | 853 | |
| 836 | summary: { | 854 | if (failure_count == 0) { |
| 837 | switch (run.summary) { | 855 | std.Progress.setStatus(.success); |
| 838 | .all, .new, .line => {}, | 856 | } else { |
| 839 | .failures => if (failure_count == 0) break :summary, | 857 | std.Progress.setStatus(.failure); |
| 840 | .none => break :summary, | | |
| 841 | } | 858 | } |
| 842 | | 859 | |
| 843 | const stderr = try io.lockStderr(&stdio_buffer_allocation, graph.stderr_mode); | 860 | summary: { |
| 844 | defer io.unlockStderr(); | 861 | switch (run.summary) { |
| 845 | const t = stderr.terminal(); | 862 | .all, .new, .line => {}, |
| 846 | const w = &stderr.file_writer.interface; | 863 | .failures => if (failure_count == 0) break :summary, |
| 847 | | 864 | .none => break :summary, |
| 848 | const total_count = success_count + failure_count + pending_count + skipped_count; | | |
| 849 | t.setColor(.cyan) catch {}; | | |
| 850 | t.setColor(.bold) catch {}; | | |
| 851 | w.writeAll("Build Summary: ") catch {}; | | |
| 852 | t.setColor(.reset) catch {}; | | |
| 853 | w.print("{d}/{d} steps succeeded", .{ success_count, total_count }) catch {}; | | |
| 854 | { | | |
| 855 | t.setColor(.dim) catch {}; | | |
| 856 | var first = true; | | |
| 857 | if (skipped_count > 0) { | | |
| 858 | w.print("{s}{d} skipped", .{ if (first) " (" else ", ", skipped_count }) catch {}; | | |
| 859 | first = false; | | |
| 860 | } | | |
| 861 | if (failure_count > 0) { | | |
| 862 | w.print("{s}{d} failed", .{ if (first) " (" else ", ", failure_count }) catch {}; | | |
| 863 | first = false; | | |
| 864 | } | 865 | } |
| 865 | if (!first) w.writeByte(')') catch {}; | | |
| 866 | t.setColor(.reset) catch {}; | | |
| 867 | } | | |
| 868 | | 866 | |
| 869 | if (test_count > 0) { | 867 | const stderr = try io.lockStderr(&stdio_buffer_allocation, graph.stderr_mode); |
| 870 | w.print("; {d}/{d} tests passed", .{ test_pass_count, test_count }) catch {}; | 868 | defer io.unlockStderr(); |
| 871 | t.setColor(.dim) catch {}; | 869 | const t = stderr.terminal(); |
| 872 | var first = true; | 870 | const w = &stderr.file_writer.interface; |
| 873 | if (test_skip_count > 0) { | 871 | |
| 874 | w.print("{s}{d} skipped", .{ if (first) " (" else ", ", test_skip_count }) catch {}; | 872 | const total_count = success_count + failure_count + pending_count + skipped_count; |
| 875 | first = false; | 873 | t.setColor(.cyan) catch {}; |
| 876 | } | 874 | t.setColor(.bold) catch {}; |
| 877 | if (test_fail_count > 0) { | 875 | w.writeAll("Build Summary: ") catch {}; |
| 878 | w.print("{s}{d} failed", .{ if (first) " (" else ", ", test_fail_count }) catch {}; | 876 | t.setColor(.reset) catch {}; |
| 879 | first = false; | 877 | w.print("{d}/{d} steps succeeded", .{ success_count, total_count }) catch {}; |
| 880 | } | 878 | { |
| 881 | if (test_crash_count > 0) { | 879 | t.setColor(.dim) catch {}; |
| 882 | w.print("{s}{d} crashed", .{ if (first) " (" else ", ", test_crash_count }) catch {}; | 880 | var first = true; |
| 883 | first = false; | 881 | if (skipped_count > 0) { |
| | 882 | w.print("{s}{d} skipped", .{ if (first) " (" else ", ", skipped_count }) catch {}; |
| | 883 | first = false; |
| | 884 | } |
| | 885 | if (failure_count > 0) { |
| | 886 | w.print("{s}{d} failed", .{ if (first) " (" else ", ", failure_count }) catch {}; |
| | 887 | first = false; |
| | 888 | } |
| | 889 | if (!first) w.writeByte(')') catch {}; |
| | 890 | t.setColor(.reset) catch {}; |
| 884 | } | 891 | } |
| 885 | if (test_timeout_count > 0) { | 892 | |
| 886 | w.print("{s}{d} timed out", .{ if (first) " (" else ", ", test_timeout_count }) catch {}; | 893 | if (test_count > 0) { |
| 887 | first = false; | 894 | w.print("; {d}/{d} tests passed", .{ test_pass_count, test_count }) catch {}; |
| | 895 | t.setColor(.dim) catch {}; |
| | 896 | var first = true; |
| | 897 | if (test_skip_count > 0) { |
| | 898 | w.print("{s}{d} skipped", .{ if (first) " (" else ", ", test_skip_count }) catch {}; |
| | 899 | first = false; |
| | 900 | } |
| | 901 | if (test_fail_count > 0) { |
| | 902 | w.print("{s}{d} failed", .{ if (first) " (" else ", ", test_fail_count }) catch {}; |
| | 903 | first = false; |
| | 904 | } |
| | 905 | if (test_crash_count > 0) { |
| | 906 | w.print("{s}{d} crashed", .{ if (first) " (" else ", ", test_crash_count }) catch {}; |
| | 907 | first = false; |
| | 908 | } |
| | 909 | if (test_timeout_count > 0) { |
| | 910 | w.print("{s}{d} timed out", .{ if (first) " (" else ", ", test_timeout_count }) catch {}; |
| | 911 | first = false; |
| | 912 | } |
| | 913 | if (!first) w.writeByte(')') catch {}; |
| | 914 | t.setColor(.reset) catch {}; |
| 888 | } | 915 | } |
| 889 | if (!first) w.writeByte(')') catch {}; | | |
| 890 | t.setColor(.reset) catch {}; | | |
| 891 | } | | |
| 892 | | 916 | |
| 893 | w.writeAll("\n") catch {}; | 917 | w.writeAll("\n") catch {}; |
| 894 | | 918 | |
| 895 | if (run.summary == .line) break :summary; | 919 | if (run.summary == .line) break :summary; |
| 896 | | 920 | |
| 897 | // Print a fancy tree with build results. | 921 | // Print a fancy tree with build results. |
| 898 | var step_stack_copy = try step_stack.clone(gpa); | 922 | var step_stack_copy = try step_stack.clone(gpa); |
| 899 | defer step_stack_copy.deinit(gpa); | 923 | defer step_stack_copy.deinit(gpa); |
| 900 | | 924 | |
| 901 | var print_node: PrintNode = .{ .parent = null }; | 925 | var print_node: PrintNode = .{ .parent = null }; |
| 902 | if (step_names.len == 0) { | 926 | if (step_names.len == 0) { |
| 903 | print_node.last = true; | 927 | print_node.last = true; |
| 904 | printTreeStep(graph, graph.default_step, run, t, &print_node, &step_stack_copy) catch {}; | 928 | printTreeStep(graph, graph.default_step, run, t, &print_node, &step_stack_copy) catch {}; |
| 905 | } else { | 929 | } else { |
| 906 | const last_index = if (run.summary == .all) run.top_level_steps.count() else blk: { | 930 | const last_index = if (run.summary == .all) top_level_steps.count() else blk: { |
| 907 | var i: usize = step_names.len; | 931 | var i: usize = step_names.len; |
| 908 | while (i > 0) { | 932 | while (i > 0) { |
| 909 | i -= 1; | 933 | i -= 1; |
| 910 | const step = run.top_level_steps.get(step_names[i]).?.step; | 934 | const step = top_level_steps.get(step_names[i]).?.step; |
| 911 | const found = switch (run.summary) { | 935 | const found = switch (run.summary) { |
| 912 | .all, .line, .none => unreachable, | 936 | .all, .line, .none => unreachable, |
| 913 | .failures => step.state != .success, | 937 | .failures => step.state != .success, |
| 914 | .new => !step.result_cached, | 938 | .new => !step.result_cached, |
| 915 | }; | 939 | }; |
| 916 | if (found) break :blk i; | 940 | if (found) break :blk i; |
| | 941 | } |
| | 942 | break :blk top_level_steps.count(); |
| | 943 | }; |
| | 944 | for (step_names, 0..) |step_name, i| { |
| | 945 | const tls = top_level_steps.get(step_name).?; |
| | 946 | print_node.last = i + 1 == last_index; |
| | 947 | printTreeStep(graph, &tls.step, run, t, &print_node, &step_stack_copy) catch {}; |
| 917 | } | 948 | } |
| 918 | break :blk run.top_level_steps.count(); | | |
| 919 | }; | | |
| 920 | for (step_names, 0..) |step_name, i| { | | |
| 921 | const tls = run.top_level_steps.get(step_name).?; | | |
| 922 | print_node.last = i + 1 == last_index; | | |
| 923 | printTreeStep(graph, &tls.step, run, t, &print_node, &step_stack_copy) catch {}; | | |
| 924 | } | 949 | } |
| | 950 | w.writeByte('\n') catch {}; |
| 925 | } | 951 | } |
| 926 | w.writeByte('\n') catch {}; | | |
| 927 | } | | |
| 928 | | 952 | |
| 929 | if (run.watch or run.web_server != null) return; | 953 | if (run.watch or run.web_server != null) return; |
| 930 | | 954 | |
| 931 | // Perhaps in the future there could be an Advanced Options flag such as | 955 | // Perhaps in the future there could be an Advanced Options flag such as |
| 932 | // --debug-build-runner-leaks which would make this code return instead of | 956 | // --debug-build-runner-leaks which would make this code return instead of |
| 933 | // calling exit. | 957 | // calling exit. |
| 934 | | 958 | |
| 935 | const code: u8 = code: { | 959 | const code: u8 = code: { |
| 936 | if (failure_count == 0) break :code 0; // success | 960 | if (failure_count == 0) break :code 0; // success |
| 937 | if (run.error_style.verboseContext()) break :code 1; // failure; print build command | 961 | if (run.error_style.verboseContext()) break :code 1; // failure; print build command |
| 938 | break :code 2; // failure; do not print build command | 962 | break :code 2; // failure; do not print build command |
| 939 | }; | 963 | }; |
| 940 | _ = io.lockStderr(&.{}, graph.stderr_mode) catch {}; | 964 | _ = io.lockStderr(&.{}, graph.stderr_mode) catch {}; |
| 941 | process.exit(code); | 965 | process.exit(code); |
| 942 | } | 966 | } |
| | 967 | }; |
| 943 | | 968 | |
| 944 | const PrintNode = struct { | 969 | const PrintNode = struct { |
| 945 | parent: ?*PrintNode, | 970 | parent: ?*PrintNode, |
| ... | @@ -1221,40 +1246,47 @@ fn printTreeStep( | ... | @@ -1221,40 +1246,47 @@ fn printTreeStep( |
| 1221 | /// random order | 1246 | /// random order |
| 1222 | fn constructGraphAndCheckForDependencyLoop( | 1247 | fn constructGraphAndCheckForDependencyLoop( |
| 1223 | gpa: Allocator, | 1248 | gpa: Allocator, |
| 1224 | s: *Step, | 1249 | c: *const Configuration, |
| 1225 | step_stack: *std.AutoArrayHashMapUnmanaged(*Step, void), | 1250 | steps: []Step, |
| | 1251 | step_index: Configuration.Step.Index, |
| | 1252 | step_stack: *std.AutoArrayHashMapUnmanaged(Configuration.Step.Index, void), |
| 1226 | rand: std.Random, | 1253 | rand: std.Random, |
| 1227 | ) !void { | 1254 | ) error{ DependencyLoopDetected, OutOfMemory }!void { |
| | 1255 | const s: *Step = &steps[@intFromEnum(step_index)]; |
| 1228 | switch (s.state) { | 1256 | switch (s.state) { |
| 1229 | .precheck_started => { | 1257 | .precheck_started => { |
| 1230 | std.debug.print("dependency loop detected:\n {s}\n", .{s.name}); | 1258 | log.err("dependency loop detected: {s}", .{step_index.ptr(c).name.slice(c)}); |
| 1231 | return error.DependencyLoopDetected; | 1259 | return error.DependencyLoopDetected; |
| 1232 | }, | 1260 | }, |
| 1233 | .precheck_unstarted => { | 1261 | .precheck_unstarted => { |
| 1234 | s.state = .precheck_started; | 1262 | s.state = .precheck_started; |
| 1235 | | 1263 | |
| 1236 | try step_stack.ensureUnusedCapacity(gpa, s.dependencies.items.len); | 1264 | const step = step_index.ptr(c); |
| | 1265 | const dependencies = step.deps.slice(c); |
| | 1266 | try step_stack.ensureUnusedCapacity(gpa, dependencies.len); |
| 1237 | | 1267 | |
| 1238 | // We dupe to avoid shuffling the steps in the summary, it depends | 1268 | // We dupe to avoid shuffling the steps in the summary, it depends |
| 1239 | // on s.dependencies' order. | 1269 | // on dependencies' order. |
| 1240 | const deps = try gpa.dupe(*Step, s.dependencies.items); | 1270 | const deps = try gpa.dupe(Configuration.Step.Index, dependencies); |
| 1241 | defer gpa.free(deps); | 1271 | defer gpa.free(deps); |
| 1242 | | 1272 | |
| 1243 | rand.shuffle(*Step, deps); | 1273 | rand.shuffle(Configuration.Step.Index, deps); |
| 1244 | | 1274 | |
| 1245 | for (deps) |dep| { | 1275 | for (deps) |dep| { |
| | 1276 | const dep_step: *Step = &steps[@intFromEnum(dep)]; |
| 1246 | try step_stack.put(gpa, dep, {}); | 1277 | try step_stack.put(gpa, dep, {}); |
| 1247 | try dep.dependants.append(gpa, s); | 1278 | try dep_step.dependants.append(gpa, s); |
| 1248 | constructGraphAndCheckForDependencyLoop(gpa, dep, step_stack, rand) catch |err| { | 1279 | constructGraphAndCheckForDependencyLoop(gpa, c, steps, dep, step_stack, rand) catch |err| switch (err) { |
| 1249 | if (err == error.DependencyLoopDetected) { | 1280 | error.DependencyLoopDetected => { |
| 1250 | std.debug.print(" {s}\n", .{s.name}); | 1281 | log.info("needed by: {s}", .{step_index.ptr(c).name.slice(c)}); |
| 1251 | } | 1282 | return err; |
| 1252 | return err; | 1283 | }, |
| | 1284 | else => return err, |
| 1253 | }; | 1285 | }; |
| 1254 | } | 1286 | } |
| 1255 | | 1287 | |
| 1256 | s.state = .precheck_done; | 1288 | s.state = .precheck_done; |
| 1257 | s.pending_deps = @intCast(s.dependencies.items.len); | 1289 | s.pending_deps = @intCast(dependencies.len); |
| 1258 | }, | 1290 | }, |
| 1259 | .precheck_done => {}, | 1291 | .precheck_done => {}, |
| 1260 | | 1292 | |
| ... | @@ -1492,8 +1524,7 @@ fn nextArg(args: []const [:0]const u8, idx: *usize) ?[:0]const u8 { | ... | @@ -1492,8 +1524,7 @@ fn nextArg(args: []const [:0]const u8, idx: *usize) ?[:0]const u8 { |
| 1492 | | 1524 | |
| 1493 | fn nextArgOrFatal(args: []const [:0]const u8, idx: *usize) [:0]const u8 { | 1525 | fn nextArgOrFatal(args: []const [:0]const u8, idx: *usize) [:0]const u8 { |
| 1494 | return nextArg(args, idx) orelse { | 1526 | return nextArg(args, idx) orelse { |
| 1495 | log.info("access the help menu with \"zig build -h\"", .{}); | 1527 | fatalWithHint("expected argument after {q}", .{args[idx.* - 1]}); |
| 1496 | fatal("expected argument after {q}", .{args[idx.* - 1]}); | | |
| 1497 | }; | 1528 | }; |
| 1498 | } | 1529 | } |
| 1499 | | 1530 | |
| ... | @@ -1532,7 +1563,7 @@ const MultilineErrors = enum { indent, newline, none }; | ... | @@ -1532,7 +1563,7 @@ const MultilineErrors = enum { indent, newline, none }; |
| 1532 | const Summary = enum { all, new, failures, line, none }; | 1563 | const Summary = enum { all, new, failures, line, none }; |
| 1533 | | 1564 | |
| 1534 | fn fatalWithHint(comptime f: []const u8, args: anytype) noreturn { | 1565 | fn fatalWithHint(comptime f: []const u8, args: anytype) noreturn { |
| 1535 | log.info("access the help menu with 'zig build -h'", .{}); | 1566 | log.info("to access the help menu: zig build -h", .{}); |
| 1536 | fatal(f, args); | 1567 | fatal(f, args); |
| 1537 | } | 1568 | } |
| 1538 | | 1569 | |
| ... | @@ -1547,13 +1578,6 @@ fn cleanTmpFiles(io: Io, steps: []const *Step) void { | ... | @@ -1547,13 +1578,6 @@ fn cleanTmpFiles(io: Io, steps: []const *Step) void { |
| 1547 | } | 1578 | } |
| 1548 | } | 1579 | } |
| 1549 | | 1580 | |
| 1550 | const InstallPaths = struct { | | |
| 1551 | prefix: Path, | | |
| 1552 | lib: Path, | | |
| 1553 | bin: Path, | | |
| 1554 | include: Path, | | |
| 1555 | }; | | |
| 1556 | | | |
| 1557 | var stdio_buffer_allocation: [256]u8 = undefined; | 1581 | var stdio_buffer_allocation: [256]u8 = undefined; |
| 1558 | var stdout_writer_allocation: Io.File.Writer = undefined; | 1582 | var stdout_writer_allocation: Io.File.Writer = undefined; |
| 1559 | | 1583 | |
| ... | @@ -1564,17 +1588,20 @@ fn initStdoutWriter(io: Io) *Writer { | ... | @@ -1564,17 +1588,20 @@ fn initStdoutWriter(io: Io) *Writer { |
| 1564 | | 1588 | |
| 1565 | const ScannedConfig = struct { | 1589 | const ScannedConfig = struct { |
| 1566 | configuration: Configuration, | 1590 | configuration: Configuration, |
| 1567 | top_level_steps: []const Configuration.Step.Index, | 1591 | top_level_steps: std.StringArrayHashMapUnmanaged(Configuration.Step.Index), |
| 1568 | | 1592 | |
| 1569 | fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void { | 1593 | fn print(sc: *const ScannedConfig, w: *Writer) Writer.Error!void { |
| | 1594 | const c = &sc.configuration; |
| 1570 | var serializer: std.zon.Serializer = .{ .writer = w }; | 1595 | var serializer: std.zon.Serializer = .{ .writer = w }; |
| 1571 | var s = try serializer.beginStruct(.{}); | 1596 | var s = try serializer.beginStruct(.{}); |
| 1572 | | 1597 | |
| 1573 | try s.field("default_step", @intFromEnum(sc.configuration.default_step), .{}); | 1598 | try s.field("default_step", @intFromEnum(c.default_step), .{}); |
| 1574 | { | 1599 | { |
| 1575 | var tuple = try s.beginTupleField("top_level_steps", .{}); | 1600 | var ss = try s.beginStructField("top_level_steps", .{}); |
| 1576 | for (sc.top_level_steps) |step| try tuple.field(@intFromEnum(step), .{}); | 1601 | for (sc.top_level_steps.keys(), sc.top_level_steps.values()) |name, step| { |
| 1577 | try tuple.end(); | 1602 | try ss.field(name, @intFromEnum(step), .{}); |
| | 1603 | } |
| | 1604 | try ss.end(); |
| 1578 | } | 1605 | } |
| 1579 | | 1606 | |
| 1580 | try s.end(); | 1607 | try s.end(); |
| ... | @@ -1583,9 +1610,8 @@ const ScannedConfig = struct { | ... | @@ -1583,9 +1610,8 @@ const ScannedConfig = struct { |
| 1583 | fn printSteps(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void { | 1610 | fn printSteps(sc: *const ScannedConfig, graph: *Graph, w: *Writer) !void { |
| 1584 | const arena = graph.arena; | 1611 | const arena = graph.arena; |
| 1585 | const c = &sc.configuration; | 1612 | const c = &sc.configuration; |
| 1586 | for (sc.top_level_steps) |step_index| { | 1613 | for (sc.top_level_steps.keys(), sc.top_level_steps.values()) |name, step_index| { |
| 1587 | const step = step_index.ptr(c); | 1614 | const step = step_index.ptr(c); |
| 1588 | const name = step.name.slice(c); | | |
| 1589 | const decorated_name = if (step_index == c.default_step) | 1615 | const decorated_name = if (step_index == c.default_step) |
| 1590 | try fmt.allocPrint(arena, "{s} (default)", .{name}) | 1616 | try fmt.allocPrint(arena, "{s} (default)", .{name}) |
| 1591 | else | 1617 | else |
| ... | @@ -1679,8 +1705,8 @@ const ScannedConfig = struct { | ... | @@ -1679,8 +1705,8 @@ const ScannedConfig = struct { |
| 1679 | try w.writeAll( | 1705 | try w.writeAll( |
| 1680 | \\ | 1706 | \\ |
| 1681 | \\General Options: | 1707 | \\General Options: |
| 1682 | \\ -h, --help Print this help and exit | 1708 | \\ -h, --help Print this help to stdout and exit |
| 1683 | \\ -l, --list-steps Print available steps | 1709 | \\ -l, --list-steps Print available steps to stdout and exit |
| 1684 | \\ | 1710 | \\ |
| 1685 | \\ -p, --prefix [path] Where to install files (default: zig-out) | 1711 | \\ -p, --prefix [path] Where to install files (default: zig-out) |
| 1686 | \\ --prefix-lib-dir [path] Where to install libraries | 1712 | \\ --prefix-lib-dir [path] Where to install libraries |