| ... | @@ -15,10 +15,10 @@ const allocPrint = std.fmt.allocPrint; | ... | @@ -15,10 +15,10 @@ const allocPrint = std.fmt.allocPrint; |
| 15 | const Step = @import("../Step.zig"); | 15 | const Step = @import("../Step.zig"); |
| 16 | const Maker = @import("../../Maker.zig"); | 16 | const Maker = @import("../../Maker.zig"); |
| 17 | | 17 | |
| 18 | /// Populated during the make phase when there is a long-lived compiler process. | 18 | /// Populated when there is compiler process that lives across multiple calls |
| 19 | /// Managed by the build runner, not user build script. | 19 | /// to `make`. |
| 20 | zig_process: ?*Step.ZigProcess = null, | 20 | zig_process: ?*Step.ZigProcess = null, |
| 21 | /// Persisted to reuse memory on subsequent make. | 21 | /// Persisted to reuse memory on subsequent calls to `make`. |
| 22 | zig_args: std.ArrayList([]const u8) = .empty, | 22 | zig_args: std.ArrayList([]const u8) = .empty, |
| 23 | | 23 | |
| 24 | pub fn make( | 24 | pub fn make( |
| ... | @@ -538,28 +538,29 @@ fn lowerZigArgs( | ... | @@ -538,28 +538,29 @@ fn lowerZigArgs( |
| 538 | try zig_args.append(gpa, try maker.resolveLazyPathIndexAbs(arena, manifest_file, compile_index)); | 538 | try zig_args.append(gpa, try maker.resolveLazyPathIndexAbs(arena, manifest_file, compile_index)); |
| 539 | } | 539 | } |
| 540 | | 540 | |
| 541 | if (true) @panic("TODO"); | 541 | if (conf_comp.win32_module_definition.value) |module_file| { |
| 542 | | 542 | try zig_args.append(gpa, try maker.resolveLazyPathIndexAbs(arena, module_file, compile_index)); |
| 543 | if (conf_comp.win32_module_definition) |module_file| { | | |
| 544 | try zig_args.append(gpa, module_file.getPath2(step)); | | |
| 545 | } | 543 | } |
| 546 | | 544 | |
| 547 | if (conf_comp.image_base) |image_base| { | 545 | if (conf_comp.image_base.value) |image_base| { |
| 548 | try zig_args.appendSlice(gpa, &.{ | 546 | (try zig_args.addManyAsArray(gpa, 2)).* = .{ |
| 549 | "--image-base", try allocPrint(arena, "0x{x}", .{image_base}), | 547 | "--image-base", try allocPrint(arena, "0x{x}", .{image_base}), |
| 550 | }); | 548 | }; |
| 551 | } | 549 | } |
| 552 | | 550 | |
| 553 | for (conf_comp.filters) |filter| { | 551 | for (conf_comp.filters.slice) |filter| { |
| 554 | try zig_args.appendSlice(gpa, &.{ "--test-filter", filter }); | 552 | (try zig_args.addManyAsArray(gpa, 2)).* = .{ "--test-filter", filter.slice(conf) }; |
| 555 | } | 553 | } |
| 556 | | 554 | |
| 557 | if (conf_comp.test_runner) |test_runner| { | 555 | switch (conf_comp.test_runner.u) { |
| 558 | try zig_args.appendSlice(gpa, &.{ "--test-runner", test_runner.path.getPath2(step) }); | 556 | .default => {}, |
| | 557 | .simple, .server => |lp| (try zig_args.addManyAsArray(gpa, 2)).* = .{ |
| | 558 | "--test-runner", try maker.resolveLazyPathIndexAbs(arena, lp, compile_index), |
| | 559 | }, |
| 559 | } | 560 | } |
| 560 | | 561 | |
| 561 | for (graph.debug_log_scopes) |log_scope| { | 562 | for (graph.debug_log_scopes.items) |log_scope| { |
| 562 | try zig_args.appendSlice(gpa, &.{ "--debug-log", log_scope }); | 563 | (try zig_args.addManyAsArray(gpa, 2)).* = .{ "--debug-log", log_scope }; |
| 563 | } | 564 | } |
| 564 | | 565 | |
| 565 | try addBool(gpa, zig_args, "--debug-compile-errors", graph.debug_compile_errors); | 566 | try addBool(gpa, zig_args, "--debug-compile-errors", graph.debug_compile_errors); |
| ... | @@ -571,179 +572,172 @@ fn lowerZigArgs( | ... | @@ -571,179 +572,172 @@ fn lowerZigArgs( |
| 571 | try addBool(gpa, zig_args, "--verbose-llvm-cpu-features", graph.verbose_llvm_cpu_features); | 572 | try addBool(gpa, zig_args, "--verbose-llvm-cpu-features", graph.verbose_llvm_cpu_features); |
| 572 | try addBool(gpa, zig_args, "--time-report", graph.time_report); | 573 | try addBool(gpa, zig_args, "--time-report", graph.time_report); |
| 573 | | 574 | |
| 574 | if (compile.generated_asm != null) try zig_args.append(gpa, "-femit-asm"); | 575 | if (conf_comp.generated_bin.value == null) try zig_args.append(gpa, "-fno-emit-bin"); |
| 575 | if (compile.generated_bin == null) try zig_args.append(gpa, "-fno-emit-bin"); | 576 | if (conf_comp.generated_asm.value != null) try zig_args.append(gpa, "-femit-asm"); |
| 576 | if (compile.generated_docs != null) try zig_args.append(gpa, "-femit-docs"); | 577 | if (conf_comp.generated_docs.value != null) try zig_args.append(gpa, "-femit-docs"); |
| 577 | if (compile.generated_implib != null) try zig_args.append(gpa, "-femit-implib"); | 578 | if (conf_comp.generated_implib.value != 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 (conf_comp.generated_llvm_bc.value != 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 (conf_comp.generated_llvm_ir.value != null) try zig_args.append(gpa, "-femit-llvm-ir"); |
| 580 | if (compile.generated_h != null) try zig_args.append(gpa, "-femit-h"); | 581 | if (conf_comp.generated_h.value != null) try zig_args.append(gpa, "-femit-h"); |
| 581 | | 582 | |
| 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()); |
| 583 | | 584 | |
| 584 | switch (conf_comp.compress_debug_sections) { | 585 | switch (conf_comp.flags3.compress_debug_sections) { |
| 585 | .none => {}, | 586 | .none => {}, |
| 586 | .zlib => try zig_args.append(gpa, "--compress-debug-sections=zlib"), | 587 | .zlib => try zig_args.append(gpa, "--compress-debug-sections=zlib"), |
| 587 | .zstd => try zig_args.append(gpa, "--compress-debug-sections=zstd"), | 588 | .zstd => try zig_args.append(gpa, "--compress-debug-sections=zstd"), |
| 588 | } | 589 | } |
| 589 | | 590 | |
| 590 | if (conf_comp.flags.link_eh_frame_hdr) { | 591 | try addBool(gpa, zig_args, "--eh-frame-hdr", conf_comp.flags.link_eh_frame_hdr); |
| 591 | try zig_args.append(gpa, "--eh-frame-hdr"); | 592 | try addBool(gpa, zig_args, "--emit-relocs", conf_comp.flags.link_emit_relocs); |
| 592 | } | 593 | try addBool(gpa, zig_args, "-ffunction-sections", conf_comp.flags.link_function_sections); |
| 593 | if (conf_comp.flags.link_emit_relocs) { | 594 | try addBool(gpa, zig_args, "-fdata-sections", conf_comp.flags.link_data_sections); |
| 594 | try zig_args.append(gpa, "--emit-relocs"); | 595 | |
| 595 | } | 596 | if (conf_comp.flags2.link_gc_sections.toBool()) |x| |
| 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| { | | |
| 603 | try zig_args.append(gpa, if (x) "--gc-sections" else "--no-gc-sections"); | 597 | try zig_args.append(gpa, if (x) "--gc-sections" else "--no-gc-sections"); |
| 604 | } | 598 | |
| 605 | if (!conf_comp.flags.linker_dynamicbase) { | 599 | if (!conf_comp.flags.linker_dynamicbase) |
| 606 | try zig_args.append(gpa, "--no-dynamicbase"); | 600 | try zig_args.append(gpa, "--no-dynamicbase"); |
| 607 | } | 601 | |
| 608 | if (conf_comp.flags.linker_allow_shlib_undefined) |x| { | 602 | try addFlag(gpa, zig_args, "allow-shlib-undefined", conf_comp.flags2.linker_allow_shlib_undefined.toBool()); |
| 609 | try zig_args.append(gpa, if (x) "-fallow-shlib-undefined" else "-fno-allow-shlib-undefined"); | 603 | if (conf_comp.flags.link_z_notext) (try zig_args.addManyAsArray(gpa, 2)).* = .{ "-z", "notext" }; |
| 610 | } | 604 | if (!conf_comp.flags.link_z_relro) (try zig_args.addManyAsArray(gpa, 2)).* = .{ "-z", "norelro" }; |
| 611 | if (conf_comp.flags.link_z_notext) try zig_args.appendSlice(gpa, &.{ "-z", "notext" }); | 605 | if (conf_comp.flags.link_z_lazy) (try zig_args.addManyAsArray(gpa, 2)).* = .{ "-z", "lazy" }; |
| 612 | if (!conf_comp.flags.link_z_relro) try zig_args.appendSlice(gpa, &.{ "-z", "norelro" }); | 606 | if (conf_comp.link_z_common_page_size.value) |size| (try zig_args.addManyAsArray(gpa, 2)).* = .{ |
| 613 | if (conf_comp.flags.link_z_lazy) try zig_args.appendSlice(gpa, &.{ "-z", "lazy" }); | 607 | "-z", try allocPrint(arena, "common-page-size={d}", .{size}), |
| 614 | if (conf_comp.flags.link_z_common_page_size) |size| try zig_args.appendSlice(gpa, &.{ | 608 | }; |
| 615 | "-z", | 609 | if (conf_comp.link_z_max_page_size.value) |size| (try zig_args.addManyAsArray(gpa, 2)).* = .{ |
| 616 | try allocPrint(arena, "common-page-size={d}", .{size}), | 610 | "-z", try allocPrint(arena, "max-page-size={d}", .{size}), |
| 617 | }); | 611 | }; |
| 618 | if (conf_comp.flags.link_z_max_page_size) |size| try zig_args.appendSlice(gpa, &.{ | 612 | if (conf_comp.flags.link_z_defs) (try zig_args.addManyAsArray(gpa, 2)).* = .{ "-z", "defs" }; |
| 619 | "-z", | 613 | |
| 620 | try allocPrint(arena, "max-page-size={d}", .{size}), | 614 | try zig_args.ensureUnusedCapacity(gpa, 2); |
| 621 | }); | 615 | if (conf_comp.libc_file.value) |libc_file| { |
| 622 | if (conf_comp.flags.link_z_defs) try zig_args.appendSlice(gpa, &.{ "-z", "defs" }); | 616 | zig_args.appendAssumeCapacity("--libc"); |
| 623 | | 617 | zig_args.appendAssumeCapacity(try maker.resolveLazyPathIndexAbs(arena, libc_file, compile_index)); |
| 624 | if (conf_comp.flags.libc_file) |libc_file| { | | |
| 625 | try zig_args.appendSlice(gpa, &.{ "--libc", libc_file.getPath2(step) }); | | |
| 626 | } else if (graph.libc_file) |libc_file| { | 618 | } 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); |
| 628 | } | 621 | } |
| 629 | | 622 | |
| 630 | try zig_args.append(gpa, "--cache-dir"); | 623 | (try zig_args.addManyAsArray(gpa, 4)).* = .{ |
| 631 | try zig_args.append(gpa, graph.cache_root.path orelse "."); | 624 | "--cache-dir", graph.local_cache_root.path orelse ".", |
| | 625 | "--global-cache-dir", graph.global_cache_root.path orelse ".", |
| | 626 | }; |
| 632 | | 627 | |
| 633 | try zig_args.append(gpa, "--global-cache-dir"); | 628 | try zig_args.ensureUnusedCapacity(gpa, 1); |
| 634 | try zig_args.append(gpa, graph.global_cache_root.path orelse "."); | 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 | }; |
| 635 | | 633 | |
| 636 | if (graph.debug_compiler_runtime_libs) |mode| | 634 | { |
| 637 | try zig_args.append(gpa, try allocPrint(arena, "--debug-rt={t}", .{mode})); | 635 | try zig_args.ensureUnusedCapacity(gpa, 7); |
| 638 | | 636 | |
| 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) }; |
| 640 | | 638 | |
| 641 | if (compile.linkage) |some| switch (some) { | 639 | switch (conf_comp.flags2.linkage) { |
| 642 | .dynamic => try zig_args.append(gpa, "-dynamic"), | 640 | .dynamic => zig_args.appendAssumeCapacity("-dynamic"), |
| 643 | .static => try zig_args.append(gpa, "-static"), | 641 | .static => zig_args.appendAssumeCapacity("-static"), |
| 644 | }; | 642 | .default => {}, |
| 645 | if (compile.kind == .lib and compile.linkage != null and compile.linkage.? == .dynamic) { | 643 | } |
| 646 | if (compile.version) |version| try zig_args.appendSlice(gpa, &.{ | | |
| 647 | "--version", try allocPrint(arena, "{f}", .{version}), | | |
| 648 | }); | | |
| 649 | | 644 | |
| 650 | if (root_module_target.flags.os_tag.isDarwin()) { | 645 | if (conf_comp.flags3.kind == .lib and conf_comp.flags2.linkage == .dynamic) { |
| 651 | const install_name = compile.install_name orelse try allocPrint(arena, "@rpath/{s}{s}{s}", .{ | 646 | if (conf_comp.version.value) |version| zig_args.addManyAsArrayAssumeCapacity(2).* = .{ |
| 652 | root_module_target.libPrefix(), | 647 | "--version", version.slice(conf), |
| 653 | compile.name, | 648 | }; |
| 654 | root_module_target.dynamicLibSuffix(), | 649 | |
| 655 | }); | 650 | const os_tag = root_module_target.flags.os_tag.unwrap().?; |
| 656 | try zig_args.appendSlice(gpa, &.{ "-install_name", install_name }); | 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 | } |
| 657 | } | 666 | } |
| 658 | } | 667 | } |
| 659 | | 668 | |
| 660 | if (compile.entitlements) |entitlements| { | 669 | if (conf_comp.entitlements.value) |entitlements| { |
| 661 | try zig_args.appendSlice(gpa, &.{ "--entitlements", entitlements }); | 670 | (try zig_args.addManyAsArray(gpa, 2)).* = .{ |
| 662 | } | 671 | "--entitlements", try maker.resolveLazyPathIndexAbs(arena, entitlements, compile_index), |
| 663 | if (compile.pagezero_size) |pagezero_size| { | 672 | }; |
| 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"); | | |
| 676 | } | 673 | } |
| 677 | if (compile.force_load_objc) { | 674 | if (conf_comp.pagezero_size.value) |pagezero_size| { |
| 678 | try zig_args.append(gpa, "-ObjC"); | 675 | (try zig_args.addManyAsArray(gpa, 2)).* = .{ |
| | 676 | "-pagezero_size", try allocPrint(arena, "{x}", .{pagezero_size}), |
| | 677 | }; |
| 679 | } | 678 | } |
| 680 | if (compile.discard_local_symbols) { | 679 | if (conf_comp.headerpad_size.value) |headerpad_size| { |
| 681 | try zig_args.append(gpa, "--discard-all"); | 680 | (try zig_args.addManyAsArray(gpa, 2)).* = .{ |
| | 681 | "-headerpad", try allocPrint(arena, "{x}", .{headerpad_size}), |
| | 682 | }; |
| 682 | } | 683 | } |
| | 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); |
| 683 | | 688 | |
| 684 | try addFlag(gpa, zig_args, "compiler-rt", compile.bundle_compiler_rt); | 689 | try addFlag(gpa, zig_args, "compiler-rt", conf_comp.flags2.bundle_compiler_rt.toBool()); |
| 685 | try addFlag(gpa, zig_args, "ubsan-rt", compile.bundle_ubsan_rt); | 690 | try addFlag(gpa, zig_args, "ubsan-rt", conf_comp.flags2.bundle_ubsan_rt.toBool()); |
| 686 | try addFlag(gpa, zig_args, "dll-export-fns", compile.dll_export_fns); | 691 | try addFlag(gpa, zig_args, "dll-export-fns", conf_comp.flags2.dll_export_fns.toBool()); |
| 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 | } | | |
| 717 | | 692 | |
| 718 | if (compile.wasi_exec_model) |model| { | 693 | try addBool(gpa, zig_args, "-rdynamic", conf_comp.flags.rdynamic); |
| 719 | try zig_args.append(gpa, try allocPrint(arena, "-mexec-model={t}", .{model})); | 694 | try addBool(gpa, zig_args, "--import-memory", conf_comp.flags.import_memory); |
| 720 | } | 695 | try addBool(gpa, zig_args, "--export-memory", conf_comp.flags.export_memory); |
| 721 | if (compile.linker_script) |linker_script| { | 696 | try addBool(gpa, zig_args, "--import-symbols", conf_comp.flags.import_symbols); |
| 722 | try zig_args.append(gpa, "--script"); | 697 | try addBool(gpa, zig_args, "--import-table", conf_comp.flags.import_table); |
| 723 | try zig_args.append(gpa, linker_script.getPath2(step)); | 698 | try addBool(gpa, zig_args, "--export-table", conf_comp.flags.export_table); |
| 724 | } | 699 | try addBool(gpa, zig_args, "--shared-memory", conf_comp.flags.shared_memory); |
| 725 | | 700 | |
| 726 | if (compile.version_script) |version_script| { | 701 | { |
| 727 | try zig_args.append(gpa, "--version-script"); | 702 | try zig_args.ensureUnusedCapacity(gpa, 4); |
| 728 | try zig_args.append(gpa, version_script.getPath2(step)); | 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 | } |
| 729 | } | 717 | } |
| 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| { |
| 731 | try zig_args.append(gpa, if (x) "--undefined-version" else "--no-undefined-version"); | 726 | try zig_args.append(gpa, if (x) "--undefined-version" else "--no-undefined-version"); |
| 732 | } | 727 | } |
| 733 | | 728 | |
| 734 | if (compile.linker_enable_new_dtags) |enabled| { | 729 | if (conf_comp.flags2.linker_enable_new_dtags.toBool()) |enabled| { |
| 735 | try zig_args.append(gpa, if (enabled) "--enable-new-dtags" else "--disable-new-dtags"); | 730 | try zig_args.append(gpa, if (enabled) "--enable-new-dtags" else "--disable-new-dtags"); |
| 736 | } | 731 | } |
| 737 | | 732 | |
| 738 | if (compile.kind == .@"test") { | 733 | if (conf_comp.flags3.kind == .@"test" and conf_comp.exec_cmd_args.slice.len != 0) { |
| 739 | if (compile.exec_cmd_args) |exec_cmd_args| { | 734 | for (conf_comp.exec_cmd_args.slice) |cmd_arg| { |
| 740 | for (exec_cmd_args) |cmd_arg| { | 735 | try zig_args.ensureUnusedCapacity(gpa, 2); |
| 741 | if (cmd_arg) |arg| { | 736 | if (cmd_arg.slice(conf)) |arg| { |
| 742 | try zig_args.append(gpa, "--test-cmd"); | 737 | zig_args.appendAssumeCapacity("--test-cmd"); |
| 743 | try zig_args.append(gpa, arg); | 738 | zig_args.appendAssumeCapacity(arg); |
| 744 | } else { | 739 | } else { |
| 745 | try zig_args.append(gpa, "--test-cmd-bin"); | 740 | zig_args.appendAssumeCapacity("--test-cmd-bin"); |
| 746 | } | | |
| 747 | } | 741 | } |
| 748 | } | 742 | } |
| 749 | } | 743 | } |
| ... | @@ -783,54 +777,52 @@ fn lowerZigArgs( | ... | @@ -783,54 +777,52 @@ fn lowerZigArgs( |
| 783 | } | 777 | } |
| 784 | } | 778 | } |
| 785 | | 779 | |
| 786 | if (compile.rc_includes != .any) { | 780 | if (conf_comp.flags3.rc_includes != .any) (try zig_args.addManyAsArray(gpa, 2)).* = .{ |
| 787 | try zig_args.appendSlice(gpa, &.{ "-rcincludes", @tagName(compile.rc_includes) }); | 781 | "-rcincludes", @tagName(conf_comp.flags3.rc_includes), |
| 788 | } | 782 | }; |
| 789 | | 783 | |
| 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()); |
| 791 | | 785 | |
| 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| { |
| 793 | try zig_args.append(gpa, switch (build_id) { | 787 | try zig_args.append(gpa, switch (build_id) { |
| 794 | .hexstring => |hs| try allocPrint(arena, "--build-id=0x{x}", .{hs.toSlice()}), | 788 | .hexstring => |hs| try allocPrint(arena, "--build-id=0x{x}", .{hs.toSlice()}), |
| 795 | .none, .fast, .uuid, .sha1, .md5 => try allocPrint(arena, "--build-id={t}", .{build_id}), | 789 | .none, .fast, .uuid, .sha1, .md5 => try allocPrint(arena, "--build-id={t}", .{build_id}), |
| 796 | }); | 790 | }); |
| 797 | } | 791 | } |
| 798 | | 792 | |
| 799 | const opt_zig_lib_dir = if (compile.zig_lib_dir) |dir| | 793 | const opt_zig_lib_dir: ?[]const u8 = if (conf_comp.zig_lib_dir.value) |dir| |
| 800 | dir.getPath2(step) | 794 | try maker.resolveLazyPathIndexAbs(arena, dir, compile_index) |
| 801 | else if (graph.zig_lib_directory.path) |_| | 795 | else if (graph.zig_lib_directory.path) |_| |
| 802 | try allocPrint(arena, "{f}", .{graph.zig_lib_directory}) | 796 | try allocPrint(arena, "{f}", .{graph.zig_lib_directory}) |
| 803 | else | 797 | else |
| 804 | null; | 798 | null; |
| 805 | | 799 | |
| 806 | if (opt_zig_lib_dir) |zig_lib_dir| { | 800 | if (opt_zig_lib_dir) |zig_lib_dir| (try zig_args.addManyAsArray(gpa, 2)).* = .{ |
| 807 | try zig_args.append(gpa, "--zig-lib-dir"); | 801 | "--zig-lib-dir", zig_lib_dir, |
| 808 | try zig_args.append(gpa, zig_lib_dir); | 802 | }; |
| 809 | } | | |
| 810 | | 803 | |
| 811 | try addFlag(gpa, zig_args, "PIE", compile.pie); | 804 | try addFlag(gpa, zig_args, "PIE", conf_comp.flags2.pie.toBool()); |
| 812 | | 805 | |
| 813 | if (compile.lto) |lto| { | 806 | try zig_args.ensureUnusedCapacity(gpa, 1); |
| 814 | try zig_args.append(gpa, switch (lto) { | 807 | switch (conf_comp.flags3.lto) { |
| 815 | .full => "-flto=full", | 808 | .full => zig_args.appendAssumeCapacity("-flto=full"), |
| 816 | .thin => "-flto=thin", | 809 | .thin => zig_args.appendAssumeCapacity("-flto=thin"), |
| 817 | .none => "-fno-lto", | 810 | .none => zig_args.appendAssumeCapacity("-fno-lto"), |
| 818 | }); | 811 | .default => {}, |
| 819 | } | 812 | } |
| 820 | | 813 | |
| 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()); |
| 822 | | 815 | |
| 823 | if (compile.subsystem) |subsystem| { | 816 | switch (conf_comp.flags3.subsystem) { |
| 824 | try zig_args.appendSlice(gpa, &.{ "--subsystem", @tagName(subsystem) }); | 817 | .default => {}, |
| | 818 | else => |t| (try zig_args.addManyAsArray(gpa, 2)).* = .{ "--subsystem", @tagName(t) }, |
| 825 | } | 819 | } |
| 826 | | 820 | |
| 827 | if (compile.mingw_unicode_entry_point) { | 821 | try addBool(gpa, zig_args, "-municode", conf_comp.flags.mingw_unicode_entry_point); |
| 828 | try zig_args.append(gpa, "-municode"); | | |
| 829 | } | | |
| 830 | | 822 | |
| 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)).* = .{ |
| 832 | "--error-limit", try allocPrint(arena, "{d}", .{err_limit}), | 824 | "--error-limit", try allocPrint(arena, "{d}", .{err_limit}), |
| 833 | }); | 825 | }; |
| 834 | | 826 | |
| 835 | try addFlag(gpa, zig_args, "incremental", graph.incremental); | 827 | try addFlag(gpa, zig_args, "incremental", graph.incremental); |
| 836 | | 828 | |
| ... | @@ -845,7 +837,10 @@ fn lowerZigArgs( | ... | @@ -845,7 +837,10 @@ fn lowerZigArgs( |
| 845 | args_length += arg.len + 1; // +1 to account for null terminator | 837 | args_length += arg.len + 1; // +1 to account for null terminator |
| 846 | } | 838 | } |
| 847 | if (args_length >= 30 * 1024) { | 839 | 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 }); |
| 849 | | 844 | |
| 850 | const args_to_escape = zig_args.items[2..]; | 845 | const args_to_escape = zig_args.items[2..]; |
| 851 | var escaped_args = try std.array_list.Managed([]const u8).initCapacity(arena, args_to_escape.len); | 846 | var escaped_args = try std.array_list.Managed([]const u8).initCapacity(arena, args_to_escape.len); |
| ... | @@ -875,51 +870,43 @@ fn lowerZigArgs( | ... | @@ -875,51 +870,43 @@ fn lowerZigArgs( |
| 875 | var args_hash: [Sha256.digest_length]u8 = undefined; | 870 | var args_hash: [Sha256.digest_length]u8 = undefined; |
| 876 | Sha256.hash(args, &args_hash, .{}); | 871 | Sha256.hash(args, &args_hash, .{}); |
| 877 | var args_hex_hash: [Sha256.digest_length * 2]u8 = undefined; | 872 | 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; |
| 879 | | 874 | |
| 880 | const args_file = "args" ++ Dir.path.sep_str ++ args_hex_hash; | 875 | const args_file = "args" ++ Dir.path.sep_str ++ args_hex_hash; |
| 881 | if (graph.cache_root.handle.access(io, args_file, .{})) |_| { | 876 | local_cache_root.handle.access(io, args_file, .{}) catch { |
| 882 | // The args file is already present from a previous run. | 877 | var af = local_cache_root.handle.createFileAtomic(io, args_file, .{ |
| 883 | } else |err| switch (err) { | 878 | .replace = false, |
| 884 | error.FileNotFound => { | 879 | .make_path = true, |
| 885 | var af = graph.cache_root.handle.createFileAtomic(io, args_file, .{ | 880 | }) catch |e| return step.fail(maker, "failed creating tmp args file {f}{s}: {t}", .{ |
| 886 | .replace = false, | 881 | local_cache_root, args_file, e, |
| 887 | .make_path = true, | 882 | }); |
| 888 | }) catch |e| return step.fail(maker, "failed creating tmp args file {f}{s}: {t}", .{ | 883 | defer af.deinit(io); |
| 889 | graph.cache_root, args_file, e, | | |
| 890 | }); | | |
| 891 | defer af.deinit(io); | | |
| 892 | | 884 | |
| 893 | af.file.writeStreamingAll(io, args) catch |e| { | 885 | af.file.writeStreamingAll(io, args) catch |e| { |
| 894 | return step.fail(maker, "failed writing args data to tmp file {f}{s}: {t}", .{ | 886 | return step.fail(maker, "failed writing args data to tmp file {f}{s}: {t}", .{ |
| 895 | graph.cache_root, args_file, e, | 887 | local_cache_root, args_file, e, |
| 896 | }); | 888 | }); |
| 897 | }; | 889 | }; |
| 898 | // Note we can't clean up this file, not even after build | 890 | // Note we can't clean up this file, not even after build |
| 899 | // success, because that might interfere with another build | 891 | // success, because that might interfere with another build |
| 900 | // process that needs the same file. | 892 | // process that needs the same file. |
| 901 | af.link(io) catch |e| switch (e) { | 893 | af.link(io) catch |e| switch (e) { |
| 902 | error.PathAlreadyExists => { | 894 | error.PathAlreadyExists => { |
| 903 | // The args file was created by another concurrent build process. | 895 | // The args file was created by another concurrent build process. |
| 904 | }, | 896 | }, |
| 905 | else => |other_err| return step.fail(maker, "failed linking tmp file {f}{s}: {t}", .{ | 897 | else => |other_err| return step.fail(maker, "failed linking tmp file {f}{s}: {t}", .{ |
| 906 | graph.cache_root, args_file, other_err, | 898 | local_cache_root, args_file, other_err, |
| 907 | }), | 899 | }), |
| 908 | }; | 900 | }; |
| 909 | }, | 901 | }; |
| 910 | else => |other_err| return other_err, | | |
| 911 | } | | |
| 912 | | 902 | |
| 913 | const resolved_args_file = try mem.concat(arena, u8, &.{ | 903 | const resolved_args_file = try mem.concat(arena, u8, &.{ |
| 914 | "@", | 904 | "@", try local_cache_root.join(arena, &.{args_file}), |
| 915 | try graph.cache_root.join(arena, &.{args_file}), | | |
| 916 | }); | 905 | }); |
| 917 | | 906 | |
| 918 | zig_args.shrinkRetainingCapacity(2); | 907 | zig_args.shrinkRetainingCapacity(2); |
| 919 | try zig_args.append(gpa, resolved_args_file); | 908 | try zig_args.append(gpa, resolved_args_file); |
| 920 | } | 909 | } |
| 921 | | | |
| 922 | return try zig_args.toOwnedSlice(); | | |
| 923 | } | 910 | } |
| 924 | | 911 | |
| 925 | pub fn rebuildInFuzzMode(compile: *Compile, maker: *Maker, progress_node: std.Progress.Node) !Path { | 912 | pub fn rebuildInFuzzMode(compile: *Compile, maker: *Maker, progress_node: std.Progress.Node) !Path { |