authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-03-12 17:06:12-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:34-07:00
loga60ffaf5b357cd85200fffba8bd0e98df5f91a16
tree57a82d1cf128c4e22de4db8fe3ade4e58f31db72
parentcc4f205fc3a55eb788b8663fa2817ccd6761a4eb

maker: finish migrating most of CLI lowering code


3 files changed, 246 insertions(+), 218 deletions(-)

BRANCH_TODO+4
......@@ -10,3 +10,7 @@
1010* test a bunch of third party projects / help people migrate
1111* refactor with DefaultingEnum
1212* inspect b4ffb402c082605c4b324e88120306fc8fb3cf32 diff and apply changes as needed (merge conflict)
13
14## Followup Issues
15* link_eh_frame_hdr should be DefaultingBool
16* make --foo, --no-foo CLI args uniform (make them -f args instead)
lib/compiler/Maker/Step/Compile.zig+205-218
......@@ -15,10 +15,10 @@ const allocPrint = std.fmt.allocPrint;
1515const Step = @import("../Step.zig");
1616const Maker = @import("../../Maker.zig");
1717
18/// Populated during the make phase when there is a long-lived compiler process.
19/// Managed by the build runner, not user build script.
18/// Populated when there is compiler process that lives across multiple calls
19/// to `make`.
2020zig_process: ?*Step.ZigProcess = null,
21/// Persisted to reuse memory on subsequent make.
21/// Persisted to reuse memory on subsequent calls to `make`.
2222zig_args: std.ArrayList([]const u8) = .empty,
2323
2424pub fn make(
......@@ -538,28 +538,29 @@ fn lowerZigArgs(
538538 try zig_args.append(gpa, try maker.resolveLazyPathIndexAbs(arena, manifest_file, compile_index));
539539 }
540540
541 if (true) @panic("TODO");
542
543 if (conf_comp.win32_module_definition) |module_file| {
544 try zig_args.append(gpa, module_file.getPath2(step));
541 if (conf_comp.win32_module_definition.value) |module_file| {
542 try zig_args.append(gpa, try maker.resolveLazyPathIndexAbs(arena, module_file, compile_index));
545543 }
546544
547 if (conf_comp.image_base) |image_base| {
548 try zig_args.appendSlice(gpa, &.{
545 if (conf_comp.image_base.value) |image_base| {
546 (try zig_args.addManyAsArray(gpa, 2)).* = .{
549547 "--image-base", try allocPrint(arena, "0x{x}", .{image_base}),
550 });
548 };
551549 }
552550
553 for (conf_comp.filters) |filter| {
554 try zig_args.appendSlice(gpa, &.{ "--test-filter", filter });
551 for (conf_comp.filters.slice) |filter| {
552 (try zig_args.addManyAsArray(gpa, 2)).* = .{ "--test-filter", filter.slice(conf) };
555553 }
556554
557 if (conf_comp.test_runner) |test_runner| {
558 try zig_args.appendSlice(gpa, &.{ "--test-runner", test_runner.path.getPath2(step) });
555 switch (conf_comp.test_runner.u) {
556 .default => {},
557 .simple, .server => |lp| (try zig_args.addManyAsArray(gpa, 2)).* = .{
558 "--test-runner", try maker.resolveLazyPathIndexAbs(arena, lp, compile_index),
559 },
559560 }
560561
561 for (graph.debug_log_scopes) |log_scope| {
562 try zig_args.appendSlice(gpa, &.{ "--debug-log", log_scope });
562 for (graph.debug_log_scopes.items) |log_scope| {
563 (try zig_args.addManyAsArray(gpa, 2)).* = .{ "--debug-log", log_scope };
563564 }
564565
565566 try addBool(gpa, zig_args, "--debug-compile-errors", graph.debug_compile_errors);
......@@ -571,179 +572,172 @@ fn lowerZigArgs(
571572 try addBool(gpa, zig_args, "--verbose-llvm-cpu-features", graph.verbose_llvm_cpu_features);
572573 try addBool(gpa, zig_args, "--time-report", graph.time_report);
573574
574 if (compile.generated_asm != null) try zig_args.append(gpa, "-femit-asm");
575 if (compile.generated_bin == null) try zig_args.append(gpa, "-fno-emit-bin");
576 if (compile.generated_docs != null) try zig_args.append(gpa, "-femit-docs");
577 if (compile.generated_implib != null) try zig_args.append(gpa, "-femit-implib");
578 if (compile.generated_llvm_bc != null) try zig_args.append(gpa, "-femit-llvm-bc");
579 if (compile.generated_llvm_ir != null) try zig_args.append(gpa, "-femit-llvm-ir");
580 if (compile.generated_h != null) try zig_args.append(gpa, "-femit-h");
575 if (conf_comp.generated_bin.value == null) try zig_args.append(gpa, "-fno-emit-bin");
576 if (conf_comp.generated_asm.value != null) try zig_args.append(gpa, "-femit-asm");
577 if (conf_comp.generated_docs.value != null) try zig_args.append(gpa, "-femit-docs");
578 if (conf_comp.generated_implib.value != null) try zig_args.append(gpa, "-femit-implib");
579 if (conf_comp.generated_llvm_bc.value != null) try zig_args.append(gpa, "-femit-llvm-bc");
580 if (conf_comp.generated_llvm_ir.value != null) try zig_args.append(gpa, "-femit-llvm-ir");
581 if (conf_comp.generated_h.value != null) try zig_args.append(gpa, "-femit-h");
581582
582 try addFlag(gpa, zig_args, "formatted-panics", conf_comp.flags.formatted_panics);
583 try addFlag(gpa, zig_args, "formatted-panics", conf_comp.flags2.formatted_panics.toBool());
583584
584 switch (conf_comp.compress_debug_sections) {
585 switch (conf_comp.flags3.compress_debug_sections) {
585586 .none => {},
586587 .zlib => try zig_args.append(gpa, "--compress-debug-sections=zlib"),
587588 .zstd => try zig_args.append(gpa, "--compress-debug-sections=zstd"),
588589 }
589590
590 if (conf_comp.flags.link_eh_frame_hdr) {
591 try zig_args.append(gpa, "--eh-frame-hdr");
592 }
593 if (conf_comp.flags.link_emit_relocs) {
594 try zig_args.append(gpa, "--emit-relocs");
595 }
596 if (conf_comp.flags.link_function_sections) {
597 try zig_args.append(gpa, "-ffunction-sections");
598 }
599 if (conf_comp.flags.link_data_sections) {
600 try zig_args.append(gpa, "-fdata-sections");
601 }
602 if (conf_comp.flags.link_gc_sections) |x| {
591 try addBool(gpa, zig_args, "--eh-frame-hdr", conf_comp.flags.link_eh_frame_hdr);
592 try addBool(gpa, zig_args, "--emit-relocs", conf_comp.flags.link_emit_relocs);
593 try addBool(gpa, zig_args, "-ffunction-sections", conf_comp.flags.link_function_sections);
594 try addBool(gpa, zig_args, "-fdata-sections", conf_comp.flags.link_data_sections);
595
596 if (conf_comp.flags2.link_gc_sections.toBool()) |x|
603597 try zig_args.append(gpa, if (x) "--gc-sections" else "--no-gc-sections");
604 }
605 if (!conf_comp.flags.linker_dynamicbase) {
598
599 if (!conf_comp.flags.linker_dynamicbase)
606600 try zig_args.append(gpa, "--no-dynamicbase");
607 }
608 if (conf_comp.flags.linker_allow_shlib_undefined) |x| {
609 try zig_args.append(gpa, if (x) "-fallow-shlib-undefined" else "-fno-allow-shlib-undefined");
610 }
611 if (conf_comp.flags.link_z_notext) try zig_args.appendSlice(gpa, &.{ "-z", "notext" });
612 if (!conf_comp.flags.link_z_relro) try zig_args.appendSlice(gpa, &.{ "-z", "norelro" });
613 if (conf_comp.flags.link_z_lazy) try zig_args.appendSlice(gpa, &.{ "-z", "lazy" });
614 if (conf_comp.flags.link_z_common_page_size) |size| try zig_args.appendSlice(gpa, &.{
615 "-z",
616 try allocPrint(arena, "common-page-size={d}", .{size}),
617 });
618 if (conf_comp.flags.link_z_max_page_size) |size| try zig_args.appendSlice(gpa, &.{
619 "-z",
620 try allocPrint(arena, "max-page-size={d}", .{size}),
621 });
622 if (conf_comp.flags.link_z_defs) try zig_args.appendSlice(gpa, &.{ "-z", "defs" });
623
624 if (conf_comp.flags.libc_file) |libc_file| {
625 try zig_args.appendSlice(gpa, &.{ "--libc", libc_file.getPath2(step) });
601
602 try addFlag(gpa, zig_args, "allow-shlib-undefined", conf_comp.flags2.linker_allow_shlib_undefined.toBool());
603 if (conf_comp.flags.link_z_notext) (try zig_args.addManyAsArray(gpa, 2)).* = .{ "-z", "notext" };
604 if (!conf_comp.flags.link_z_relro) (try zig_args.addManyAsArray(gpa, 2)).* = .{ "-z", "norelro" };
605 if (conf_comp.flags.link_z_lazy) (try zig_args.addManyAsArray(gpa, 2)).* = .{ "-z", "lazy" };
606 if (conf_comp.link_z_common_page_size.value) |size| (try zig_args.addManyAsArray(gpa, 2)).* = .{
607 "-z", try allocPrint(arena, "common-page-size={d}", .{size}),
608 };
609 if (conf_comp.link_z_max_page_size.value) |size| (try zig_args.addManyAsArray(gpa, 2)).* = .{
610 "-z", try allocPrint(arena, "max-page-size={d}", .{size}),
611 };
612 if (conf_comp.flags.link_z_defs) (try zig_args.addManyAsArray(gpa, 2)).* = .{ "-z", "defs" };
613
614 try zig_args.ensureUnusedCapacity(gpa, 2);
615 if (conf_comp.libc_file.value) |libc_file| {
616 zig_args.appendAssumeCapacity("--libc");
617 zig_args.appendAssumeCapacity(try maker.resolveLazyPathIndexAbs(arena, libc_file, compile_index));
626618 } else if (graph.libc_file) |libc_file| {
627 try zig_args.appendSlice(gpa, &.{ "--libc", libc_file });
619 zig_args.appendAssumeCapacity("--libc");
620 zig_args.appendAssumeCapacity(libc_file);
628621 }
629622
630 try zig_args.append(gpa, "--cache-dir");
631 try zig_args.append(gpa, graph.cache_root.path orelse ".");
623 (try zig_args.addManyAsArray(gpa, 4)).* = .{
624 "--cache-dir", graph.local_cache_root.path orelse ".",
625 "--global-cache-dir", graph.global_cache_root.path orelse ".",
626 };
632627
633 try zig_args.append(gpa, "--global-cache-dir");
634 try zig_args.append(gpa, graph.global_cache_root.path orelse ".");
628 try zig_args.ensureUnusedCapacity(gpa, 1);
629 if (graph.debug_compiler_runtime_libs) |mode| switch (mode) {
630 .Debug => zig_args.appendAssumeCapacity("--debug-rt"),
631 else => zig_args.appendAssumeCapacity(try allocPrint(arena, "--debug-rt={t}", .{mode})),
632 };
635633
636 if (graph.debug_compiler_runtime_libs) |mode|
637 try zig_args.append(gpa, try allocPrint(arena, "--debug-rt={t}", .{mode}));
634 {
635 try zig_args.ensureUnusedCapacity(gpa, 7);
638636
639 try zig_args.appendSlice(gpa, &.{ "--name", conf_comp.root_name.slice(conf) });
637 zig_args.addManyAsArrayAssumeCapacity(2).* = .{ "--name", conf_comp.root_name.slice(conf) };
640638
641 if (compile.linkage) |some| switch (some) {
642 .dynamic => try zig_args.append(gpa, "-dynamic"),
643 .static => try zig_args.append(gpa, "-static"),
644 };
645 if (compile.kind == .lib and compile.linkage != null and compile.linkage.? == .dynamic) {
646 if (compile.version) |version| try zig_args.appendSlice(gpa, &.{
647 "--version", try allocPrint(arena, "{f}", .{version}),
648 });
639 switch (conf_comp.flags2.linkage) {
640 .dynamic => zig_args.appendAssumeCapacity("-dynamic"),
641 .static => zig_args.appendAssumeCapacity("-static"),
642 .default => {},
643 }
649644
650 if (root_module_target.flags.os_tag.isDarwin()) {
651 const install_name = compile.install_name orelse try allocPrint(arena, "@rpath/{s}{s}{s}", .{
652 root_module_target.libPrefix(),
653 compile.name,
654 root_module_target.dynamicLibSuffix(),
655 });
656 try zig_args.appendSlice(gpa, &.{ "-install_name", install_name });
645 if (conf_comp.flags3.kind == .lib and conf_comp.flags2.linkage == .dynamic) {
646 if (conf_comp.version.value) |version| zig_args.addManyAsArrayAssumeCapacity(2).* = .{
647 "--version", version.slice(conf),
648 };
649
650 const os_tag = root_module_target.flags.os_tag.unwrap().?;
651 if (os_tag.isDarwin()) {
652 const abi = root_module_target.flags.abi.unwrap().?;
653 zig_args.addManyAsArrayAssumeCapacity(2).* = .{
654 "-install_name",
655 if (conf_comp.install_name.value) |s| s.slice(conf) else try allocPrint(
656 arena,
657 "@rpath/{s}{s}{s}",
658 .{
659 os_tag.libPrefix(abi),
660 conf_comp.root_name.slice(conf),
661 os_tag.dynamicLibSuffix(),
662 },
663 ),
664 };
665 }
657666 }
658667 }
659668
660 if (compile.entitlements) |entitlements| {
661 try zig_args.appendSlice(gpa, &.{ "--entitlements", entitlements });
662 }
663 if (compile.pagezero_size) |pagezero_size| {
664 const size = try allocPrint(arena, "{x}", .{pagezero_size});
665 try zig_args.appendSlice(gpa, &.{ "-pagezero_size", size });
666 }
667 if (compile.headerpad_size) |headerpad_size| {
668 const size = try allocPrint(arena, "{x}", .{headerpad_size});
669 try zig_args.appendSlice(gpa, &.{ "-headerpad", size });
670 }
671 if (compile.headerpad_max_install_names) {
672 try zig_args.append(gpa, "-headerpad_max_install_names");
673 }
674 if (compile.dead_strip_dylibs) {
675 try zig_args.append(gpa, "-dead_strip_dylibs");
669 if (conf_comp.entitlements.value) |entitlements| {
670 (try zig_args.addManyAsArray(gpa, 2)).* = .{
671 "--entitlements", try maker.resolveLazyPathIndexAbs(arena, entitlements, compile_index),
672 };
676673 }
677 if (compile.force_load_objc) {
678 try zig_args.append(gpa, "-ObjC");
674 if (conf_comp.pagezero_size.value) |pagezero_size| {
675 (try zig_args.addManyAsArray(gpa, 2)).* = .{
676 "-pagezero_size", try allocPrint(arena, "{x}", .{pagezero_size}),
677 };
679678 }
680 if (compile.discard_local_symbols) {
681 try zig_args.append(gpa, "--discard-all");
679 if (conf_comp.headerpad_size.value) |headerpad_size| {
680 (try zig_args.addManyAsArray(gpa, 2)).* = .{
681 "-headerpad", try allocPrint(arena, "{x}", .{headerpad_size}),
682 };
682683 }
684 try addBool(gpa, zig_args, "-headerpad_max_install_names", conf_comp.flags.headerpad_max_install_names);
685 try addBool(gpa, zig_args, "-dead_strip_dylibs", conf_comp.flags.dead_strip_dylibs);
686 try addBool(gpa, zig_args, "-ObjC", conf_comp.flags.force_load_objc);
687 try addBool(gpa, zig_args, "--discard-all", conf_comp.flags.discard_local_symbols);
683688
684 try addFlag(gpa, zig_args, "compiler-rt", compile.bundle_compiler_rt);
685 try addFlag(gpa, zig_args, "ubsan-rt", compile.bundle_ubsan_rt);
686 try addFlag(gpa, zig_args, "dll-export-fns", compile.dll_export_fns);
687 if (compile.rdynamic) {
688 try zig_args.append(gpa, "-rdynamic");
689 }
690 if (compile.import_memory) {
691 try zig_args.append(gpa, "--import-memory");
692 }
693 if (compile.export_memory) {
694 try zig_args.append(gpa, "--export-memory");
695 }
696 if (compile.import_symbols) {
697 try zig_args.append(gpa, "--import-symbols");
698 }
699 if (compile.import_table) {
700 try zig_args.append(gpa, "--import-table");
701 }
702 if (compile.export_table) {
703 try zig_args.append(gpa, "--export-table");
704 }
705 if (compile.initial_memory) |initial_memory| {
706 try zig_args.append(gpa, try allocPrint(arena, "--initial-memory={d}", .{initial_memory}));
707 }
708 if (compile.max_memory) |max_memory| {
709 try zig_args.append(gpa, try allocPrint(arena, "--max-memory={d}", .{max_memory}));
710 }
711 if (compile.shared_memory) {
712 try zig_args.append(gpa, "--shared-memory");
713 }
714 if (compile.global_base) |global_base| {
715 try zig_args.append(gpa, try allocPrint(arena, "--global-base={d}", .{global_base}));
716 }
689 try addFlag(gpa, zig_args, "compiler-rt", conf_comp.flags2.bundle_compiler_rt.toBool());
690 try addFlag(gpa, zig_args, "ubsan-rt", conf_comp.flags2.bundle_ubsan_rt.toBool());
691 try addFlag(gpa, zig_args, "dll-export-fns", conf_comp.flags2.dll_export_fns.toBool());
717692
718 if (compile.wasi_exec_model) |model| {
719 try zig_args.append(gpa, try allocPrint(arena, "-mexec-model={t}", .{model}));
720 }
721 if (compile.linker_script) |linker_script| {
722 try zig_args.append(gpa, "--script");
723 try zig_args.append(gpa, linker_script.getPath2(step));
724 }
693 try addBool(gpa, zig_args, "-rdynamic", conf_comp.flags.rdynamic);
694 try addBool(gpa, zig_args, "--import-memory", conf_comp.flags.import_memory);
695 try addBool(gpa, zig_args, "--export-memory", conf_comp.flags.export_memory);
696 try addBool(gpa, zig_args, "--import-symbols", conf_comp.flags.import_symbols);
697 try addBool(gpa, zig_args, "--import-table", conf_comp.flags.import_table);
698 try addBool(gpa, zig_args, "--export-table", conf_comp.flags.export_table);
699 try addBool(gpa, zig_args, "--shared-memory", conf_comp.flags.shared_memory);
725700
726 if (compile.version_script) |version_script| {
727 try zig_args.append(gpa, "--version-script");
728 try zig_args.append(gpa, version_script.getPath2(step));
701 {
702 try zig_args.ensureUnusedCapacity(gpa, 4);
703 if (conf_comp.initial_memory.value) |initial_memory| {
704 zig_args.appendAssumeCapacity(try allocPrint(arena, "--initial-memory={d}", .{initial_memory}));
705 }
706 if (conf_comp.max_memory.value) |max_memory| {
707 zig_args.appendAssumeCapacity(try allocPrint(arena, "--max-memory={d}", .{max_memory}));
708 }
709 if (conf_comp.global_base.value) |global_base| {
710 zig_args.appendAssumeCapacity(try allocPrint(arena, "--global-base={d}", .{global_base}));
711 }
712 switch (conf_comp.flags3.wasi_exec_model) {
713 .default => {},
714 .command => zig_args.appendAssumeCapacity("-mexec-model=command"),
715 .reactor => zig_args.appendAssumeCapacity("-mexec-model=reactor"),
716 }
729717 }
730 if (compile.linker_allow_undefined_version) |x| {
718
719 if (conf_comp.linker_script.value) |linker_script| (try zig_args.addManyAsArray(gpa, 2)).* = .{
720 "--script", try maker.resolveLazyPathIndexAbs(arena, linker_script, compile_index),
721 };
722 if (conf_comp.version_script.value) |version_script| (try zig_args.addManyAsArray(gpa, 2)).* = .{
723 "--version-script", try maker.resolveLazyPathIndexAbs(arena, version_script, compile_index),
724 };
725 if (conf_comp.flags2.linker_allow_undefined_version.toBool()) |x| {
731726 try zig_args.append(gpa, if (x) "--undefined-version" else "--no-undefined-version");
732727 }
733728
734 if (compile.linker_enable_new_dtags) |enabled| {
729 if (conf_comp.flags2.linker_enable_new_dtags.toBool()) |enabled| {
735730 try zig_args.append(gpa, if (enabled) "--enable-new-dtags" else "--disable-new-dtags");
736731 }
737732
738 if (compile.kind == .@"test") {
739 if (compile.exec_cmd_args) |exec_cmd_args| {
740 for (exec_cmd_args) |cmd_arg| {
741 if (cmd_arg) |arg| {
742 try zig_args.append(gpa, "--test-cmd");
743 try zig_args.append(gpa, arg);
744 } else {
745 try zig_args.append(gpa, "--test-cmd-bin");
746 }
733 if (conf_comp.flags3.kind == .@"test" and conf_comp.exec_cmd_args.slice.len != 0) {
734 for (conf_comp.exec_cmd_args.slice) |cmd_arg| {
735 try zig_args.ensureUnusedCapacity(gpa, 2);
736 if (cmd_arg.slice(conf)) |arg| {
737 zig_args.appendAssumeCapacity("--test-cmd");
738 zig_args.appendAssumeCapacity(arg);
739 } else {
740 zig_args.appendAssumeCapacity("--test-cmd-bin");
747741 }
748742 }
749743 }
......@@ -783,54 +777,52 @@ fn lowerZigArgs(
783777 }
784778 }
785779
786 if (compile.rc_includes != .any) {
787 try zig_args.appendSlice(gpa, &.{ "-rcincludes", @tagName(compile.rc_includes) });
788 }
780 if (conf_comp.flags3.rc_includes != .any) (try zig_args.addManyAsArray(gpa, 2)).* = .{
781 "-rcincludes", @tagName(conf_comp.flags3.rc_includes),
782 };
789783
790 try addFlag(gpa, zig_args, "each-lib-rpath", compile.each_lib_rpath);
784 try addFlag(gpa, zig_args, "each-lib-rpath", conf_comp.flags2.each_lib_rpath.toBool());
791785
792 if (compile.build_id orelse graph.build_id) |build_id| {
786 if (conf_comp.flags3.build_id.unwrap(conf_comp.build_id.value, conf) orelse graph.build_id) |build_id| {
793787 try zig_args.append(gpa, switch (build_id) {
794788 .hexstring => |hs| try allocPrint(arena, "--build-id=0x{x}", .{hs.toSlice()}),
795789 .none, .fast, .uuid, .sha1, .md5 => try allocPrint(arena, "--build-id={t}", .{build_id}),
796790 });
797791 }
798792
799 const opt_zig_lib_dir = if (compile.zig_lib_dir) |dir|
800 dir.getPath2(step)
793 const opt_zig_lib_dir: ?[]const u8 = if (conf_comp.zig_lib_dir.value) |dir|
794 try maker.resolveLazyPathIndexAbs(arena, dir, compile_index)
801795 else if (graph.zig_lib_directory.path) |_|
802796 try allocPrint(arena, "{f}", .{graph.zig_lib_directory})
803797 else
804798 null;
805799
806 if (opt_zig_lib_dir) |zig_lib_dir| {
807 try zig_args.append(gpa, "--zig-lib-dir");
808 try zig_args.append(gpa, zig_lib_dir);
809 }
800 if (opt_zig_lib_dir) |zig_lib_dir| (try zig_args.addManyAsArray(gpa, 2)).* = .{
801 "--zig-lib-dir", zig_lib_dir,
802 };
810803
811 try addFlag(gpa, zig_args, "PIE", compile.pie);
804 try addFlag(gpa, zig_args, "PIE", conf_comp.flags2.pie.toBool());
812805
813 if (compile.lto) |lto| {
814 try zig_args.append(gpa, switch (lto) {
815 .full => "-flto=full",
816 .thin => "-flto=thin",
817 .none => "-fno-lto",
818 });
806 try zig_args.ensureUnusedCapacity(gpa, 1);
807 switch (conf_comp.flags3.lto) {
808 .full => zig_args.appendAssumeCapacity("-flto=full"),
809 .thin => zig_args.appendAssumeCapacity("-flto=thin"),
810 .none => zig_args.appendAssumeCapacity("-fno-lto"),
811 .default => {},
819812 }
820813
821 try addFlag(gpa, zig_args, "sanitize-coverage-trace-pc-guard", compile.sanitize_coverage_trace_pc_guard);
814 try addFlag(gpa, zig_args, "sanitize-coverage-trace-pc-guard", conf_comp.flags2.sanitize_coverage_trace_pc_guard.toBool());
822815
823 if (compile.subsystem) |subsystem| {
824 try zig_args.appendSlice(gpa, &.{ "--subsystem", @tagName(subsystem) });
816 switch (conf_comp.flags3.subsystem) {
817 .default => {},
818 else => |t| (try zig_args.addManyAsArray(gpa, 2)).* = .{ "--subsystem", @tagName(t) },
825819 }
826820
827 if (compile.mingw_unicode_entry_point) {
828 try zig_args.append(gpa, "-municode");
829 }
821 try addBool(gpa, zig_args, "-municode", conf_comp.flags.mingw_unicode_entry_point);
830822
831 if (compile.error_limit orelse graph.error_limit) |err_limit| try zig_args.appendSlice(gpa, &.{
823 if (conf_comp.error_limit.value orelse graph.error_limit) |err_limit| (try zig_args.addManyAsArray(gpa, 2)).* = .{
832824 "--error-limit", try allocPrint(arena, "{d}", .{err_limit}),
833 });
825 };
834826
835827 try addFlag(gpa, zig_args, "incremental", graph.incremental);
836828
......@@ -845,7 +837,10 @@ fn lowerZigArgs(
845837 args_length += arg.len + 1; // +1 to account for null terminator
846838 }
847839 if (args_length >= 30 * 1024) {
848 try graph.cache_root.handle.createDirPath(io, "args");
840 const local_cache_root = graph.local_cache_root;
841 const args_path: Path = .{ .root_dir = local_cache_root, .sub_path = "args" };
842 args_path.root_dir.handle.createDirPath(io, args_path.sub_path) catch |err|
843 return step.fail(maker, "failed creating directory {f}: {t}", .{ args_path, err });
849844
850845 const args_to_escape = zig_args.items[2..];
851846 var escaped_args = try std.array_list.Managed([]const u8).initCapacity(arena, args_to_escape.len);
......@@ -875,51 +870,43 @@ fn lowerZigArgs(
875870 var args_hash: [Sha256.digest_length]u8 = undefined;
876871 Sha256.hash(args, &args_hash, .{});
877872 var args_hex_hash: [Sha256.digest_length * 2]u8 = undefined;
878 _ = try std.fmt.bufPrint(&args_hex_hash, "{x}", .{&args_hash});
873 _ = std.fmt.bufPrint(&args_hex_hash, "{x}", .{&args_hash}) catch unreachable;
879874
880875 const args_file = "args" ++ Dir.path.sep_str ++ args_hex_hash;
881 if (graph.cache_root.handle.access(io, args_file, .{})) |_| {
882 // The args file is already present from a previous run.
883 } else |err| switch (err) {
884 error.FileNotFound => {
885 var af = graph.cache_root.handle.createFileAtomic(io, args_file, .{
886 .replace = false,
887 .make_path = true,
888 }) catch |e| return step.fail(maker, "failed creating tmp args file {f}{s}: {t}", .{
889 graph.cache_root, args_file, e,
890 });
891 defer af.deinit(io);
876 local_cache_root.handle.access(io, args_file, .{}) catch {
877 var af = local_cache_root.handle.createFileAtomic(io, args_file, .{
878 .replace = false,
879 .make_path = true,
880 }) catch |e| return step.fail(maker, "failed creating tmp args file {f}{s}: {t}", .{
881 local_cache_root, args_file, e,
882 });
883 defer af.deinit(io);
892884
893 af.file.writeStreamingAll(io, args) catch |e| {
894 return step.fail(maker, "failed writing args data to tmp file {f}{s}: {t}", .{
895 graph.cache_root, args_file, e,
896 });
897 };
898 // Note we can't clean up this file, not even after build
899 // success, because that might interfere with another build
900 // process that needs the same file.
901 af.link(io) catch |e| switch (e) {
902 error.PathAlreadyExists => {
903 // The args file was created by another concurrent build process.
904 },
905 else => |other_err| return step.fail(maker, "failed linking tmp file {f}{s}: {t}", .{
906 graph.cache_root, args_file, other_err,
907 }),
908 };
909 },
910 else => |other_err| return other_err,
911 }
885 af.file.writeStreamingAll(io, args) catch |e| {
886 return step.fail(maker, "failed writing args data to tmp file {f}{s}: {t}", .{
887 local_cache_root, args_file, e,
888 });
889 };
890 // Note we can't clean up this file, not even after build
891 // success, because that might interfere with another build
892 // process that needs the same file.
893 af.link(io) catch |e| switch (e) {
894 error.PathAlreadyExists => {
895 // The args file was created by another concurrent build process.
896 },
897 else => |other_err| return step.fail(maker, "failed linking tmp file {f}{s}: {t}", .{
898 local_cache_root, args_file, other_err,
899 }),
900 };
901 };
912902
913903 const resolved_args_file = try mem.concat(arena, u8, &.{
914 "@",
915 try graph.cache_root.join(arena, &.{args_file}),
904 "@", try local_cache_root.join(arena, &.{args_file}),
916905 });
917906
918907 zig_args.shrinkRetainingCapacity(2);
919908 try zig_args.append(gpa, resolved_args_file);
920909 }
921
922 return try zig_args.toOwnedSlice();
923910}
924911
925912pub fn rebuildInFuzzMode(compile: *Compile, maker: *Maker, progress_node: std.Progress.Node) !Path {
lib/std/Build/Configuration.zig+37
......@@ -728,6 +728,22 @@ pub const Step = extern struct {
728728 .hexstring => .hexstring,
729729 };
730730 }
731
732 pub fn unwrap(this: @This(), hexstring: ?String, c: *const Configuration) ?std.zig.BuildId {
733 if (hexstring) |h| {
734 assert(this == .hexstring);
735 return .initHexString(h.slice(c));
736 }
737 return switch (this) {
738 .none => .none,
739 .fast => .fast,
740 .uuid => .uuid,
741 .sha1 => .sha1,
742 .md5 => .md5,
743 .hexstring => unreachable,
744 .default => null,
745 };
746 }
731747 };
732748 pub const WasiExecModel = enum(u2) {
733749 default,
......@@ -1425,6 +1441,15 @@ pub const OptionalString = enum(u32) {
14251441 assert(result != .none);
14261442 return result;
14271443 }
1444
1445 pub fn unwrap(this: @This()) ?String {
1446 if (this == .none) return null;
1447 return @enumFromInt(@intFromEnum(this));
1448 }
1449
1450 pub fn slice(this: @This(), c: *const Configuration) ?[:0]const u8 {
1451 return (unwrap(this) orelse return null).slice(c);
1452 }
14281453};
14291454
14301455/// Points into `string_bytes`, null-terminated.
......@@ -1740,6 +1765,12 @@ pub const TargetQuery = struct {
17401765 // TODO comptime assert the enums match
17411766 return @enumFromInt(@intFromEnum(x orelse return .default));
17421767 }
1768
1769 pub fn unwrap(this: @This()) ?std.Target.Abi {
1770 // TODO comptime assert the enums match
1771 if (this == .default) return null;
1772 return @enumFromInt(@intFromEnum(this));
1773 }
17431774 };
17441775 pub const CpuArch = enum(u6) {
17451776 aarch64,
......@@ -1857,6 +1888,12 @@ pub const TargetQuery = struct {
18571888 // TODO comptime assert the enums match
18581889 return @enumFromInt(@intFromEnum(x orelse return .default));
18591890 }
1891
1892 pub fn unwrap(this: @This()) ?std.Target.Os.Tag {
1893 // TODO comptime assert the enums match
1894 if (this == .default) return null;
1895 return @enumFromInt(@intFromEnum(this));
1896 }
18601897 };
18611898 pub const ObjectFormat = enum(u4) {
18621899 c,