| ... | ... | @@ -15,10 +15,10 @@ const allocPrint = std.fmt.allocPrint; |
| 15 | 15 | const Step = @import("../Step.zig"); |
| 16 | 16 | const Maker = @import("../../Maker.zig"); |
| 17 | 17 | |
| 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`. |
| 20 | 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 | 22 | zig_args: std.ArrayList([]const u8) = .empty, |
| 23 | 23 | |
| 24 | 24 | pub fn make( |
| ... | ... | @@ -538,28 +538,29 @@ fn lowerZigArgs( |
| 538 | 538 | try zig_args.append(gpa, try maker.resolveLazyPathIndexAbs(arena, manifest_file, compile_index)); |
| 539 | 539 | } |
| 540 | 540 | |
| 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)); |
| 545 | 543 | } |
| 546 | 544 | |
| 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)).* = .{ |
| 549 | 547 | "--image-base", try allocPrint(arena, "0x{x}", .{image_base}), |
| 550 | | }); |
| 548 | }; |
| 551 | 549 | } |
| 552 | 550 | |
| 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) }; |
| 555 | 553 | } |
| 556 | 554 | |
| 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 | }, |
| 559 | 560 | } |
| 560 | 561 | |
| 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 }; |
| 563 | 564 | } |
| 564 | 565 | |
| 565 | 566 | try addBool(gpa, zig_args, "--debug-compile-errors", graph.debug_compile_errors); |
| ... | ... | @@ -571,179 +572,172 @@ fn lowerZigArgs( |
| 571 | 572 | try addBool(gpa, zig_args, "--verbose-llvm-cpu-features", graph.verbose_llvm_cpu_features); |
| 572 | 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 (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"); |
| 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 | 586 | .none => {}, |
| 586 | 587 | .zlib => try zig_args.append(gpa, "--compress-debug-sections=zlib"), |
| 587 | 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 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| |
| 603 | 597 | 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) |
| 606 | 600 | 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)); |
| 626 | 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"); |
| 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 | }; |
| 632 | 627 | |
| 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 | }; |
| 635 | 633 | |
| 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); |
| 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) { |
| 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 | } |
| 649 | 644 | |
| 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 | } |
| 657 | 666 | } |
| 658 | 667 | } |
| 659 | 668 | |
| 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 | }; |
| 676 | 673 | } |
| 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 | }; |
| 679 | 678 | } |
| 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 | }; |
| 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); |
| 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()); |
| 717 | 692 | |
| 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); |
| 725 | 700 | |
| 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 | } |
| 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 | 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 | 730 | try zig_args.append(gpa, if (enabled) "--enable-new-dtags" else "--disable-new-dtags"); |
| 736 | 731 | } |
| 737 | 732 | |
| 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"); |
| 747 | 741 | } |
| 748 | 742 | } |
| 749 | 743 | } |
| ... | ... | @@ -783,54 +777,52 @@ fn lowerZigArgs( |
| 783 | 777 | } |
| 784 | 778 | } |
| 785 | 779 | |
| 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 | }; |
| 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 | 787 | try zig_args.append(gpa, switch (build_id) { |
| 794 | 788 | .hexstring => |hs| try allocPrint(arena, "--build-id=0x{x}", .{hs.toSlice()}), |
| 795 | 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| |
| 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) |
| 801 | 795 | else if (graph.zig_lib_directory.path) |_| |
| 802 | 796 | try allocPrint(arena, "{f}", .{graph.zig_lib_directory}) |
| 803 | 797 | else |
| 804 | 798 | null; |
| 805 | 799 | |
| 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 | }; |
| 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| { |
| 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 => {}, |
| 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| { |
| 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) }, |
| 825 | 819 | } |
| 826 | 820 | |
| 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); |
| 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 | 824 | "--error-limit", try allocPrint(arena, "{d}", .{err_limit}), |
| 833 | | }); |
| 825 | }; |
| 834 | 826 | |
| 835 | 827 | try addFlag(gpa, zig_args, "incremental", graph.incremental); |
| 836 | 828 | |
| ... | ... | @@ -845,7 +837,10 @@ fn lowerZigArgs( |
| 845 | 837 | args_length += arg.len + 1; // +1 to account for null terminator |
| 846 | 838 | } |
| 847 | 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 | 845 | const args_to_escape = zig_args.items[2..]; |
| 851 | 846 | var escaped_args = try std.array_list.Managed([]const u8).initCapacity(arena, args_to_escape.len); |
| ... | ... | @@ -875,51 +870,43 @@ fn lowerZigArgs( |
| 875 | 870 | var args_hash: [Sha256.digest_length]u8 = undefined; |
| 876 | 871 | Sha256.hash(args, &args_hash, .{}); |
| 877 | 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 | 875 | 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); |
| 892 | 884 | |
| 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 | }; |
| 912 | 902 | |
| 913 | 903 | 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}), |
| 916 | 905 | }); |
| 917 | 906 | |
| 918 | 907 | zig_args.shrinkRetainingCapacity(2); |
| 919 | 908 | try zig_args.append(gpa, resolved_args_file); |
| 920 | 909 | } |
| 921 | | |
| 922 | | return try zig_args.toOwnedSlice(); |
| 923 | 910 | } |
| 924 | 911 | |
| 925 | 912 | pub fn rebuildInFuzzMode(compile: *Compile, maker: *Maker, progress_node: std.Progress.Node) !Path { |