| author | |
| committer | |
| log | 38840e2e586d71f2b38ed825ea02529f615c5f0c |
| tree | 5c31180307056823d2fc8a5aab73f094ad4d729d |
| parent | f8386de7ae12fca1e50e7920964fd7c47301fc05 |
* introduce LazyPath.cwd_relative variant and use it for --zig-lib-dir. closes #12685
* move overrideZigLibDir and setMainPkgPath to options fields set once
and then never mutated.
* avoid introducing Build/util.zig
* use doc comments for deprecation notices so that they show up in
generated documentation.
* introduce InstallArtifact.Options, accept it as a parameter to
addInstallArtifact, and move override_dest_dir into it. Instead of
configuring the installation via Compile step, configure the
installation via the InstallArtifact step. In retrospect this is
obvious.
* remove calls to pushInstalledFile in InstallArtifact. See #14943
* rewrite InstallArtifact to not incorrectly observe whether a Compile
step has any generated outputs. InstallArtifact is meant to trigger
output generation.
* fix child process evaluation code handling of `-fno-emit-bin`.
* don't store out_h_filename, out_ll_filename, etc., pointlessly. these
are all just simple extensions appended to the root name.
* make emit_directory optional. It's possible to have nothing outputted,
for example, if you're just type-checking.
* avoid passing -femit-foo/-fno-emit-foo when it is the default
* rename ConfigHeader.getTemplate to getOutput
* deprecate addOptionArtifact
* update the random number seed of Options step caching.
* avoid using `inline for` pointlessly
* avoid using `override_Dest_dir` pointlessly
* avoid emitting an executable pointlessly in test cases
Removes forceBuild and forceEmit. Let's consider these additions separately.
Nearly all of the usage sites were suspicious.29 files changed, 396 insertions(+), 388 deletions(-)
build.zig+14-13| ... | @@ -45,7 +45,8 @@ pub fn build(b: *std.Build) !void { | ... | @@ -45,7 +45,8 @@ pub fn build(b: *std.Build) !void { |
| 45 | const docgen_cmd = b.addRunArtifact(docgen_exe); | 45 | const docgen_cmd = b.addRunArtifact(docgen_exe); |
| 46 | docgen_cmd.addArgs(&.{ "--zig", b.zig_exe }); | 46 | docgen_cmd.addArgs(&.{ "--zig", b.zig_exe }); |
| 47 | if (b.zig_lib_dir) |p| { | 47 | if (b.zig_lib_dir) |p| { |
| 48 | docgen_cmd.addArgs(&.{ "--zig-lib-dir", b.pathFromRoot(p) }); | 48 | docgen_cmd.addArg("--zig-lib-dir"); |
| 49 | docgen_cmd.addFileArg(p); | ||
| 49 | } | 50 | } |
| 50 | docgen_cmd.addFileArg(.{ .path = "doc/langref.html.in" }); | 51 | docgen_cmd.addFileArg(.{ .path = "doc/langref.html.in" }); |
| 51 | const langref_file = docgen_cmd.addOutputFileArg("langref.html"); | 52 | const langref_file = docgen_cmd.addOutputFileArg("langref.html"); |
| ... | @@ -57,8 +58,8 @@ pub fn build(b: *std.Build) !void { | ... | @@ -57,8 +58,8 @@ pub fn build(b: *std.Build) !void { |
| 57 | const autodoc_test = b.addTest(.{ | 58 | const autodoc_test = b.addTest(.{ |
| 58 | .root_source_file = .{ .path = "lib/std/std.zig" }, | 59 | .root_source_file = .{ .path = "lib/std/std.zig" }, |
| 59 | .target = target, | 60 | .target = target, |
| 61 | .zig_lib_dir = .{ .path = "lib" }, | ||
| 60 | }); | 62 | }); |
| 61 | autodoc_test.overrideZigLibDir(.{ .path = "lib" }); | ||
| 62 | const install_std_docs = b.addInstallDirectory(.{ | 63 | const install_std_docs = b.addInstallDirectory(.{ |
| 63 | .source_dir = autodoc_test.getEmittedDocs(), | 64 | .source_dir = autodoc_test.getEmittedDocs(), |
| 64 | .install_dir = .prefix, | 65 | .install_dir = .prefix, |
| ... | @@ -87,8 +88,8 @@ pub fn build(b: *std.Build) !void { | ... | @@ -87,8 +88,8 @@ pub fn build(b: *std.Build) !void { |
| 87 | .name = "check-case", | 88 | .name = "check-case", |
| 88 | .root_source_file = .{ .path = "test/src/Cases.zig" }, | 89 | .root_source_file = .{ .path = "test/src/Cases.zig" }, |
| 89 | .optimize = optimize, | 90 | .optimize = optimize, |
| 91 | .main_pkg_path = .{ .path = "." }, | ||
| 90 | }); | 92 | }); |
| 91 | check_case_exe.setMainPkgPath(.{ .path = "." }); | ||
| 92 | check_case_exe.stack_size = stack_size; | 93 | check_case_exe.stack_size = stack_size; |
| 93 | check_case_exe.single_threaded = single_threaded; | 94 | check_case_exe.single_threaded = single_threaded; |
| 94 | 95 | ||
| ... | @@ -203,7 +204,7 @@ pub fn build(b: *std.Build) !void { | ... | @@ -203,7 +204,7 @@ pub fn build(b: *std.Build) !void { |
| 203 | ); | 204 | ); |
| 204 | 205 | ||
| 205 | if (!no_bin) { | 206 | if (!no_bin) { |
| 206 | const install_exe = b.addInstallArtifact(exe); | 207 | const install_exe = b.addInstallArtifact(exe, .{}); |
| 207 | if (flat) { | 208 | if (flat) { |
| 208 | install_exe.dest_dir = .prefix; | 209 | install_exe.dest_dir = .prefix; |
| 209 | } | 210 | } |
| ... | @@ -357,8 +358,8 @@ pub fn build(b: *std.Build) !void { | ... | @@ -357,8 +358,8 @@ pub fn build(b: *std.Build) !void { |
| 357 | else | 358 | else |
| 358 | &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" }; | 359 | &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" }; |
| 359 | 360 | ||
| 360 | exe.addIncludePath(.{ .path = tracy_path }); | 361 | exe.addIncludePath(.{ .cwd_relative = tracy_path }); |
| 361 | exe.addCSourceFile(.{ .file = .{ .path = client_cpp }, .flags = tracy_c_flags }); | 362 | exe.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags }); |
| 362 | if (!enable_llvm) { | 363 | if (!enable_llvm) { |
| 363 | exe.linkSystemLibraryName("c++"); | 364 | exe.linkSystemLibraryName("c++"); |
| 364 | } | 365 | } |
| ... | @@ -597,7 +598,7 @@ fn addCmakeCfgOptionsToExe( | ... | @@ -597,7 +598,7 @@ fn addCmakeCfgOptionsToExe( |
| 597 | // useful for package maintainers | 598 | // useful for package maintainers |
| 598 | exe.headerpad_max_install_names = true; | 599 | exe.headerpad_max_install_names = true; |
| 599 | } | 600 | } |
| 600 | exe.addObjectFile(.{ .path = b.pathJoin(&[_][]const u8{ | 601 | exe.addObjectFile(.{ .cwd_relative = b.pathJoin(&[_][]const u8{ |
| 601 | cfg.cmake_binary_dir, | 602 | cfg.cmake_binary_dir, |
| 602 | "zigcpp", | 603 | "zigcpp", |
| 603 | b.fmt("{s}{s}{s}", .{ | 604 | b.fmt("{s}{s}{s}", .{ |
| ... | @@ -607,9 +608,9 @@ fn addCmakeCfgOptionsToExe( | ... | @@ -607,9 +608,9 @@ fn addCmakeCfgOptionsToExe( |
| 607 | }), | 608 | }), |
| 608 | }) }); | 609 | }) }); |
| 609 | assert(cfg.lld_include_dir.len != 0); | 610 | assert(cfg.lld_include_dir.len != 0); |
| 610 | exe.addIncludePath(.{ .path = cfg.lld_include_dir }); | 611 | exe.addIncludePath(.{ .cwd_relative = cfg.lld_include_dir }); |
| 611 | exe.addIncludePath(.{ .path = cfg.llvm_include_dir }); | 612 | exe.addIncludePath(.{ .cwd_relative = cfg.llvm_include_dir }); |
| 612 | exe.addLibraryPath(.{ .path = cfg.llvm_lib_dir }); | 613 | exe.addLibraryPath(.{ .cwd_relative = cfg.llvm_lib_dir }); |
| 613 | addCMakeLibraryList(exe, cfg.clang_libraries); | 614 | addCMakeLibraryList(exe, cfg.clang_libraries); |
| 614 | addCMakeLibraryList(exe, cfg.lld_libraries); | 615 | addCMakeLibraryList(exe, cfg.lld_libraries); |
| 615 | addCMakeLibraryList(exe, cfg.llvm_libraries); | 616 | addCMakeLibraryList(exe, cfg.llvm_libraries); |
| ... | @@ -665,7 +666,7 @@ fn addCmakeCfgOptionsToExe( | ... | @@ -665,7 +666,7 @@ fn addCmakeCfgOptionsToExe( |
| 665 | } | 666 | } |
| 666 | 667 | ||
| 667 | if (cfg.dia_guids_lib.len != 0) { | 668 | if (cfg.dia_guids_lib.len != 0) { |
| 668 | exe.addObjectFile(.{ .path = cfg.dia_guids_lib }); | 669 | exe.addObjectFile(.{ .cwd_relative = cfg.dia_guids_lib }); |
| 669 | } | 670 | } |
| 670 | } | 671 | } |
| 671 | 672 | ||
| ... | @@ -726,7 +727,7 @@ fn addCxxKnownPath( | ... | @@ -726,7 +727,7 @@ fn addCxxKnownPath( |
| 726 | } | 727 | } |
| 727 | return error.RequiredLibraryNotFound; | 728 | return error.RequiredLibraryNotFound; |
| 728 | } | 729 | } |
| 729 | exe.addObjectFile(.{ .path = path_unpadded }); | 730 | exe.addObjectFile(.{ .cwd_relative = path_unpadded }); |
| 730 | 731 | ||
| 731 | // TODO a way to integrate with system c++ include files here | 732 | // TODO a way to integrate with system c++ include files here |
| 732 | // c++ -E -Wp,-v -xc++ /dev/null | 733 | // c++ -E -Wp,-v -xc++ /dev/null |
| ... | @@ -746,7 +747,7 @@ fn addCMakeLibraryList(exe: *std.Build.Step.Compile, list: []const u8) void { | ... | @@ -746,7 +747,7 @@ fn addCMakeLibraryList(exe: *std.Build.Step.Compile, list: []const u8) void { |
| 746 | } else if (exe.target.isWindows() and mem.endsWith(u8, lib, ".lib") and !fs.path.isAbsolute(lib)) { | 747 | } else if (exe.target.isWindows() and mem.endsWith(u8, lib, ".lib") and !fs.path.isAbsolute(lib)) { |
| 747 | exe.linkSystemLibrary(lib[0 .. lib.len - ".lib".len]); | 748 | exe.linkSystemLibrary(lib[0 .. lib.len - ".lib".len]); |
| 748 | } else { | 749 | } else { |
| 749 | exe.addObjectFile(.{ .path = lib }); | 750 | exe.addObjectFile(.{ .cwd_relative = lib }); |
| 750 | } | 751 | } |
| 751 | } | 752 | } |
| 752 | } | 753 | } |
lib/build_runner.zig+2-2| ... | @@ -188,10 +188,10 @@ pub fn main() !void { | ... | @@ -188,10 +188,10 @@ pub fn main() !void { |
| 188 | usageAndErr(builder, false, stderr_stream); | 188 | usageAndErr(builder, false, stderr_stream); |
| 189 | }; | 189 | }; |
| 190 | } else if (mem.eql(u8, arg, "--zig-lib-dir")) { | 190 | } else if (mem.eql(u8, arg, "--zig-lib-dir")) { |
| 191 | builder.zig_lib_dir = nextArg(args, &arg_idx) orelse { | 191 | builder.zig_lib_dir = .{ .cwd_relative = nextArg(args, &arg_idx) orelse { |
| 192 | std.debug.print("Expected argument after {s}\n\n", .{arg}); | 192 | std.debug.print("Expected argument after {s}\n\n", .{arg}); |
| 193 | usageAndErr(builder, false, stderr_stream); | 193 | usageAndErr(builder, false, stderr_stream); |
| 194 | }; | 194 | } }; |
| 195 | } else if (mem.eql(u8, arg, "--debug-log")) { | 195 | } else if (mem.eql(u8, arg, "--debug-log")) { |
| 196 | const next_arg = nextArg(args, &arg_idx) orelse { | 196 | const next_arg = nextArg(args, &arg_idx) orelse { |
| 197 | std.debug.print("Expected argument after {s}\n\n", .{arg}); | 197 | std.debug.print("Expected argument after {s}\n\n", .{arg}); |
lib/std/Build.zig+114-18| ... | @@ -19,8 +19,6 @@ const NativeTargetInfo = std.zig.system.NativeTargetInfo; | ... | @@ -19,8 +19,6 @@ const NativeTargetInfo = std.zig.system.NativeTargetInfo; |
| 19 | const Sha256 = std.crypto.hash.sha2.Sha256; | 19 | const Sha256 = std.crypto.hash.sha2.Sha256; |
| 20 | const Build = @This(); | 20 | const Build = @This(); |
| 21 | 21 | ||
| 22 | const build_util = @import("Build/util.zig"); | ||
| 23 | |||
| 24 | pub const Cache = @import("Build/Cache.zig"); | 22 | pub const Cache = @import("Build/Cache.zig"); |
| 25 | 23 | ||
| 26 | /// deprecated: use `Step.Compile`. | 24 | /// deprecated: use `Step.Compile`. |
| ... | @@ -59,6 +57,8 @@ pub const RunStep = @import("Build/Step/Run.zig"); | ... | @@ -59,6 +57,8 @@ pub const RunStep = @import("Build/Step/Run.zig"); |
| 59 | pub const TranslateCStep = @import("Build/Step/TranslateC.zig"); | 57 | pub const TranslateCStep = @import("Build/Step/TranslateC.zig"); |
| 60 | /// deprecated: use `Step.WriteFile`. | 58 | /// deprecated: use `Step.WriteFile`. |
| 61 | pub const WriteFileStep = @import("Build/Step/WriteFile.zig"); | 59 | pub const WriteFileStep = @import("Build/Step/WriteFile.zig"); |
| 60 | /// deprecated: use `LazyPath`. | ||
| 61 | pub const FileSource = LazyPath; | ||
| 62 | 62 | ||
| 63 | install_tls: TopLevelStep, | 63 | install_tls: TopLevelStep, |
| 64 | uninstall_tls: TopLevelStep, | 64 | uninstall_tls: TopLevelStep, |
| ... | @@ -95,8 +95,7 @@ build_root: Cache.Directory, | ... | @@ -95,8 +95,7 @@ build_root: Cache.Directory, |
| 95 | cache_root: Cache.Directory, | 95 | cache_root: Cache.Directory, |
| 96 | global_cache_root: Cache.Directory, | 96 | global_cache_root: Cache.Directory, |
| 97 | cache: *Cache, | 97 | cache: *Cache, |
| 98 | /// If non-null, overrides the default zig lib dir. | 98 | zig_lib_dir: ?LazyPath, |
| 99 | zig_lib_dir: ?[]const u8, | ||
| 100 | vcpkg_root: VcpkgRoot = .unattempted, | 99 | vcpkg_root: VcpkgRoot = .unattempted, |
| 101 | pkg_config_pkg_list: ?(PkgConfigError![]const PkgConfigPkg) = null, | 100 | pkg_config_pkg_list: ?(PkgConfigError![]const PkgConfigPkg) = null, |
| 102 | args: ?[][]const u8 = null, | 101 | args: ?[][]const u8 = null, |
| ... | @@ -483,6 +482,8 @@ pub const ExecutableOptions = struct { | ... | @@ -483,6 +482,8 @@ pub const ExecutableOptions = struct { |
| 483 | single_threaded: ?bool = null, | 482 | single_threaded: ?bool = null, |
| 484 | use_llvm: ?bool = null, | 483 | use_llvm: ?bool = null, |
| 485 | use_lld: ?bool = null, | 484 | use_lld: ?bool = null, |
| 485 | zig_lib_dir: ?LazyPath = null, | ||
| 486 | main_pkg_path: ?LazyPath = null, | ||
| 486 | }; | 487 | }; |
| 487 | 488 | ||
| 488 | pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { | 489 | pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { |
| ... | @@ -499,6 +500,8 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { | ... | @@ -499,6 +500,8 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile { |
| 499 | .single_threaded = options.single_threaded, | 500 | .single_threaded = options.single_threaded, |
| 500 | .use_llvm = options.use_llvm, | 501 | .use_llvm = options.use_llvm, |
| 501 | .use_lld = options.use_lld, | 502 | .use_lld = options.use_lld, |
| 503 | .zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir, | ||
| 504 | .main_pkg_path = options.main_pkg_path, | ||
| 502 | }); | 505 | }); |
| 503 | } | 506 | } |
| 504 | 507 | ||
| ... | @@ -512,6 +515,8 @@ pub const ObjectOptions = struct { | ... | @@ -512,6 +515,8 @@ pub const ObjectOptions = struct { |
| 512 | single_threaded: ?bool = null, | 515 | single_threaded: ?bool = null, |
| 513 | use_llvm: ?bool = null, | 516 | use_llvm: ?bool = null, |
| 514 | use_lld: ?bool = null, | 517 | use_lld: ?bool = null, |
| 518 | zig_lib_dir: ?LazyPath = null, | ||
| 519 | main_pkg_path: ?LazyPath = null, | ||
| 515 | }; | 520 | }; |
| 516 | 521 | ||
| 517 | pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { | 522 | pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { |
| ... | @@ -526,6 +531,8 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { | ... | @@ -526,6 +531,8 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile { |
| 526 | .single_threaded = options.single_threaded, | 531 | .single_threaded = options.single_threaded, |
| 527 | .use_llvm = options.use_llvm, | 532 | .use_llvm = options.use_llvm, |
| 528 | .use_lld = options.use_lld, | 533 | .use_lld = options.use_lld, |
| 534 | .zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir, | ||
| 535 | .main_pkg_path = options.main_pkg_path, | ||
| 529 | }); | 536 | }); |
| 530 | } | 537 | } |
| 531 | 538 | ||
| ... | @@ -540,6 +547,8 @@ pub const SharedLibraryOptions = struct { | ... | @@ -540,6 +547,8 @@ pub const SharedLibraryOptions = struct { |
| 540 | single_threaded: ?bool = null, | 547 | single_threaded: ?bool = null, |
| 541 | use_llvm: ?bool = null, | 548 | use_llvm: ?bool = null, |
| 542 | use_lld: ?bool = null, | 549 | use_lld: ?bool = null, |
| 550 | zig_lib_dir: ?LazyPath = null, | ||
| 551 | main_pkg_path: ?LazyPath = null, | ||
| 543 | }; | 552 | }; |
| 544 | 553 | ||
| 545 | pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile { | 554 | pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile { |
| ... | @@ -556,6 +565,8 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile | ... | @@ -556,6 +565,8 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile |
| 556 | .single_threaded = options.single_threaded, | 565 | .single_threaded = options.single_threaded, |
| 557 | .use_llvm = options.use_llvm, | 566 | .use_llvm = options.use_llvm, |
| 558 | .use_lld = options.use_lld, | 567 | .use_lld = options.use_lld, |
| 568 | .zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir, | ||
| 569 | .main_pkg_path = options.main_pkg_path, | ||
| 559 | }); | 570 | }); |
| 560 | } | 571 | } |
| 561 | 572 | ||
| ... | @@ -570,6 +581,8 @@ pub const StaticLibraryOptions = struct { | ... | @@ -570,6 +581,8 @@ pub const StaticLibraryOptions = struct { |
| 570 | single_threaded: ?bool = null, | 581 | single_threaded: ?bool = null, |
| 571 | use_llvm: ?bool = null, | 582 | use_llvm: ?bool = null, |
| 572 | use_lld: ?bool = null, | 583 | use_lld: ?bool = null, |
| 584 | zig_lib_dir: ?LazyPath = null, | ||
| 585 | main_pkg_path: ?LazyPath = null, | ||
| 573 | }; | 586 | }; |
| 574 | 587 | ||
| 575 | pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile { | 588 | pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile { |
| ... | @@ -586,6 +599,8 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile | ... | @@ -586,6 +599,8 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile |
| 586 | .single_threaded = options.single_threaded, | 599 | .single_threaded = options.single_threaded, |
| 587 | .use_llvm = options.use_llvm, | 600 | .use_llvm = options.use_llvm, |
| 588 | .use_lld = options.use_lld, | 601 | .use_lld = options.use_lld, |
| 602 | .zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir, | ||
| 603 | .main_pkg_path = options.main_pkg_path, | ||
| 589 | }); | 604 | }); |
| 590 | } | 605 | } |
| 591 | 606 | ||
| ... | @@ -602,6 +617,8 @@ pub const TestOptions = struct { | ... | @@ -602,6 +617,8 @@ pub const TestOptions = struct { |
| 602 | single_threaded: ?bool = null, | 617 | single_threaded: ?bool = null, |
| 603 | use_llvm: ?bool = null, | 618 | use_llvm: ?bool = null, |
| 604 | use_lld: ?bool = null, | 619 | use_lld: ?bool = null, |
| 620 | zig_lib_dir: ?LazyPath = null, | ||
| 621 | main_pkg_path: ?LazyPath = null, | ||
| 605 | }; | 622 | }; |
| 606 | 623 | ||
| 607 | pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { | 624 | pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { |
| ... | @@ -618,6 +635,8 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { | ... | @@ -618,6 +635,8 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile { |
| 618 | .single_threaded = options.single_threaded, | 635 | .single_threaded = options.single_threaded, |
| 619 | .use_llvm = options.use_llvm, | 636 | .use_llvm = options.use_llvm, |
| 620 | .use_lld = options.use_lld, | 637 | .use_lld = options.use_lld, |
| 638 | .zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir, | ||
| 639 | .main_pkg_path = options.main_pkg_path, | ||
| 621 | }); | 640 | }); |
| 622 | } | 641 | } |
| 623 | 642 | ||
| ... | @@ -627,6 +646,7 @@ pub const AssemblyOptions = struct { | ... | @@ -627,6 +646,7 @@ pub const AssemblyOptions = struct { |
| 627 | target: CrossTarget, | 646 | target: CrossTarget, |
| 628 | optimize: std.builtin.Mode, | 647 | optimize: std.builtin.Mode, |
| 629 | max_rss: usize = 0, | 648 | max_rss: usize = 0, |
| 649 | zig_lib_dir: ?LazyPath = null, | ||
| 630 | }; | 650 | }; |
| 631 | 651 | ||
| 632 | pub fn addAssembly(b: *Build, options: AssemblyOptions) *Step.Compile { | 652 | pub fn addAssembly(b: *Build, options: AssemblyOptions) *Step.Compile { |
| ... | @@ -637,6 +657,7 @@ pub fn addAssembly(b: *Build, options: AssemblyOptions) *Step.Compile { | ... | @@ -637,6 +657,7 @@ pub fn addAssembly(b: *Build, options: AssemblyOptions) *Step.Compile { |
| 637 | .target = options.target, | 657 | .target = options.target, |
| 638 | .optimize = options.optimize, | 658 | .optimize = options.optimize, |
| 639 | .max_rss = options.max_rss, | 659 | .max_rss = options.max_rss, |
| 660 | .zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir, | ||
| 640 | }); | 661 | }); |
| 641 | obj_step.addAssemblyLazyPath(options.source_file.dupe(b)); | 662 | obj_step.addAssemblyLazyPath(options.source_file.dupe(b)); |
| 642 | return obj_step; | 663 | return obj_step; |
| ... | @@ -1259,12 +1280,21 @@ fn printCmd(ally: Allocator, cwd: ?[]const u8, argv: []const []const u8) void { | ... | @@ -1259,12 +1280,21 @@ fn printCmd(ally: Allocator, cwd: ?[]const u8, argv: []const []const u8) void { |
| 1259 | std.debug.print("{s}\n", .{text}); | 1280 | std.debug.print("{s}\n", .{text}); |
| 1260 | } | 1281 | } |
| 1261 | 1282 | ||
| 1283 | /// This creates the install step and adds it to the dependencies of the | ||
| 1284 | /// top-level install step, using all the default options. | ||
| 1285 | /// See `addInstallArtifact` for a more flexible function. | ||
| 1262 | pub fn installArtifact(self: *Build, artifact: *Step.Compile) void { | 1286 | pub fn installArtifact(self: *Build, artifact: *Step.Compile) void { |
| 1263 | self.getInstallStep().dependOn(&self.addInstallArtifact(artifact).step); | 1287 | self.getInstallStep().dependOn(&self.addInstallArtifact(artifact, .{}).step); |
| 1264 | } | 1288 | } |
| 1265 | 1289 | ||
| 1266 | pub fn addInstallArtifact(self: *Build, artifact: *Step.Compile) *Step.InstallArtifact { | 1290 | /// This merely creates the step; it does not add it to the dependencies of the |
| 1267 | return Step.InstallArtifact.create(self, artifact); | 1291 | /// top-level install step. |
| 1292 | pub fn addInstallArtifact( | ||
| 1293 | self: *Build, | ||
| 1294 | artifact: *Step.Compile, | ||
| 1295 | options: Step.InstallArtifact.Options, | ||
| 1296 | ) *Step.InstallArtifact { | ||
| 1297 | return Step.InstallArtifact.create(self, artifact, options); | ||
| 1268 | } | 1298 | } |
| 1269 | 1299 | ||
| 1270 | ///`dest_rel_path` is relative to prefix path | 1300 | ///`dest_rel_path` is relative to prefix path |
| ... | @@ -1330,6 +1360,7 @@ pub fn addCheckFile( | ... | @@ -1330,6 +1360,7 @@ pub fn addCheckFile( |
| 1330 | return Step.CheckFile.create(b, file_source, options); | 1360 | return Step.CheckFile.create(b, file_source, options); |
| 1331 | } | 1361 | } |
| 1332 | 1362 | ||
| 1363 | /// deprecated: https://github.com/ziglang/zig/issues/14943 | ||
| 1333 | pub fn pushInstalledFile(self: *Build, dir: InstallDir, dest_rel_path: []const u8) void { | 1364 | pub fn pushInstalledFile(self: *Build, dir: InstallDir, dest_rel_path: []const u8) void { |
| 1334 | const file = InstalledFile{ | 1365 | const file = InstalledFile{ |
| 1335 | .dir = dir, | 1366 | .dir = dir, |
| ... | @@ -1632,19 +1663,27 @@ pub const GeneratedFile = struct { | ... | @@ -1632,19 +1663,27 @@ pub const GeneratedFile = struct { |
| 1632 | } | 1663 | } |
| 1633 | }; | 1664 | }; |
| 1634 | 1665 | ||
| 1635 | pub const FileSource = LazyPath; // DEPRECATED, use LazyPath now | ||
| 1636 | |||
| 1637 | /// A reference to an existing or future path. | 1666 | /// A reference to an existing or future path. |
| 1638 | pub const LazyPath = union(enum) { | 1667 | pub const LazyPath = union(enum) { |
| 1639 | /// A plain file path, relative to build root or absolute. | 1668 | /// A source file path relative to build root. |
| 1669 | /// This should not be an absolute path, but in an older iteration of the zig build | ||
| 1670 | /// system API, it was allowed to be absolute. Absolute paths should use `cwd_relative`. | ||
| 1640 | path: []const u8, | 1671 | path: []const u8, |
| 1641 | 1672 | ||
| 1642 | /// A file that is generated by an interface. Those files usually are | 1673 | /// A file that is generated by an interface. Those files usually are |
| 1643 | /// not available until built by a build step. | 1674 | /// not available until built by a build step. |
| 1644 | generated: *const GeneratedFile, | 1675 | generated: *const GeneratedFile, |
| 1645 | 1676 | ||
| 1677 | /// An absolute path or a path relative to the current working directory of | ||
| 1678 | /// the build runner process. | ||
| 1679 | /// This is uncommon but used for system environment paths such as `--zig-lib-dir` which | ||
| 1680 | /// ignore the file system path of build.zig and instead are relative to the directory from | ||
| 1681 | /// which `zig build` was invoked. | ||
| 1682 | /// Use of this tag indicates a dependency on the host system. | ||
| 1683 | cwd_relative: []const u8, | ||
| 1684 | |||
| 1646 | /// Returns a new file source that will have a relative path to the build root guaranteed. | 1685 | /// Returns a new file source that will have a relative path to the build root guaranteed. |
| 1647 | /// This should be preferred over setting `.path` directly as it documents that the files are in the project directory. | 1686 | /// Asserts the parameter is not an absolute path. |
| 1648 | pub fn relative(path: []const u8) LazyPath { | 1687 | pub fn relative(path: []const u8) LazyPath { |
| 1649 | std.debug.assert(!std.fs.path.isAbsolute(path)); | 1688 | std.debug.assert(!std.fs.path.isAbsolute(path)); |
| 1650 | return LazyPath{ .path = path }; | 1689 | return LazyPath{ .path = path }; |
| ... | @@ -1654,7 +1693,7 @@ pub const LazyPath = union(enum) { | ... | @@ -1654,7 +1693,7 @@ pub const LazyPath = union(enum) { |
| 1654 | /// Either returns the path or `"generated"`. | 1693 | /// Either returns the path or `"generated"`. |
| 1655 | pub fn getDisplayName(self: LazyPath) []const u8 { | 1694 | pub fn getDisplayName(self: LazyPath) []const u8 { |
| 1656 | return switch (self) { | 1695 | return switch (self) { |
| 1657 | .path => self.path, | 1696 | .path, .cwd_relative => self.path, |
| 1658 | .generated => "generated", | 1697 | .generated => "generated", |
| 1659 | }; | 1698 | }; |
| 1660 | } | 1699 | } |
| ... | @@ -1662,26 +1701,34 @@ pub const LazyPath = union(enum) { | ... | @@ -1662,26 +1701,34 @@ pub const LazyPath = union(enum) { |
| 1662 | /// Adds dependencies this file source implies to the given step. | 1701 | /// Adds dependencies this file source implies to the given step. |
| 1663 | pub fn addStepDependencies(self: LazyPath, other_step: *Step) void { | 1702 | pub fn addStepDependencies(self: LazyPath, other_step: *Step) void { |
| 1664 | switch (self) { | 1703 | switch (self) { |
| 1665 | .path => {}, | 1704 | .path, .cwd_relative => {}, |
| 1666 | .generated => |gen| other_step.dependOn(gen.step), | 1705 | .generated => |gen| other_step.dependOn(gen.step), |
| 1667 | } | 1706 | } |
| 1668 | } | 1707 | } |
| 1669 | 1708 | ||
| 1670 | /// Should only be called during make(), returns a path relative to the build root or absolute. | 1709 | /// Returns a path relative to the current process's current working directory, suitable |
| 1710 | /// for direct file system operations. | ||
| 1711 | /// | ||
| 1712 | /// Intended to be used during the make phase only. | ||
| 1671 | pub fn getPath(self: LazyPath, src_builder: *Build) []const u8 { | 1713 | pub fn getPath(self: LazyPath, src_builder: *Build) []const u8 { |
| 1672 | return getPath2(self, src_builder, null); | 1714 | return getPath2(self, src_builder, null); |
| 1673 | } | 1715 | } |
| 1674 | 1716 | ||
| 1675 | /// Should only be called during make(), returns a path relative to the build root or absolute. | 1717 | /// Returns a path relative to the current process's current working directory, suitable |
| 1676 | /// asking_step is only used for debugging purposes; it's the step being run that is asking for | 1718 | /// for direct file system operations. |
| 1677 | /// the path. | 1719 | /// |
| 1720 | /// Intended to be used during the make phase only. | ||
| 1721 | /// | ||
| 1722 | /// `asking_step` is only used for debugging purposes; it's the step being | ||
| 1723 | /// run that is asking for the path. | ||
| 1678 | pub fn getPath2(self: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 { | 1724 | pub fn getPath2(self: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 { |
| 1679 | switch (self) { | 1725 | switch (self) { |
| 1680 | .path => |p| return src_builder.pathFromRoot(p), | 1726 | .path => |p| return src_builder.pathFromRoot(p), |
| 1727 | .cwd_relative => |p| return p, | ||
| 1681 | .generated => |gen| return gen.path orelse { | 1728 | .generated => |gen| return gen.path orelse { |
| 1682 | std.debug.getStderrMutex().lock(); | 1729 | std.debug.getStderrMutex().lock(); |
| 1683 | const stderr = std.io.getStdErr(); | 1730 | const stderr = std.io.getStdErr(); |
| 1684 | build_util.dumpBadGetPathHelp(gen.step, stderr, src_builder, asking_step) catch {}; | 1731 | dumpBadGetPathHelp(gen.step, stderr, src_builder, asking_step) catch {}; |
| 1685 | @panic("misconfigured build script"); | 1732 | @panic("misconfigured build script"); |
| 1686 | }, | 1733 | }, |
| 1687 | } | 1734 | } |
| ... | @@ -1691,11 +1738,60 @@ pub const LazyPath = union(enum) { | ... | @@ -1691,11 +1738,60 @@ pub const LazyPath = union(enum) { |
| 1691 | pub fn dupe(self: LazyPath, b: *Build) LazyPath { | 1738 | pub fn dupe(self: LazyPath, b: *Build) LazyPath { |
| 1692 | return switch (self) { | 1739 | return switch (self) { |
| 1693 | .path => |p| .{ .path = b.dupePath(p) }, | 1740 | .path => |p| .{ .path = b.dupePath(p) }, |
| 1741 | .cwd_relative => |p| .{ .cwd_relative = b.dupePath(p) }, | ||
| 1694 | .generated => |gen| .{ .generated = gen }, | 1742 | .generated => |gen| .{ .generated = gen }, |
| 1695 | }; | 1743 | }; |
| 1696 | } | 1744 | } |
| 1697 | }; | 1745 | }; |
| 1698 | 1746 | ||
| 1747 | /// In this function the stderr mutex has already been locked. | ||
| 1748 | pub fn dumpBadGetPathHelp( | ||
| 1749 | s: *Step, | ||
| 1750 | stderr: fs.File, | ||
| 1751 | src_builder: *Build, | ||
| 1752 | asking_step: ?*Step, | ||
| 1753 | ) anyerror!void { | ||
| 1754 | const w = stderr.writer(); | ||
| 1755 | try w.print( | ||
| 1756 | \\getPath() was called on a GeneratedFile that wasn't built yet. | ||
| 1757 | \\ source package path: {s} | ||
| 1758 | \\ Is there a missing Step dependency on step '{s}'? | ||
| 1759 | \\ | ||
| 1760 | , .{ | ||
| 1761 | src_builder.build_root.path orelse ".", | ||
| 1762 | s.name, | ||
| 1763 | }); | ||
| 1764 | |||
| 1765 | const tty_config = std.io.tty.detectConfig(stderr); | ||
| 1766 | tty_config.setColor(w, .red) catch {}; | ||
| 1767 | try stderr.writeAll(" The step was created by this stack trace:\n"); | ||
| 1768 | tty_config.setColor(w, .reset) catch {}; | ||
| 1769 | |||
| 1770 | const debug_info = std.debug.getSelfDebugInfo() catch |err| { | ||
| 1771 | try w.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}); | ||
| 1772 | return; | ||
| 1773 | }; | ||
| 1774 | const ally = debug_info.allocator; | ||
| 1775 | std.debug.writeStackTrace(s.getStackTrace(), w, ally, debug_info, tty_config) catch |err| { | ||
| 1776 | try stderr.writer().print("Unable to dump stack trace: {s}\n", .{@errorName(err)}); | ||
| 1777 | return; | ||
| 1778 | }; | ||
| 1779 | if (asking_step) |as| { | ||
| 1780 | tty_config.setColor(w, .red) catch {}; | ||
| 1781 | try stderr.writeAll(" The step that is missing a dependency on the above step was created by this stack trace:\n"); | ||
| 1782 | tty_config.setColor(w, .reset) catch {}; | ||
| 1783 | |||
| 1784 | std.debug.writeStackTrace(as.getStackTrace(), w, ally, debug_info, tty_config) catch |err| { | ||
| 1785 | try stderr.writer().print("Unable to dump stack trace: {s}\n", .{@errorName(err)}); | ||
| 1786 | return; | ||
| 1787 | }; | ||
| 1788 | } | ||
| 1789 | |||
| 1790 | tty_config.setColor(w, .red) catch {}; | ||
| 1791 | try stderr.writeAll(" Hope that helps. Proceeding to panic.\n"); | ||
| 1792 | tty_config.setColor(w, .reset) catch {}; | ||
| 1793 | } | ||
| 1794 | |||
| 1699 | /// Allocates a new string for assigning a value to a named macro. | 1795 | /// Allocates a new string for assigning a value to a named macro. |
| 1700 | /// If the value is omitted, it is set to 1. | 1796 | /// If the value is omitted, it is set to 1. |
| 1701 | /// `name` and `value` need not live longer than the function call. | 1797 | /// `name` and `value` need not live longer than the function call. |
lib/std/Build/Step.zig+1-9| ... | @@ -423,15 +423,7 @@ pub fn evalZigProcess( | ... | @@ -423,15 +423,7 @@ pub fn evalZigProcess( |
| 423 | }); | 423 | }); |
| 424 | } | 424 | } |
| 425 | 425 | ||
| 426 | if (s.cast(Compile)) |compile| { | 426 | return result; |
| 427 | if (compile.generated_bin == null) // TODO(xq): How to handle this properly?! | ||
| 428 | return result; | ||
| 429 | } | ||
| 430 | |||
| 431 | return result orelse return s.fail( | ||
| 432 | "the following command failed to communicate the compilation result:\n{s}", | ||
| 433 | .{try allocPrintCmd(arena, null, argv)}, | ||
| 434 | ); | ||
| 435 | } | 427 | } |
| 436 | 428 | ||
| 437 | fn sendMessage(file: std.fs.File, tag: std.zig.Client.Message.Tag) !void { | 429 | fn sendMessage(file: std.fs.File, tag: std.zig.Client.Message.Tag) !void { |
lib/std/Build/Step/Compile.zig+79-150| ... | @@ -21,8 +21,6 @@ const InstallDir = std.Build.InstallDir; | ... | @@ -21,8 +21,6 @@ const InstallDir = std.Build.InstallDir; |
| 21 | const GeneratedFile = std.Build.GeneratedFile; | 21 | const GeneratedFile = std.Build.GeneratedFile; |
| 22 | const Compile = @This(); | 22 | const Compile = @This(); |
| 23 | 23 | ||
| 24 | const build_util = @import("../util.zig"); | ||
| 25 | |||
| 26 | pub const base_id: Step.Id = .compile; | 24 | pub const base_id: Step.Id = .compile; |
| 27 | 25 | ||
| 28 | step: Step, | 26 | step: Step, |
| ... | @@ -68,7 +66,9 @@ max_memory: ?u64 = null, | ... | @@ -68,7 +66,9 @@ max_memory: ?u64 = null, |
| 68 | shared_memory: bool = false, | 66 | shared_memory: bool = false, |
| 69 | global_base: ?u64 = null, | 67 | global_base: ?u64 = null, |
| 70 | c_std: std.Build.CStd, | 68 | c_std: std.Build.CStd, |
| 69 | /// Set via options; intended to be read-only after that. | ||
| 71 | zig_lib_dir: ?LazyPath, | 70 | zig_lib_dir: ?LazyPath, |
| 71 | /// Set via options; intended to be read-only after that. | ||
| 72 | main_pkg_path: ?LazyPath, | 72 | main_pkg_path: ?LazyPath, |
| 73 | exec_cmd_args: ?[]const ?[]const u8, | 73 | exec_cmd_args: ?[]const ?[]const u8, |
| 74 | filter: ?[]const u8, | 74 | filter: ?[]const u8, |
| ... | @@ -80,12 +80,7 @@ wasi_exec_model: ?std.builtin.WasiExecModel = null, | ... | @@ -80,12 +80,7 @@ wasi_exec_model: ?std.builtin.WasiExecModel = null, |
| 80 | export_symbol_names: []const []const u8 = &.{}, | 80 | export_symbol_names: []const []const u8 = &.{}, |
| 81 | 81 | ||
| 82 | root_src: ?LazyPath, | 82 | root_src: ?LazyPath, |
| 83 | out_h_filename: []const u8, | ||
| 84 | out_ll_filename: []const u8, | ||
| 85 | out_bc_filename: []const u8, | ||
| 86 | out_asm_filename: []const u8, | ||
| 87 | out_lib_filename: []const u8, | 83 | out_lib_filename: []const u8, |
| 88 | out_pdb_filename: []const u8, | ||
| 89 | modules: std.StringArrayHashMap(*Module), | 84 | modules: std.StringArrayHashMap(*Module), |
| 90 | 85 | ||
| 91 | link_objects: ArrayList(LinkObject), | 86 | link_objects: ArrayList(LinkObject), |
| ... | @@ -96,8 +91,6 @@ is_linking_libc: bool, | ... | @@ -96,8 +91,6 @@ is_linking_libc: bool, |
| 96 | is_linking_libcpp: bool, | 91 | is_linking_libcpp: bool, |
| 97 | vcpkg_bin_path: ?[]const u8 = null, | 92 | vcpkg_bin_path: ?[]const u8 = null, |
| 98 | 93 | ||
| 99 | /// This may be set in order to override the default install directory | ||
| 100 | override_dest_dir: ?InstallDir, | ||
| 101 | installed_path: ?[]const u8, | 94 | installed_path: ?[]const u8, |
| 102 | 95 | ||
| 103 | /// Base address for an executable image. | 96 | /// Base address for an executable image. |
| ... | @@ -207,9 +200,7 @@ use_lld: ?bool, | ... | @@ -207,9 +200,7 @@ use_lld: ?bool, |
| 207 | /// otherwise. | 200 | /// otherwise. |
| 208 | expect_errors: []const []const u8 = &.{}, | 201 | expect_errors: []const []const u8 = &.{}, |
| 209 | 202 | ||
| 210 | force_build: bool, | 203 | emit_directory: ?*GeneratedFile, |
| 211 | |||
| 212 | emit_directory: GeneratedFile, | ||
| 213 | 204 | ||
| 214 | generated_docs: ?*GeneratedFile, | 205 | generated_docs: ?*GeneratedFile, |
| 215 | generated_asm: ?*GeneratedFile, | 206 | generated_asm: ?*GeneratedFile, |
| ... | @@ -221,6 +212,7 @@ generated_llvm_ir: ?*GeneratedFile, | ... | @@ -221,6 +212,7 @@ generated_llvm_ir: ?*GeneratedFile, |
| 221 | generated_h: ?*GeneratedFile, | 212 | generated_h: ?*GeneratedFile, |
| 222 | 213 | ||
| 223 | pub const CSourceFiles = struct { | 214 | pub const CSourceFiles = struct { |
| 215 | /// Relative to the build root. | ||
| 224 | files: []const []const u8, | 216 | files: []const []const u8, |
| 225 | flags: []const []const u8, | 217 | flags: []const []const u8, |
| 226 | }; | 218 | }; |
| ... | @@ -289,6 +281,8 @@ pub const Options = struct { | ... | @@ -289,6 +281,8 @@ pub const Options = struct { |
| 289 | single_threaded: ?bool = null, | 281 | single_threaded: ?bool = null, |
| 290 | use_llvm: ?bool = null, | 282 | use_llvm: ?bool = null, |
| 291 | use_lld: ?bool = null, | 283 | use_lld: ?bool = null, |
| 284 | zig_lib_dir: ?LazyPath = null, | ||
| 285 | main_pkg_path: ?LazyPath = null, | ||
| 292 | }; | 286 | }; |
| 293 | 287 | ||
| 294 | pub const BuildId = union(enum) { | 288 | pub const BuildId = union(enum) { |
| ... | @@ -376,17 +370,6 @@ pub const Kind = enum { | ... | @@ -376,17 +370,6 @@ pub const Kind = enum { |
| 376 | 370 | ||
| 377 | pub const Linkage = enum { dynamic, static }; | 371 | pub const Linkage = enum { dynamic, static }; |
| 378 | 372 | ||
| 379 | pub const EmitOption = enum { | ||
| 380 | docs, | ||
| 381 | @"asm", | ||
| 382 | bin, | ||
| 383 | pdb, | ||
| 384 | implib, | ||
| 385 | llvm_bc, | ||
| 386 | llvm_ir, | ||
| 387 | h, | ||
| 388 | }; | ||
| 389 | |||
| 390 | pub fn create(owner: *std.Build, options: Options) *Compile { | 373 | pub fn create(owner: *std.Build, options: Options) *Compile { |
| 391 | const name = owner.dupe(options.name); | 374 | const name = owner.dupe(options.name); |
| 392 | const root_src: ?LazyPath = if (options.root_source_file) |rsrc| rsrc.dupe(owner) else null; | 375 | const root_src: ?LazyPath = if (options.root_source_file) |rsrc| rsrc.dupe(owner) else null; |
| ... | @@ -451,12 +434,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -451,12 +434,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 451 | }), | 434 | }), |
| 452 | .version = options.version, | 435 | .version = options.version, |
| 453 | .out_filename = out_filename, | 436 | .out_filename = out_filename, |
| 454 | .out_h_filename = owner.fmt("{s}.h", .{name}), | ||
| 455 | .out_ll_filename = owner.fmt("{s}.bc", .{name}), | ||
| 456 | .out_bc_filename = owner.fmt("{s}.ll", .{name}), | ||
| 457 | .out_asm_filename = owner.fmt("{s}.s", .{name}), | ||
| 458 | .out_lib_filename = undefined, | 437 | .out_lib_filename = undefined, |
| 459 | .out_pdb_filename = owner.fmt("{s}.pdb", .{name}), | ||
| 460 | .major_only_filename = null, | 438 | .major_only_filename = null, |
| 461 | .name_only_filename = null, | 439 | .name_only_filename = null, |
| 462 | .modules = std.StringArrayHashMap(*Module).init(owner.allocator), | 440 | .modules = std.StringArrayHashMap(*Module).init(owner.allocator), |
| ... | @@ -477,14 +455,10 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -477,14 +455,10 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 477 | .disable_sanitize_c = false, | 455 | .disable_sanitize_c = false, |
| 478 | .sanitize_thread = false, | 456 | .sanitize_thread = false, |
| 479 | .rdynamic = false, | 457 | .rdynamic = false, |
| 480 | .override_dest_dir = null, | ||
| 481 | .installed_path = null, | 458 | .installed_path = null, |
| 482 | .force_undefined_symbols = StringHashMap(void).init(owner.allocator), | 459 | .force_undefined_symbols = StringHashMap(void).init(owner.allocator), |
| 483 | 460 | ||
| 484 | .force_build = false, | 461 | .emit_directory = null, |
| 485 | |||
| 486 | .emit_directory = GeneratedFile{ .step = &self.step }, | ||
| 487 | |||
| 488 | .generated_docs = null, | 462 | .generated_docs = null, |
| 489 | .generated_asm = null, | 463 | .generated_asm = null, |
| 490 | .generated_bin = null, | 464 | .generated_bin = null, |
| ... | @@ -503,6 +477,16 @@ pub fn create(owner: *std.Build, options: Options) *Compile { | ... | @@ -503,6 +477,16 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 503 | .use_lld = options.use_lld, | 477 | .use_lld = options.use_lld, |
| 504 | }; | 478 | }; |
| 505 | 479 | ||
| 480 | if (options.zig_lib_dir) |lp| { | ||
| 481 | self.zig_lib_dir = lp.dupe(self.step.owner); | ||
| 482 | lp.addStepDependencies(&self.step); | ||
| 483 | } | ||
| 484 | |||
| 485 | if (options.main_pkg_path) |lp| { | ||
| 486 | self.main_pkg_path = lp.dupe(self.step.owner); | ||
| 487 | lp.addStepDependencies(&self.step); | ||
| 488 | } | ||
| 489 | |||
| 506 | if (self.kind == .lib) { | 490 | if (self.kind == .lib) { |
| 507 | if (self.linkage != null and self.linkage.? == .static) { | 491 | if (self.linkage != null and self.linkage.? == .static) { |
| 508 | self.out_lib_filename = self.out_filename; | 492 | self.out_lib_filename = self.out_filename; |
| ... | @@ -636,7 +620,8 @@ pub fn checkObject(self: *Compile) *Step.CheckObject { | ... | @@ -636,7 +620,8 @@ pub fn checkObject(self: *Compile) *Step.CheckObject { |
| 636 | return Step.CheckObject.create(self.step.owner, self.getEmittedBin(), self.target_info.target.ofmt); | 620 | return Step.CheckObject.create(self.step.owner, self.getEmittedBin(), self.target_info.target.ofmt); |
| 637 | } | 621 | } |
| 638 | 622 | ||
| 639 | pub const setLinkerScriptPath = setLinkerScript; // DEPRECATED, use setLinkerScript | 623 | /// deprecated: use `setLinkerScript` |
| 624 | pub const setLinkerScriptPath = setLinkerScript; | ||
| 640 | 625 | ||
| 641 | pub fn setLinkerScript(self: *Compile, source: LazyPath) void { | 626 | pub fn setLinkerScript(self: *Compile, source: LazyPath) void { |
| 642 | const b = self.step.owner; | 627 | const b = self.step.owner; |
| ... | @@ -700,12 +685,17 @@ pub fn isStaticLibrary(self: *Compile) bool { | ... | @@ -700,12 +685,17 @@ pub fn isStaticLibrary(self: *Compile) bool { |
| 700 | 685 | ||
| 701 | pub fn producesPdbFile(self: *Compile) bool { | 686 | pub fn producesPdbFile(self: *Compile) bool { |
| 702 | // TODO: Is this right? Isn't PDB for *any* PE/COFF file? | 687 | // TODO: Is this right? Isn't PDB for *any* PE/COFF file? |
| 688 | // TODO: just share this logic with the compiler, silly! | ||
| 703 | if (!self.target.isWindows() and !self.target.isUefi()) return false; | 689 | if (!self.target.isWindows() and !self.target.isUefi()) return false; |
| 704 | if (self.target.getObjectFormat() == .c) return false; | 690 | if (self.target.getObjectFormat() == .c) return false; |
| 705 | if (self.strip == true or (self.strip == null and self.optimize == .ReleaseSmall)) return false; | 691 | if (self.strip == true or (self.strip == null and self.optimize == .ReleaseSmall)) return false; |
| 706 | return self.isDynamicLibrary() or self.kind == .exe or self.kind == .@"test"; | 692 | return self.isDynamicLibrary() or self.kind == .exe or self.kind == .@"test"; |
| 707 | } | 693 | } |
| 708 | 694 | ||
| 695 | pub fn producesImplib(self: *Compile) bool { | ||
| 696 | return self.isDynamicLibrary() and self.target.isWindows(); | ||
| 697 | } | ||
| 698 | |||
| 709 | pub fn linkLibC(self: *Compile) void { | 699 | pub fn linkLibC(self: *Compile) void { |
| 710 | self.is_linking_libc = true; | 700 | self.is_linking_libc = true; |
| 711 | } | 701 | } |
| ... | @@ -961,16 +951,6 @@ pub fn setVerboseCC(self: *Compile, value: bool) void { | ... | @@ -961,16 +951,6 @@ pub fn setVerboseCC(self: *Compile, value: bool) void { |
| 961 | self.verbose_cc = value; | 951 | self.verbose_cc = value; |
| 962 | } | 952 | } |
| 963 | 953 | ||
| 964 | pub fn overrideZigLibDir(self: *Compile, dir_path: LazyPath) void { | ||
| 965 | self.zig_lib_dir = dir_path.dupe(self.step.owner); | ||
| 966 | dir_path.addStepDependencies(&self.step); | ||
| 967 | } | ||
| 968 | |||
| 969 | pub fn setMainPkgPath(self: *Compile, dir_path: LazyPath) void { | ||
| 970 | self.main_pkg_path = dir_path.dupe(self.step.owner); | ||
| 971 | dir_path.addStepDependencies(&self.step); | ||
| 972 | } | ||
| 973 | |||
| 974 | pub fn setLibCFile(self: *Compile, libc_file: ?LazyPath) void { | 954 | pub fn setLibCFile(self: *Compile, libc_file: ?LazyPath) void { |
| 975 | const b = self.step.owner; | 955 | const b = self.step.owner; |
| 976 | self.libc_file = if (libc_file) |f| f.dupe(b) else null; | 956 | self.libc_file = if (libc_file) |f| f.dupe(b) else null; |
| ... | @@ -987,34 +967,17 @@ fn getEmittedFileGeneric(self: *Compile, output_file: *?*GeneratedFile) LazyPath | ... | @@ -987,34 +967,17 @@ fn getEmittedFileGeneric(self: *Compile, output_file: *?*GeneratedFile) LazyPath |
| 987 | return .{ .generated = generated_file }; | 967 | return .{ .generated = generated_file }; |
| 988 | } | 968 | } |
| 989 | 969 | ||
| 990 | /// Disables the panic in the build evaluation if nothing is emitted. | 970 | /// deprecated: use `getEmittedBinDirectory` |
| 991 | /// | 971 | pub const getOutputDirectorySource = getEmittedBinDirectory; |
| 992 | /// Unless for compilation tests this is a code smell. | ||
| 993 | pub fn forceBuild(self: *Compile) void { | ||
| 994 | self.force_build = true; | ||
| 995 | } | ||
| 996 | 972 | ||
| 997 | pub fn forceEmit(self: *Compile, emit: EmitOption) void { | 973 | /// Returns the path to the directory that contains the emitted binary file. |
| 998 | switch (emit) { | 974 | pub fn getEmittedBinDirectory(self: *Compile) LazyPath { |
| 999 | .docs => _ = self.getEmittedDocs(), | 975 | _ = self.getEmittedBin(); |
| 1000 | .@"asm" => _ = self.getEmittedAsm(), | 976 | return self.getEmittedFileGeneric(&self.emit_directory); |
| 1001 | .bin => _ = self.getEmittedBin(), | ||
| 1002 | .pdb => _ = self.getEmittedPdb(), | ||
| 1003 | .implib => _ = self.getEmittedImplib(), | ||
| 1004 | .llvm_bc => _ = self.getEmittedLlvmBc(), | ||
| 1005 | .llvm_ir => _ = self.getEmittedLlvmIr(), | ||
| 1006 | .h => _ = self.getEmittedH(), | ||
| 1007 | } | ||
| 1008 | } | 977 | } |
| 1009 | 978 | ||
| 1010 | pub const getOutputDirectorySource = getEmitDirectory; // DEPRECATED, use getEmitDirectory | 979 | /// deprecated: use `getEmittedBin` |
| 1011 | 980 | pub const getOutputSource = getEmittedBin; | |
| 1012 | /// Returns the path to the output directory. | ||
| 1013 | pub fn getEmitDirectory(self: *Compile) LazyPath { | ||
| 1014 | return .{ .generated = &self.emit_directory }; | ||
| 1015 | } | ||
| 1016 | |||
| 1017 | pub const getOutputSource = getEmittedBin; // DEPRECATED, use getEmittedBin | ||
| 1018 | 981 | ||
| 1019 | /// Returns the path to the generated executable, library or object file. | 982 | /// Returns the path to the generated executable, library or object file. |
| 1020 | /// To run an executable built with zig build, use `run`, or create an install step and invoke it. | 983 | /// To run an executable built with zig build, use `run`, or create an install step and invoke it. |
| ... | @@ -1022,15 +985,18 @@ pub fn getEmittedBin(self: *Compile) LazyPath { | ... | @@ -1022,15 +985,18 @@ pub fn getEmittedBin(self: *Compile) LazyPath { |
| 1022 | return self.getEmittedFileGeneric(&self.generated_bin); | 985 | return self.getEmittedFileGeneric(&self.generated_bin); |
| 1023 | } | 986 | } |
| 1024 | 987 | ||
| 1025 | pub const getOutputLibSource = getEmittedImplib; // DEPRECATED, use getEmittedImplib | 988 | /// deprecated: use `getEmittedImplib` |
| 989 | pub const getOutputLibSource = getEmittedImplib; | ||
| 1026 | 990 | ||
| 1027 | /// Returns the path to the generated import library. This function can only be called for libraries. | 991 | /// Returns the path to the generated import library. |
| 992 | /// This function can only be called for libraries. | ||
| 1028 | pub fn getEmittedImplib(self: *Compile) LazyPath { | 993 | pub fn getEmittedImplib(self: *Compile) LazyPath { |
| 1029 | assert(self.kind == .lib); | 994 | assert(self.kind == .lib); |
| 1030 | return self.getEmittedFileGeneric(&self.generated_implib); | 995 | return self.getEmittedFileGeneric(&self.generated_implib); |
| 1031 | } | 996 | } |
| 1032 | 997 | ||
| 1033 | pub const getOutputHSource = getEmittedH; // DEPRECATED, use getEmittedH | 998 | /// deprecated: use `getEmittedH` |
| 999 | pub const getOutputHSource = getEmittedH; | ||
| 1034 | 1000 | ||
| 1035 | /// Returns the path to the generated header file. | 1001 | /// Returns the path to the generated header file. |
| 1036 | /// This function can only be called for libraries or objects. | 1002 | /// This function can only be called for libraries or objects. |
| ... | @@ -1039,11 +1005,14 @@ pub fn getEmittedH(self: *Compile) LazyPath { | ... | @@ -1039,11 +1005,14 @@ pub fn getEmittedH(self: *Compile) LazyPath { |
| 1039 | return self.getEmittedFileGeneric(&self.generated_h); | 1005 | return self.getEmittedFileGeneric(&self.generated_h); |
| 1040 | } | 1006 | } |
| 1041 | 1007 | ||
| 1042 | pub const getOutputPdbSource = getEmittedPdb; // DEPRECATED, use getEmittedPdb | 1008 | /// deprecated: use `getEmittedPdb`. |
| 1009 | pub const getOutputPdbSource = getEmittedPdb; | ||
| 1043 | 1010 | ||
| 1044 | /// Returns the generated PDB file. This function can only be called for Windows and UEFI. | 1011 | /// Returns the generated PDB file. |
| 1012 | /// If the compilation does not produce a PDB file, this causes a FileNotFound error | ||
| 1013 | /// at build time. | ||
| 1045 | pub fn getEmittedPdb(self: *Compile) LazyPath { | 1014 | pub fn getEmittedPdb(self: *Compile) LazyPath { |
| 1046 | assert(self.producesPdbFile()); | 1015 | _ = self.getEmittedBin(); |
| 1047 | return self.getEmittedFileGeneric(&self.generated_pdb); | 1016 | return self.getEmittedFileGeneric(&self.generated_pdb); |
| 1048 | } | 1017 | } |
| 1049 | 1018 | ||
| ... | @@ -1198,13 +1167,11 @@ pub fn setExecCmd(self: *Compile, args: []const ?[]const u8) void { | ... | @@ -1198,13 +1167,11 @@ pub fn setExecCmd(self: *Compile, args: []const ?[]const u8) void { |
| 1198 | } | 1167 | } |
| 1199 | 1168 | ||
| 1200 | fn linkLibraryOrObject(self: *Compile, other: *Compile) void { | 1169 | fn linkLibraryOrObject(self: *Compile, other: *Compile) void { |
| 1201 | other.forceEmit(.bin); | 1170 | other.getEmittedBin().addStepDependencies(&self.step); |
| 1202 | 1171 | if (other.target.isWindows() and other.isDynamicLibrary()) { | |
| 1203 | if (other.target.isWindows() and other.isDynamicLibrary()) { // TODO(xq): Is this the correct logic here? | 1172 | other.getEmittedImplib().addStepDependencies(&self.step); |
| 1204 | other.forceEmit(.implib); | ||
| 1205 | } | 1173 | } |
| 1206 | 1174 | ||
| 1207 | self.step.dependOn(&other.step); | ||
| 1208 | self.link_objects.append(.{ .other_step = other }) catch @panic("OOM"); | 1175 | self.link_objects.append(.{ .other_step = other }) catch @panic("OOM"); |
| 1209 | self.include_dirs.append(.{ .other_step = other }) catch @panic("OOM"); | 1176 | self.include_dirs.append(.{ .other_step = other }) catch @panic("OOM"); |
| 1210 | 1177 | ||
| ... | @@ -1330,7 +1297,7 @@ fn getGeneratedFilePath(self: *Compile, comptime tag_name: []const u8, asking_st | ... | @@ -1330,7 +1297,7 @@ fn getGeneratedFilePath(self: *Compile, comptime tag_name: []const u8, asking_st |
| 1330 | std.debug.getStderrMutex().lock(); | 1297 | std.debug.getStderrMutex().lock(); |
| 1331 | const stderr = std.io.getStdErr(); | 1298 | const stderr = std.io.getStdErr(); |
| 1332 | 1299 | ||
| 1333 | build_util.dumpBadGetPathHelp(&self.step, stderr, self.step.owner, asking_step) catch {}; | 1300 | std.Build.dumpBadGetPathHelp(&self.step, stderr, self.step.owner, asking_step) catch {}; |
| 1334 | 1301 | ||
| 1335 | @panic("missing emit option for " ++ tag_name); | 1302 | @panic("missing emit option for " ++ tag_name); |
| 1336 | }; | 1303 | }; |
| ... | @@ -1339,7 +1306,7 @@ fn getGeneratedFilePath(self: *Compile, comptime tag_name: []const u8, asking_st | ... | @@ -1339,7 +1306,7 @@ fn getGeneratedFilePath(self: *Compile, comptime tag_name: []const u8, asking_st |
| 1339 | std.debug.getStderrMutex().lock(); | 1306 | std.debug.getStderrMutex().lock(); |
| 1340 | const stderr = std.io.getStdErr(); | 1307 | const stderr = std.io.getStdErr(); |
| 1341 | 1308 | ||
| 1342 | build_util.dumpBadGetPathHelp(&self.step, stderr, self.step.owner, asking_step) catch {}; | 1309 | std.Build.dumpBadGetPathHelp(&self.step, stderr, self.step.owner, asking_step) catch {}; |
| 1343 | 1310 | ||
| 1344 | @panic(tag_name ++ " is null. Is there a missing step dependency?"); | 1311 | @panic(tag_name ++ " is null. Is there a missing step dependency?"); |
| 1345 | }; | 1312 | }; |
| ... | @@ -1432,11 +1399,12 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1432,11 +1399,12 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1432 | break :l; | 1399 | break :l; |
| 1433 | } | 1400 | } |
| 1434 | 1401 | ||
| 1435 | // TODO(xq): Is that the right way? | 1402 | // For DLLs, we gotta link against the implib. For |
| 1436 | const full_path_lib = if (other.isDynamicLibrary() and other.target.isWindows()) | 1403 | // everything else, we directly link against the library file. |
| 1437 | other.getGeneratedFilePath("generated_implib", &self.step) // For DLLs, we gotta link against the implib, | 1404 | const full_path_lib = if (other.producesImplib()) |
| 1405 | other.getGeneratedFilePath("generated_implib", &self.step) | ||
| 1438 | else | 1406 | else |
| 1439 | other.getGeneratedFilePath("generated_bin", &self.step); // for everything else, we directly link against the library file | 1407 | other.getGeneratedFilePath("generated_bin", &self.step); |
| 1440 | try zig_args.append(full_path_lib); | 1408 | try zig_args.append(full_path_lib); |
| 1441 | 1409 | ||
| 1442 | if (other.linkage == Linkage.dynamic and !self.target.isWindows()) { | 1410 | if (other.linkage == Linkage.dynamic and !self.target.isWindows()) { |
| ... | @@ -1579,36 +1547,13 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1579,36 +1547,13 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1579 | if (b.verbose_cc or self.verbose_cc) try zig_args.append("--verbose-cc"); | 1547 | if (b.verbose_cc or self.verbose_cc) try zig_args.append("--verbose-cc"); |
| 1580 | if (b.verbose_llvm_cpu_features) try zig_args.append("--verbose-llvm-cpu-features"); | 1548 | if (b.verbose_llvm_cpu_features) try zig_args.append("--verbose-llvm-cpu-features"); |
| 1581 | 1549 | ||
| 1582 | const Emitter = struct { | 1550 | if (self.generated_asm != null) try zig_args.append("-femit-asm"); |
| 1583 | ptr: ?*GeneratedFile, | 1551 | if (self.generated_bin == null) try zig_args.append("-fno-emit-bin"); |
| 1584 | emit_suffix: []const u8, | 1552 | if (self.generated_docs != null) try zig_args.append("-femit-docs"); |
| 1585 | }; | 1553 | if (self.generated_implib != null) try zig_args.append("-femit-implib"); |
| 1586 | 1554 | if (self.generated_llvm_bc != null) try zig_args.append("-femit-llvm-bc"); | |
| 1587 | const generated_files = [_]Emitter{ | 1555 | if (self.generated_llvm_ir != null) try zig_args.append("-femit-llvm-ir"); |
| 1588 | .{ .ptr = self.generated_asm, .emit_suffix = "asm" }, | 1556 | if (self.generated_h != null) try zig_args.append("-femit-h"); |
| 1589 | .{ .ptr = self.generated_bin, .emit_suffix = "bin" }, | ||
| 1590 | .{ .ptr = self.generated_docs, .emit_suffix = "docs" }, | ||
| 1591 | .{ .ptr = self.generated_implib, .emit_suffix = "implib" }, | ||
| 1592 | .{ .ptr = self.generated_llvm_bc, .emit_suffix = "llvm-bc" }, | ||
| 1593 | .{ .ptr = self.generated_llvm_ir, .emit_suffix = "llvm-ir" }, | ||
| 1594 | .{ .ptr = self.generated_h, .emit_suffix = "h" }, | ||
| 1595 | }; | ||
| 1596 | var any_emitted_file = false; | ||
| 1597 | for (generated_files) |file| { | ||
| 1598 | try zig_args.append(if (file.ptr != null) | ||
| 1599 | b.fmt("-femit-{s}", .{file.emit_suffix}) | ||
| 1600 | else | ||
| 1601 | b.fmt("-fno-emit-{s}", .{file.emit_suffix})); | ||
| 1602 | |||
| 1603 | if (file.ptr != null) any_emitted_file = true; | ||
| 1604 | } | ||
| 1605 | |||
| 1606 | if (!any_emitted_file and !self.force_build) { | ||
| 1607 | std.debug.getStderrMutex().lock(); | ||
| 1608 | const stderr = std.io.getStdErr(); | ||
| 1609 | build_util.dumpBadGetPathHelp(&self.step, stderr, self.step.owner, null) catch {}; | ||
| 1610 | std.debug.panic("Artifact '{s}' has no emit options set, but it is made. Did you forget to call `.getEmitted*()`? If not, use `.forceBuild()` or `.forceEmit(…)` to make sure it builds anyways.", .{self.name}); | ||
| 1611 | } | ||
| 1612 | 1557 | ||
| 1613 | try addFlag(&zig_args, "strip", self.strip); | 1558 | try addFlag(&zig_args, "strip", self.strip); |
| 1614 | try addFlag(&zig_args, "unwind-tables", self.unwind_tables); | 1559 | try addFlag(&zig_args, "unwind-tables", self.unwind_tables); |
| ... | @@ -1895,7 +1840,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1895,7 +1840,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1895 | zig_args.appendAssumeCapacity("-rpath"); | 1840 | zig_args.appendAssumeCapacity("-rpath"); |
| 1896 | 1841 | ||
| 1897 | if (self.target_info.target.isDarwin()) switch (rpath) { | 1842 | if (self.target_info.target.isDarwin()) switch (rpath) { |
| 1898 | .path => |path| { | 1843 | .path, .cwd_relative => |path| { |
| 1899 | // On Darwin, we should not try to expand special runtime paths such as | 1844 | // On Darwin, we should not try to expand special runtime paths such as |
| 1900 | // * @executable_path | 1845 | // * @executable_path |
| 1901 | // * @loader_path | 1846 | // * @loader_path |
| ... | @@ -1993,9 +1938,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -1993,9 +1938,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1993 | if (self.zig_lib_dir) |dir| { | 1938 | if (self.zig_lib_dir) |dir| { |
| 1994 | try zig_args.append("--zig-lib-dir"); | 1939 | try zig_args.append("--zig-lib-dir"); |
| 1995 | try zig_args.append(dir.getPath(b)); | 1940 | try zig_args.append(dir.getPath(b)); |
| 1996 | } else if (b.zig_lib_dir) |dir| { | ||
| 1997 | try zig_args.append("--zig-lib-dir"); | ||
| 1998 | try zig_args.append(dir); | ||
| 1999 | } | 1941 | } |
| 2000 | 1942 | ||
| 2001 | if (self.main_pkg_path) |dir| { | 1943 | if (self.main_pkg_path) |dir| { |
| ... | @@ -2093,37 +2035,30 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -2093,37 +2035,30 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 2093 | if (maybe_output_bin_path) |output_bin_path| { | 2035 | if (maybe_output_bin_path) |output_bin_path| { |
| 2094 | const output_dir = fs.path.dirname(output_bin_path).?; | 2036 | const output_dir = fs.path.dirname(output_bin_path).?; |
| 2095 | 2037 | ||
| 2096 | self.emit_directory.path = output_dir; | 2038 | if (self.emit_directory) |lp| { |
| 2039 | lp.path = output_dir; | ||
| 2040 | } | ||
| 2097 | 2041 | ||
| 2098 | // -femit-bin[=path] (default) Output machine code | 2042 | // -femit-bin[=path] (default) Output machine code |
| 2099 | if (self.generated_bin) |bin| { | 2043 | if (self.generated_bin) |bin| { |
| 2100 | bin.path = b.pathJoin( | 2044 | bin.path = b.pathJoin(&.{ output_dir, self.out_filename }); |
| 2101 | &.{ output_dir, self.out_filename }, | ||
| 2102 | ); | ||
| 2103 | } | 2045 | } |
| 2104 | 2046 | ||
| 2047 | const sep = std.fs.path.sep; | ||
| 2048 | |||
| 2105 | // output PDB if someone requested it | 2049 | // output PDB if someone requested it |
| 2106 | if (self.generated_pdb) |pdb| { | 2050 | if (self.generated_pdb) |pdb| { |
| 2107 | std.debug.assert(self.producesPdbFile()); | 2051 | pdb.path = b.fmt("{s}{c}{s}.pdb", .{ output_dir, sep, self.name }); |
| 2108 | pdb.path = b.pathJoin( | ||
| 2109 | &.{ output_dir, self.out_pdb_filename }, | ||
| 2110 | ); | ||
| 2111 | } | 2052 | } |
| 2112 | 2053 | ||
| 2113 | // -femit-implib[=path] (default) Produce an import .lib when building a Windows DLL | 2054 | // -femit-implib[=path] (default) Produce an import .lib when building a Windows DLL |
| 2114 | if (self.kind == .lib) { | 2055 | if (self.generated_implib) |implib| { |
| 2115 | if (self.generated_implib) |lib| { | 2056 | implib.path = b.fmt("{s}{c}{s}.lib", .{ output_dir, sep, self.name }); |
| 2116 | lib.path = b.pathJoin( | ||
| 2117 | &.{ output_dir, self.out_lib_filename }, | ||
| 2118 | ); | ||
| 2119 | } | ||
| 2120 | } | 2057 | } |
| 2121 | 2058 | ||
| 2122 | // -femit-h[=path] Generate a C header file (.h) | 2059 | // -femit-h[=path] Generate a C header file (.h) |
| 2123 | if (self.generated_h) |lazy_path| { | 2060 | if (self.generated_h) |lp| { |
| 2124 | lazy_path.path = b.pathJoin( | 2061 | lp.path = b.fmt("{s}{c}{s}.h", .{ output_dir, sep, self.name }); |
| 2125 | &.{ output_dir, self.out_h_filename }, | ||
| 2126 | ); | ||
| 2127 | } | 2062 | } |
| 2128 | 2063 | ||
| 2129 | // -femit-docs[=path] Create a docs/ dir with html documentation | 2064 | // -femit-docs[=path] Create a docs/ dir with html documentation |
| ... | @@ -2132,24 +2067,18 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -2132,24 +2067,18 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 2132 | } | 2067 | } |
| 2133 | 2068 | ||
| 2134 | // -femit-asm[=path] Output .s (assembly code) | 2069 | // -femit-asm[=path] Output .s (assembly code) |
| 2135 | if (self.generated_asm) |lazy_path| { | 2070 | if (self.generated_asm) |lp| { |
| 2136 | lazy_path.path = b.pathJoin( | 2071 | lp.path = b.fmt("{s}{c}{s}.s", .{ output_dir, sep, self.name }); |
| 2137 | &.{ output_dir, self.out_asm_filename }, | ||
| 2138 | ); | ||
| 2139 | } | 2072 | } |
| 2140 | 2073 | ||
| 2141 | // -femit-llvm-ir[=path] Produce a .ll file with optimized LLVM IR (requires LLVM extensions) | 2074 | // -femit-llvm-ir[=path] Produce a .ll file with optimized LLVM IR (requires LLVM extensions) |
| 2142 | if (self.generated_llvm_ir) |lazy_path| { | 2075 | if (self.generated_llvm_ir) |lp| { |
| 2143 | lazy_path.path = b.pathJoin( | 2076 | lp.path = b.fmt("{s}{c}{s}.ll", .{ output_dir, sep, self.name }); |
| 2144 | &.{ output_dir, self.out_ll_filename }, | ||
| 2145 | ); | ||
| 2146 | } | 2077 | } |
| 2147 | 2078 | ||
| 2148 | // -femit-llvm-bc[=path] Produce an optimized LLVM module as a .bc file (requires LLVM extensions) | 2079 | // -femit-llvm-bc[=path] Produce an optimized LLVM module as a .bc file (requires LLVM extensions) |
| 2149 | if (self.generated_llvm_bc) |lazy_path| { | 2080 | if (self.generated_llvm_bc) |lp| { |
| 2150 | lazy_path.path = b.pathJoin( | 2081 | lp.path = b.fmt("{s}{c}{s}.bc", .{ output_dir, sep, self.name }); |
| 2151 | &.{ output_dir, self.out_bc_filename }, | ||
| 2152 | ); | ||
| 2153 | } | 2082 | } |
| 2154 | } | 2083 | } |
| 2155 | 2084 |
lib/std/Build/Step/ConfigHeader.zig+5-3| ... | @@ -15,7 +15,8 @@ pub const Style = union(enum) { | ... | @@ -15,7 +15,8 @@ pub const Style = union(enum) { |
| 15 | /// Start with nothing, like blank, and output a nasm .asm file. | 15 | /// Start with nothing, like blank, and output a nasm .asm file. |
| 16 | nasm, | 16 | nasm, |
| 17 | 17 | ||
| 18 | pub const getFileSource = getPath; // DEPRECATED, use getPath | 18 | /// deprecated: use `getPath` |
| 19 | pub const getFileSource = getPath; | ||
| 19 | 20 | ||
| 20 | pub fn getPath(style: Style) ?std.Build.LazyPath { | 21 | pub fn getPath(style: Style) ?std.Build.LazyPath { |
| 21 | switch (style) { | 22 | switch (style) { |
| ... | @@ -100,9 +101,10 @@ pub fn addValues(self: *ConfigHeader, values: anytype) void { | ... | @@ -100,9 +101,10 @@ pub fn addValues(self: *ConfigHeader, values: anytype) void { |
| 100 | return addValuesInner(self, values) catch @panic("OOM"); | 101 | return addValuesInner(self, values) catch @panic("OOM"); |
| 101 | } | 102 | } |
| 102 | 103 | ||
| 103 | pub const getFileSource = getTemplate; // DEPRECATED, use getOutput | 104 | /// deprecated: use `getOutput` |
| 105 | pub const getFileSource = getOutput; | ||
| 104 | 106 | ||
| 105 | pub fn getTemplate(self: *ConfigHeader) std.Build.LazyPath { | 107 | pub fn getOutput(self: *ConfigHeader) std.Build.LazyPath { |
| 106 | return .{ .generated = &self.output_file }; | 108 | return .{ .generated = &self.output_file }; |
| 107 | } | 109 | } |
| 108 | 110 |
lib/std/Build/Step/InstallArtifact.zig+112-65| ... | @@ -3,67 +3,117 @@ const Step = std.Build.Step; | ... | @@ -3,67 +3,117 @@ const Step = std.Build.Step; |
| 3 | const InstallDir = std.Build.InstallDir; | 3 | const InstallDir = std.Build.InstallDir; |
| 4 | const InstallArtifact = @This(); | 4 | const InstallArtifact = @This(); |
| 5 | const fs = std.fs; | 5 | const fs = std.fs; |
| 6 | 6 | const LazyPath = std.Build.LazyPath; | |
| 7 | pub const base_id = .install_artifact; | ||
| 8 | 7 | ||
| 9 | step: Step, | 8 | step: Step, |
| 10 | artifact: *Step.Compile, | 9 | |
| 11 | dest_dir: InstallDir, | 10 | dest_dir: ?InstallDir, |
| 11 | dest_sub_path: []const u8, | ||
| 12 | emitted_bin: ?LazyPath, | ||
| 13 | |||
| 14 | implib_dir: ?InstallDir, | ||
| 15 | emitted_implib: ?LazyPath, | ||
| 16 | |||
| 12 | pdb_dir: ?InstallDir, | 17 | pdb_dir: ?InstallDir, |
| 18 | emitted_pdb: ?LazyPath, | ||
| 19 | |||
| 13 | h_dir: ?InstallDir, | 20 | h_dir: ?InstallDir, |
| 14 | /// If non-null, adds additional path components relative to dest_dir, and | 21 | emitted_h: ?LazyPath, |
| 15 | /// overrides the basename of the Compile step. | 22 | |
| 16 | dest_sub_path: ?[]const u8, | 23 | dylib_symlinks: ?DylibSymlinkInfo, |
| 24 | |||
| 25 | artifact: *Step.Compile, | ||
| 26 | |||
| 27 | const DylibSymlinkInfo = struct { | ||
| 28 | major_only_filename: []const u8, | ||
| 29 | name_only_filename: []const u8, | ||
| 30 | }; | ||
| 31 | |||
| 32 | pub const base_id = .install_artifact; | ||
| 33 | |||
| 34 | pub const Options = struct { | ||
| 35 | /// Which installation directory to put the main output file into. | ||
| 36 | dest_dir: Dir = .default, | ||
| 37 | pdb_dir: Dir = .default, | ||
| 38 | h_dir: Dir = .default, | ||
| 39 | implib_dir: Dir = .default, | ||
| 40 | |||
| 41 | /// Whether to install symlinks along with dynamic libraries. | ||
| 42 | dylib_symlinks: ?bool = null, | ||
| 43 | /// If non-null, adds additional path components relative to bin dir, and | ||
| 44 | /// overrides the basename of the Compile step for installation purposes. | ||
| 45 | dest_sub_path: ?[]const u8 = null, | ||
| 17 | 46 | ||
| 18 | pub fn create(owner: *std.Build, artifact: *Step.Compile) *InstallArtifact { | 47 | pub const Dir = union(enum) { |
| 48 | disabled, | ||
| 49 | default, | ||
| 50 | override: InstallDir, | ||
| 51 | }; | ||
| 52 | }; | ||
| 53 | |||
| 54 | pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *InstallArtifact { | ||
| 19 | const self = owner.allocator.create(InstallArtifact) catch @panic("OOM"); | 55 | const self = owner.allocator.create(InstallArtifact) catch @panic("OOM"); |
| 20 | self.* = InstallArtifact{ | 56 | const dest_dir: ?InstallDir = switch (options.dest_dir) { |
| 57 | .disabled => null, | ||
| 58 | .default => switch (artifact.kind) { | ||
| 59 | .obj => @panic("object files have no standard installation procedure"), | ||
| 60 | .exe, .@"test" => InstallDir{ .bin = {} }, | ||
| 61 | .lib => InstallDir{ .lib = {} }, | ||
| 62 | }, | ||
| 63 | .override => |o| o, | ||
| 64 | }; | ||
| 65 | self.* = .{ | ||
| 21 | .step = Step.init(.{ | 66 | .step = Step.init(.{ |
| 22 | .id = base_id, | 67 | .id = base_id, |
| 23 | .name = owner.fmt("install {s}", .{artifact.name}), | 68 | .name = owner.fmt("install {s}", .{artifact.name}), |
| 24 | .owner = owner, | 69 | .owner = owner, |
| 25 | .makeFn = make, | 70 | .makeFn = make, |
| 26 | }), | 71 | }), |
| 27 | .artifact = artifact, | 72 | .dest_dir = dest_dir, |
| 28 | .dest_dir = artifact.override_dest_dir orelse switch (artifact.kind) { | 73 | .pdb_dir = switch (options.pdb_dir) { |
| 29 | .obj => @panic("Cannot install a .obj build artifact."), | 74 | .disabled => null, |
| 30 | .exe, .@"test" => InstallDir{ .bin = {} }, | 75 | .default => if (artifact.producesPdbFile()) dest_dir else null, |
| 31 | .lib => InstallDir{ .lib = {} }, | 76 | .override => |o| o, |
| 32 | }, | 77 | }, |
| 33 | .pdb_dir = if (artifact.producesPdbFile()) blk: { | 78 | .h_dir = switch (options.h_dir) { |
| 34 | if (artifact.kind == .exe or artifact.kind == .@"test") { | 79 | .disabled => null, |
| 35 | break :blk InstallDir{ .bin = {} }; | 80 | .default => switch (artifact.kind) { |
| 36 | } else { | 81 | .lib => .header, |
| 37 | break :blk InstallDir{ .lib = {} }; | 82 | else => null, |
| 38 | } | 83 | }, |
| 84 | .override => |o| o, | ||
| 85 | }, | ||
| 86 | .implib_dir = switch (options.implib_dir) { | ||
| 87 | .disabled => null, | ||
| 88 | .default => if (artifact.producesImplib()) dest_dir else null, | ||
| 89 | .override => |o| o, | ||
| 90 | }, | ||
| 91 | |||
| 92 | .dylib_symlinks = if (options.dylib_symlinks orelse (dest_dir != null and | ||
| 93 | artifact.isDynamicLibrary() and | ||
| 94 | artifact.version != null and | ||
| 95 | artifact.target.wantSharedLibSymLinks())) .{ | ||
| 96 | .major_only_filename = artifact.major_only_filename.?, | ||
| 97 | .name_only_filename = artifact.name_only_filename.?, | ||
| 39 | } else null, | 98 | } else null, |
| 40 | .h_dir = if (artifact.kind == .lib and artifact.generated_h != null) .header else null, | 99 | |
| 41 | .dest_sub_path = null, | 100 | .dest_sub_path = options.dest_sub_path orelse artifact.out_filename, |
| 101 | |||
| 102 | .emitted_bin = null, | ||
| 103 | .emitted_pdb = null, | ||
| 104 | .emitted_h = null, | ||
| 105 | .emitted_implib = null, | ||
| 106 | |||
| 107 | .artifact = artifact, | ||
| 42 | }; | 108 | }; |
| 109 | |||
| 43 | self.step.dependOn(&artifact.step); | 110 | self.step.dependOn(&artifact.step); |
| 44 | 111 | ||
| 45 | artifact.forceEmit(.bin); | 112 | if (self.dest_dir != null) self.emitted_bin = artifact.getEmittedBin(); |
| 113 | if (self.pdb_dir != null) self.emitted_pdb = artifact.getEmittedPdb(); | ||
| 114 | if (self.h_dir != null) self.emitted_h = artifact.getEmittedH(); | ||
| 115 | if (self.implib_dir != null) self.emitted_implib = artifact.getEmittedImplib(); | ||
| 46 | 116 | ||
| 47 | owner.pushInstalledFile(self.dest_dir, artifact.out_filename); | ||
| 48 | if (self.artifact.isDynamicLibrary()) { | ||
| 49 | if (artifact.major_only_filename) |name| { | ||
| 50 | owner.pushInstalledFile(.lib, name); | ||
| 51 | } | ||
| 52 | if (artifact.name_only_filename) |name| { | ||
| 53 | owner.pushInstalledFile(.lib, name); | ||
| 54 | } | ||
| 55 | if (self.artifact.target.isWindows()) { | ||
| 56 | owner.pushInstalledFile(.lib, artifact.out_lib_filename); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | if (self.pdb_dir) |pdb_dir| { | ||
| 60 | _ = artifact.getEmittedPdb(); // force creation | ||
| 61 | owner.pushInstalledFile(pdb_dir, artifact.out_pdb_filename); | ||
| 62 | } | ||
| 63 | if (self.h_dir) |h_dir| { | ||
| 64 | _ = artifact.getEmittedH(); // force creation | ||
| 65 | owner.pushInstalledFile(h_dir, artifact.out_h_filename); | ||
| 66 | } | ||
| 67 | return self; | 117 | return self; |
| 68 | } | 118 | } |
| 69 | 119 | ||
| ... | @@ -71,35 +121,30 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -71,35 +121,30 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 71 | _ = prog_node; | 121 | _ = prog_node; |
| 72 | const self = @fieldParentPtr(InstallArtifact, "step", step); | 122 | const self = @fieldParentPtr(InstallArtifact, "step", step); |
| 73 | const dest_builder = step.owner; | 123 | const dest_builder = step.owner; |
| 74 | |||
| 75 | const dest_sub_path = if (self.dest_sub_path) |sub_path| sub_path else self.artifact.out_filename; | ||
| 76 | const full_dest_path = dest_builder.getInstallPath(self.dest_dir, dest_sub_path); | ||
| 77 | const cwd = fs.cwd(); | 124 | const cwd = fs.cwd(); |
| 78 | 125 | ||
| 79 | var all_cached = true; | 126 | var all_cached = true; |
| 80 | 127 | ||
| 81 | { | 128 | if (self.dest_dir) |dest_dir| { |
| 82 | const full_src_path = self.artifact.generated_bin.?.path.?; | 129 | const full_dest_path = dest_builder.getInstallPath(dest_dir, self.dest_sub_path); |
| 130 | const full_src_path = self.emitted_bin.?.getPath2(step.owner, step); | ||
| 83 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_dest_path, .{}) catch |err| { | 131 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_dest_path, .{}) catch |err| { |
| 84 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ | 132 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ |
| 85 | full_src_path, full_dest_path, @errorName(err), | 133 | full_src_path, full_dest_path, @errorName(err), |
| 86 | }); | 134 | }); |
| 87 | }; | 135 | }; |
| 88 | all_cached = all_cached and p == .fresh; | 136 | all_cached = all_cached and p == .fresh; |
| 89 | } | ||
| 90 | 137 | ||
| 91 | if (self.artifact.isDynamicLibrary() and | 138 | if (self.dylib_symlinks) |dls| { |
| 92 | self.artifact.version != null and | 139 | try Step.Compile.doAtomicSymLinks(step, full_dest_path, dls.major_only_filename, dls.name_only_filename); |
| 93 | self.artifact.target.wantSharedLibSymLinks()) | 140 | } |
| 94 | { | 141 | |
| 95 | try Step.Compile.doAtomicSymLinks(step, full_dest_path, self.artifact.major_only_filename.?, self.artifact.name_only_filename.?); | 142 | self.artifact.installed_path = full_dest_path; |
| 96 | } | 143 | } |
| 97 | if (self.artifact.isDynamicLibrary() and | 144 | |
| 98 | self.artifact.target.isWindows() and | 145 | if (self.implib_dir) |implib_dir| { |
| 99 | self.artifact.generated_implib != null) | 146 | const full_src_path = self.emitted_implib.?.getPath2(step.owner, step); |
| 100 | { | 147 | const full_implib_path = dest_builder.getInstallPath(implib_dir, fs.path.basename(full_src_path)); |
| 101 | const full_src_path = self.artifact.generated_implib.?.path.?; | ||
| 102 | const full_implib_path = dest_builder.getInstallPath(self.dest_dir, self.artifact.out_lib_filename); | ||
| 103 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_implib_path, .{}) catch |err| { | 148 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_implib_path, .{}) catch |err| { |
| 104 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ | 149 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ |
| 105 | full_src_path, full_implib_path, @errorName(err), | 150 | full_src_path, full_implib_path, @errorName(err), |
| ... | @@ -107,9 +152,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -107,9 +152,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 107 | }; | 152 | }; |
| 108 | all_cached = all_cached and p == .fresh; | 153 | all_cached = all_cached and p == .fresh; |
| 109 | } | 154 | } |
| 155 | |||
| 110 | if (self.pdb_dir) |pdb_dir| { | 156 | if (self.pdb_dir) |pdb_dir| { |
| 111 | const full_src_path = self.artifact.generated_pdb.?.path.?; | 157 | const full_src_path = self.emitted_pdb.?.getPath2(step.owner, step); |
| 112 | const full_pdb_path = dest_builder.getInstallPath(pdb_dir, self.artifact.out_pdb_filename); | 158 | const full_pdb_path = dest_builder.getInstallPath(pdb_dir, fs.path.basename(full_src_path)); |
| 113 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_pdb_path, .{}) catch |err| { | 159 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_pdb_path, .{}) catch |err| { |
| 114 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ | 160 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ |
| 115 | full_src_path, full_pdb_path, @errorName(err), | 161 | full_src_path, full_pdb_path, @errorName(err), |
| ... | @@ -117,9 +163,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -117,9 +163,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 117 | }; | 163 | }; |
| 118 | all_cached = all_cached and p == .fresh; | 164 | all_cached = all_cached and p == .fresh; |
| 119 | } | 165 | } |
| 166 | |||
| 120 | if (self.h_dir) |h_dir| { | 167 | if (self.h_dir) |h_dir| { |
| 121 | const full_src_path = self.artifact.generated_h.?.path.?; | 168 | const full_src_path = self.emitted_h.?.getPath2(step.owner, step); |
| 122 | const full_h_path = dest_builder.getInstallPath(h_dir, self.artifact.out_h_filename); | 169 | const full_h_path = dest_builder.getInstallPath(h_dir, fs.path.basename(full_src_path)); |
| 123 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_h_path, .{}) catch |err| { | 170 | const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_h_path, .{}) catch |err| { |
| 124 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ | 171 | return step.fail("unable to update file from '{s}' to '{s}': {s}", .{ |
| 125 | full_src_path, full_h_path, @errorName(err), | 172 | full_src_path, full_h_path, @errorName(err), |
| ... | @@ -127,6 +174,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -127,6 +174,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 127 | }; | 174 | }; |
| 128 | all_cached = all_cached and p == .fresh; | 175 | all_cached = all_cached and p == .fresh; |
| 129 | } | 176 | } |
| 130 | self.artifact.installed_path = full_dest_path; | 177 | |
| 131 | step.result_cached = all_cached; | 178 | step.result_cached = all_cached; |
| 132 | } | 179 | } |
lib/std/Build/Step/ObjCopy.zig+2-1| ... | @@ -60,7 +60,8 @@ pub fn create( | ... | @@ -60,7 +60,8 @@ pub fn create( |
| 60 | return self; | 60 | return self; |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | pub const getOutputSource = getOutput; // DEPRECATED, use getOutput | 63 | /// deprecated: use getOutput |
| 64 | pub const getOutputSource = getOutput; | ||
| 64 | 65 | ||
| 65 | pub fn getOutput(self: *const ObjCopy) std.Build.LazyPath { | 66 | pub fn getOutput(self: *const ObjCopy) std.Build.LazyPath { |
| 66 | return .{ .generated = &self.output_file }; | 67 | return .{ .generated = &self.output_file }; |
lib/std/Build/Step/Options.zig+10-13| ... | @@ -13,7 +13,7 @@ step: Step, | ... | @@ -13,7 +13,7 @@ step: Step, |
| 13 | generated_file: GeneratedFile, | 13 | generated_file: GeneratedFile, |
| 14 | 14 | ||
| 15 | contents: std.ArrayList(u8), | 15 | contents: std.ArrayList(u8), |
| 16 | args: std.ArrayList(OptionLazyPathArg), | 16 | args: std.ArrayList(Arg), |
| 17 | 17 | ||
| 18 | pub fn create(owner: *std.Build) *Options { | 18 | pub fn create(owner: *std.Build) *Options { |
| 19 | const self = owner.allocator.create(Options) catch @panic("OOM"); | 19 | const self = owner.allocator.create(Options) catch @panic("OOM"); |
| ... | @@ -26,7 +26,7 @@ pub fn create(owner: *std.Build) *Options { | ... | @@ -26,7 +26,7 @@ pub fn create(owner: *std.Build) *Options { |
| 26 | }), | 26 | }), |
| 27 | .generated_file = undefined, | 27 | .generated_file = undefined, |
| 28 | .contents = std.ArrayList(u8).init(owner.allocator), | 28 | .contents = std.ArrayList(u8).init(owner.allocator), |
| 29 | .args = std.ArrayList(OptionLazyPathArg).init(owner.allocator), | 29 | .args = std.ArrayList(Arg).init(owner.allocator), |
| 30 | }; | 30 | }; |
| 31 | self.generated_file = .{ .step = &self.step }; | 31 | self.generated_file = .{ .step = &self.step }; |
| 32 | 32 | ||
| ... | @@ -166,7 +166,8 @@ fn printLiteral(out: anytype, val: anytype, indent: u8) !void { | ... | @@ -166,7 +166,8 @@ fn printLiteral(out: anytype, val: anytype, indent: u8) !void { |
| 166 | } | 166 | } |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | pub const addOptionFileSource = addOptionPath; // DEPRECATED, use addPathOption | 169 | /// deprecated: use `addOptionPath` |
| 170 | pub const addOptionFileSource = addOptionPath; | ||
| 170 | 171 | ||
| 171 | /// The value is the path in the cache dir. | 172 | /// The value is the path in the cache dir. |
| 172 | /// Adds a dependency automatically. | 173 | /// Adds a dependency automatically. |
| ... | @@ -182,14 +183,9 @@ pub fn addOptionPath( | ... | @@ -182,14 +183,9 @@ pub fn addOptionPath( |
| 182 | path.addStepDependencies(&self.step); | 183 | path.addStepDependencies(&self.step); |
| 183 | } | 184 | } |
| 184 | 185 | ||
| 185 | /// The value is the path in the cache dir. | 186 | /// Deprecated: use `addOptionPath(options, name, artifact.getEmittedBin())` instead. |
| 186 | /// Adds a dependency automatically. | ||
| 187 | pub fn addOptionArtifact(self: *Options, name: []const u8, artifact: *Step.Compile) void { | 187 | pub fn addOptionArtifact(self: *Options, name: []const u8, artifact: *Step.Compile) void { |
| 188 | self.args.append(.{ | 188 | return addOptionPath(self, name, artifact.getEmittedBin()); |
| 189 | .name = self.step.owner.dupe(name), | ||
| 190 | .artifact = artifact.getEmittedBin, | ||
| 191 | }) catch @panic("OOM"); | ||
| 192 | self.step.dependOn(&artifact.step); | ||
| 193 | } | 189 | } |
| 194 | 190 | ||
| 195 | pub fn createModule(self: *Options) *std.Build.Module { | 191 | pub fn createModule(self: *Options) *std.Build.Module { |
| ... | @@ -199,7 +195,8 @@ pub fn createModule(self: *Options) *std.Build.Module { | ... | @@ -199,7 +195,8 @@ pub fn createModule(self: *Options) *std.Build.Module { |
| 199 | }); | 195 | }); |
| 200 | } | 196 | } |
| 201 | 197 | ||
| 202 | pub const getSource = getOutput; // DEPRECATED, use getOutput | 198 | /// deprecated: use `getOutput` |
| 199 | pub const getSource = getOutput; | ||
| 203 | 200 | ||
| 204 | pub fn getOutput(self: *Options) LazyPath { | 201 | pub fn getOutput(self: *Options) LazyPath { |
| 205 | return .{ .generated = &self.generated_file }; | 202 | return .{ .generated = &self.generated_file }; |
| ... | @@ -226,7 +223,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -226,7 +223,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 226 | var hash = b.cache.hash; | 223 | var hash = b.cache.hash; |
| 227 | // Random bytes to make unique. Refresh this with new random bytes when | 224 | // Random bytes to make unique. Refresh this with new random bytes when |
| 228 | // implementation is modified in a non-backwards-compatible way. | 225 | // implementation is modified in a non-backwards-compatible way. |
| 229 | hash.add(@as(u32, 0x38845ef8)); | 226 | hash.add(@as(u32, 0xad95e922)); |
| 230 | hash.addBytes(self.contents.items); | 227 | hash.addBytes(self.contents.items); |
| 231 | const sub_path = "c" ++ fs.path.sep_str ++ hash.final() ++ fs.path.sep_str ++ basename; | 228 | const sub_path = "c" ++ fs.path.sep_str ++ hash.final() ++ fs.path.sep_str ++ basename; |
| 232 | 229 | ||
| ... | @@ -291,7 +288,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { | ... | @@ -291,7 +288,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 291 | } | 288 | } |
| 292 | } | 289 | } |
| 293 | 290 | ||
| 294 | const OptionLazyPathArg = struct { | 291 | const Arg = struct { |
| 295 | name: []const u8, | 292 | name: []const u8, |
| 296 | path: LazyPath, | 293 | path: LazyPath, |
| 297 | }; | 294 | }; |
lib/std/Build/Step/Run.zig+13-12| ... | @@ -164,12 +164,9 @@ pub fn enableTestRunnerMode(self: *Run) void { | ... | @@ -164,12 +164,9 @@ pub fn enableTestRunnerMode(self: *Run) void { |
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | pub fn addArtifactArg(self: *Run, artifact: *Step.Compile) void { | 166 | pub fn addArtifactArg(self: *Run, artifact: *Step.Compile) void { |
| 167 | // enforce creation of the binary file by invoking getEmittedBin | ||
| 168 | const bin_file = artifact.getEmittedBin(); | 167 | const bin_file = artifact.getEmittedBin(); |
| 169 | bin_file.addStepDependencies(&self.step); | 168 | bin_file.addStepDependencies(&self.step); |
| 170 | |||
| 171 | self.argv.append(Arg{ .artifact = artifact }) catch @panic("OOM"); | 169 | self.argv.append(Arg{ .artifact = artifact }) catch @panic("OOM"); |
| 172 | self.step.dependOn(&artifact.step); | ||
| 173 | } | 170 | } |
| 174 | 171 | ||
| 175 | /// This provides file path as a command line argument to the command being | 172 | /// This provides file path as a command line argument to the command being |
| ... | @@ -201,32 +198,36 @@ pub fn addPrefixedOutputFileArg( | ... | @@ -201,32 +198,36 @@ pub fn addPrefixedOutputFileArg( |
| 201 | return .{ .generated = &output.generated_file }; | 198 | return .{ .generated = &output.generated_file }; |
| 202 | } | 199 | } |
| 203 | 200 | ||
| 204 | pub const addFileSourceArg = addFileArg; // DEPRECATED, use addFileArg | 201 | /// deprecated: use `addFileArg` |
| 202 | pub const addFileSourceArg = addFileArg; | ||
| 205 | 203 | ||
| 206 | pub fn addFileArg(self: *Run, file_source: std.Build.LazyPath) void { | 204 | pub fn addFileArg(self: *Run, lp: std.Build.LazyPath) void { |
| 207 | self.addPrefixedFileArg("", file_source); | 205 | self.addPrefixedFileArg("", lp); |
| 208 | } | 206 | } |
| 209 | 207 | ||
| 210 | pub const addPrefixedFileSourceArg = addPrefixedFileArg; // DEPRECATED, use addPrefixedFileArg | 208 | // deprecated: use `addPrefixedFileArg` |
| 209 | pub const addPrefixedFileSourceArg = addPrefixedFileArg; | ||
| 211 | 210 | ||
| 212 | pub fn addPrefixedFileArg(self: *Run, prefix: []const u8, file_source: std.Build.LazyPath) void { | 211 | pub fn addPrefixedFileArg(self: *Run, prefix: []const u8, lp: std.Build.LazyPath) void { |
| 213 | const b = self.step.owner; | 212 | const b = self.step.owner; |
| 214 | 213 | ||
| 215 | const prefixed_file_source: PrefixedLazyPath = .{ | 214 | const prefixed_file_source: PrefixedLazyPath = .{ |
| 216 | .prefix = b.dupe(prefix), | 215 | .prefix = b.dupe(prefix), |
| 217 | .file_source = file_source.dupe(b), | 216 | .file_source = lp.dupe(b), |
| 218 | }; | 217 | }; |
| 219 | self.argv.append(.{ .file_source = prefixed_file_source }) catch @panic("OOM"); | 218 | self.argv.append(.{ .file_source = prefixed_file_source }) catch @panic("OOM"); |
| 220 | file_source.addStepDependencies(&self.step); | 219 | lp.addStepDependencies(&self.step); |
| 221 | } | 220 | } |
| 222 | 221 | ||
| 223 | pub const addDirectorySourceArg = addDirectoryArg; // DEPRECATED, use addDirectoryArg | 222 | /// deprecated: use `addDirectoryArg` |
| 223 | pub const addDirectorySourceArg = addDirectoryArg; | ||
| 224 | 224 | ||
| 225 | pub fn addDirectoryArg(self: *Run, directory_source: std.Build.LazyPath) void { | 225 | pub fn addDirectoryArg(self: *Run, directory_source: std.Build.LazyPath) void { |
| 226 | self.addPrefixedDirectoryArg("", directory_source); | 226 | self.addPrefixedDirectoryArg("", directory_source); |
| 227 | } | 227 | } |
| 228 | 228 | ||
| 229 | pub const addPrefixedDirectorySourceArg = addPrefixedDirectoryArg; // DEPRECATED, use addPrefixedDirectoryArg | 229 | // deprecated: use `addPrefixedDirectoryArg` |
| 230 | pub const addPrefixedDirectorySourceArg = addPrefixedDirectoryArg; | ||
| 230 | 231 | ||
| 231 | pub fn addPrefixedDirectoryArg(self: *Run, prefix: []const u8, directory_source: std.Build.LazyPath) void { | 232 | pub fn addPrefixedDirectoryArg(self: *Run, prefix: []const u8, directory_source: std.Build.LazyPath) void { |
| 232 | const b = self.step.owner; | 233 | const b = self.step.owner; |
lib/std/Build/Step/WriteFile.zig+2-1| ... | @@ -28,7 +28,8 @@ pub const File = struct { | ... | @@ -28,7 +28,8 @@ pub const File = struct { |
| 28 | sub_path: []const u8, | 28 | sub_path: []const u8, |
| 29 | contents: Contents, | 29 | contents: Contents, |
| 30 | 30 | ||
| 31 | pub const getFileSource = getPath; // DEPRECATED, use getPath | 31 | /// deprecated: use `getPath` |
| 32 | pub const getFileSource = getPath; | ||
| 32 | 33 | ||
| 33 | pub fn getPath(self: *File) std.Build.LazyPath { | 34 | pub fn getPath(self: *File) std.Build.LazyPath { |
| 34 | return .{ .generated = &self.generated_file }; | 35 | return .{ .generated = &self.generated_file }; |
lib/std/Build/util.zig deleted-53| ... | @@ -1,53 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const fs = std.fs; | ||
| 3 | |||
| 4 | const Build = std.Build; | ||
| 5 | const Step = std.Build.Step; | ||
| 6 | |||
| 7 | /// In this function the stderr mutex has already been locked. | ||
| 8 | pub fn dumpBadGetPathHelp( | ||
| 9 | s: *Step, | ||
| 10 | stderr: fs.File, | ||
| 11 | src_builder: *Build, | ||
| 12 | asking_step: ?*Step, | ||
| 13 | ) anyerror!void { | ||
| 14 | const w = stderr.writer(); | ||
| 15 | try w.print( | ||
| 16 | \\getPath() was called on a GeneratedFile that wasn't built yet. | ||
| 17 | \\ source package path: {s} | ||
| 18 | \\ Is there a missing Step dependency on step '{s}'? | ||
| 19 | \\ | ||
| 20 | , .{ | ||
| 21 | src_builder.build_root.path orelse ".", | ||
| 22 | s.name, | ||
| 23 | }); | ||
| 24 | |||
| 25 | const tty_config = std.io.tty.detectConfig(stderr); | ||
| 26 | tty_config.setColor(w, .red) catch {}; | ||
| 27 | try stderr.writeAll(" The step was created by this stack trace:\n"); | ||
| 28 | tty_config.setColor(w, .reset) catch {}; | ||
| 29 | |||
| 30 | const debug_info = std.debug.getSelfDebugInfo() catch |err| { | ||
| 31 | try w.print("Unable to dump stack trace: Unable to open debug info: {s}\n", .{@errorName(err)}); | ||
| 32 | return; | ||
| 33 | }; | ||
| 34 | const ally = debug_info.allocator; | ||
| 35 | std.debug.writeStackTrace(s.getStackTrace(), w, ally, debug_info, tty_config) catch |err| { | ||
| 36 | try stderr.writer().print("Unable to dump stack trace: {s}\n", .{@errorName(err)}); | ||
| 37 | return; | ||
| 38 | }; | ||
| 39 | if (asking_step) |as| { | ||
| 40 | tty_config.setColor(w, .red) catch {}; | ||
| 41 | try stderr.writeAll(" The step that is missing a dependency on the above step was created by this stack trace:\n"); | ||
| 42 | tty_config.setColor(w, .reset) catch {}; | ||
| 43 | |||
| 44 | std.debug.writeStackTrace(as.getStackTrace(), w, ally, debug_info, tty_config) catch |err| { | ||
| 45 | try stderr.writer().print("Unable to dump stack trace: {s}\n", .{@errorName(err)}); | ||
| 46 | return; | ||
| 47 | }; | ||
| 48 | } | ||
| 49 | |||
| 50 | tty_config.setColor(w, .red) catch {}; | ||
| 51 | try stderr.writeAll(" Hope that helps. Proceeding to panic.\n"); | ||
| 52 | tty_config.setColor(w, .reset) catch {}; | ||
| 53 | } | ||
test/link/glibc_compat/build.zig+3-2| ... | @@ -4,7 +4,7 @@ pub fn build(b: *std.Build) void { | ... | @@ -4,7 +4,7 @@ pub fn build(b: *std.Build) void { |
| 4 | const test_step = b.step("test", "Test"); | 4 | const test_step = b.step("test", "Test"); |
| 5 | b.default_step = test_step; | 5 | b.default_step = test_step; |
| 6 | 6 | ||
| 7 | inline for (.{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| { | 7 | for ([_][]const u8{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| { |
| 8 | const exe = b.addExecutable(.{ | 8 | const exe = b.addExecutable(.{ |
| 9 | .name = t, | 9 | .name = t, |
| 10 | .root_source_file = .{ .path = "main.c" }, | 10 | .root_source_file = .{ .path = "main.c" }, |
| ... | @@ -13,7 +13,8 @@ pub fn build(b: *std.Build) void { | ... | @@ -13,7 +13,8 @@ pub fn build(b: *std.Build) void { |
| 13 | ) catch unreachable, | 13 | ) catch unreachable, |
| 14 | }); | 14 | }); |
| 15 | exe.linkLibC(); | 15 | exe.linkLibC(); |
| 16 | exe.forceBuild(); | 16 | // TODO: actually test the output |
| 17 | _ = exe.getEmittedBin(); | ||
| 17 | test_step.dependOn(&exe.step); | 18 | test_step.dependOn(&exe.step); |
| 18 | } | 19 | } |
| 19 | } | 20 | } |
test/link/macho/dylib/build.zig+2-2| ... | @@ -41,8 +41,8 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -41,8 +41,8 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 41 | }); | 41 | }); |
| 42 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); | 42 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); |
| 43 | exe.linkSystemLibrary("a"); | 43 | exe.linkSystemLibrary("a"); |
| 44 | exe.addLibraryPath(dylib.getEmitDirectory()); | 44 | exe.addLibraryPath(dylib.getEmittedBinDirectory()); |
| 45 | exe.addRPath(dylib.getEmitDirectory()); | 45 | exe.addRPath(dylib.getEmittedBinDirectory()); |
| 46 | exe.linkLibC(); | 46 | exe.linkLibC(); |
| 47 | 47 | ||
| 48 | const check_exe = exe.checkObject(); | 48 | const check_exe = exe.checkObject(); |
test/link/macho/needed_library/build.zig+2-3| ... | @@ -23,7 +23,6 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -23,7 +23,6 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 23 | }); | 23 | }); |
| 24 | dylib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} }); | 24 | dylib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} }); |
| 25 | dylib.linkLibC(); | 25 | dylib.linkLibC(); |
| 26 | dylib.forceEmit(.bin); // enforce library creation, we import it below | ||
| 27 | 26 | ||
| 28 | // -dead_strip_dylibs | 27 | // -dead_strip_dylibs |
| 29 | // -needed-la | 28 | // -needed-la |
| ... | @@ -35,8 +34,8 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -35,8 +34,8 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 35 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); | 34 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); |
| 36 | exe.linkLibC(); | 35 | exe.linkLibC(); |
| 37 | exe.linkSystemLibraryNeeded("a"); | 36 | exe.linkSystemLibraryNeeded("a"); |
| 38 | exe.addLibraryPath(dylib.getEmitDirectory()); | 37 | exe.addLibraryPath(dylib.getEmittedBinDirectory()); |
| 39 | exe.addRPath(dylib.getEmitDirectory()); | 38 | exe.addRPath(dylib.getEmittedBinDirectory()); |
| 40 | exe.dead_strip_dylibs = true; | 39 | exe.dead_strip_dylibs = true; |
| 41 | 40 | ||
| 42 | const check = exe.checkObject(); | 41 | const check = exe.checkObject(); |
test/link/macho/search_strategy/build.zig+3-11| ... | @@ -57,10 +57,6 @@ fn createScenario( | ... | @@ -57,10 +57,6 @@ fn createScenario( |
| 57 | }); | 57 | }); |
| 58 | static.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} }); | 58 | static.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} }); |
| 59 | static.linkLibC(); | 59 | static.linkLibC(); |
| 60 | static.override_dest_dir = std.Build.InstallDir{ | ||
| 61 | .custom = "static", | ||
| 62 | }; | ||
| 63 | static.forceEmit(.bin); | ||
| 64 | 60 | ||
| 65 | const dylib = b.addSharedLibrary(.{ | 61 | const dylib = b.addSharedLibrary(.{ |
| 66 | .name = name, | 62 | .name = name, |
| ... | @@ -70,10 +66,6 @@ fn createScenario( | ... | @@ -70,10 +66,6 @@ fn createScenario( |
| 70 | }); | 66 | }); |
| 71 | dylib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} }); | 67 | dylib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} }); |
| 72 | dylib.linkLibC(); | 68 | dylib.linkLibC(); |
| 73 | dylib.override_dest_dir = std.Build.InstallDir{ | ||
| 74 | .custom = "dynamic", | ||
| 75 | }; | ||
| 76 | dylib.forceEmit(.bin); // we want the binary to be built as we use it further below | ||
| 77 | 69 | ||
| 78 | const exe = b.addExecutable(.{ | 70 | const exe = b.addExecutable(.{ |
| 79 | .name = name, | 71 | .name = name, |
| ... | @@ -83,8 +75,8 @@ fn createScenario( | ... | @@ -83,8 +75,8 @@ fn createScenario( |
| 83 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); | 75 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} }); |
| 84 | exe.linkSystemLibraryName(name); | 76 | exe.linkSystemLibraryName(name); |
| 85 | exe.linkLibC(); | 77 | exe.linkLibC(); |
| 86 | exe.addLibraryPath(static.getEmitDirectory()); | 78 | exe.addLibraryPath(static.getEmittedBinDirectory()); |
| 87 | exe.addLibraryPath(dylib.getEmitDirectory()); | 79 | exe.addLibraryPath(dylib.getEmittedBinDirectory()); |
| 88 | exe.addRPath(dylib.getEmitDirectory()); | 80 | exe.addRPath(dylib.getEmittedBinDirectory()); |
| 89 | return exe; | 81 | return exe; |
| 90 | } | 82 | } |
test/link/macho/tbdv3/build.zig+1-2| ... | @@ -25,7 +25,6 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -25,7 +25,6 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 25 | }); | 25 | }); |
| 26 | lib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} }); | 26 | lib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} }); |
| 27 | lib.linkLibC(); | 27 | lib.linkLibC(); |
| 28 | lib.forceEmit(.bin); // will be referenced by the tbd file | ||
| 29 | 28 | ||
| 30 | const tbd_file = b.addWriteFile("liba.tbd", | 29 | const tbd_file = b.addWriteFile("liba.tbd", |
| 31 | \\--- !tapi-tbd-v3 | 30 | \\--- !tapi-tbd-v3 |
| ... | @@ -47,7 +46,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -47,7 +46,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 47 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); | 46 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); |
| 48 | exe.linkSystemLibrary("a"); | 47 | exe.linkSystemLibrary("a"); |
| 49 | exe.addLibraryPath(tbd_file.getDirectory()); | 48 | exe.addLibraryPath(tbd_file.getDirectory()); |
| 50 | exe.addRPath(lib.getEmitDirectory()); | 49 | exe.addRPath(lib.getEmittedBinDirectory()); |
| 51 | exe.linkLibC(); | 50 | exe.linkLibC(); |
| 52 | 51 | ||
| 53 | const run = b.addRunArtifact(exe); | 52 | const run = b.addRunArtifact(exe); |
test/link/macho/weak_library/build.zig+2-2| ... | @@ -33,8 +33,8 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize | ... | @@ -33,8 +33,8 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize |
| 33 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); | 33 | exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} }); |
| 34 | exe.linkLibC(); | 34 | exe.linkLibC(); |
| 35 | exe.linkSystemLibraryWeak("a"); | 35 | exe.linkSystemLibraryWeak("a"); |
| 36 | exe.addLibraryPath(dylib.getEmitDirectory()); | 36 | exe.addLibraryPath(dylib.getEmittedBinDirectory()); |
| 37 | exe.addRPath(dylib.getEmitDirectory()); | 37 | exe.addRPath(dylib.getEmittedBinDirectory()); |
| 38 | 38 | ||
| 39 | const check = exe.checkObject(); | 39 | const check = exe.checkObject(); |
| 40 | check.checkStart(); | 40 | check.checkStart(); |
test/src/Cases.zig-6| ... | @@ -551,12 +551,6 @@ pub fn lowerToBuildSteps( | ... | @@ -551,12 +551,6 @@ pub fn lowerToBuildSteps( |
| 551 | }), | 551 | }), |
| 552 | }; | 552 | }; |
| 553 | 553 | ||
| 554 | if (case.emit_bin) { | ||
| 555 | artifact.forceEmit(.bin); | ||
| 556 | } else { | ||
| 557 | artifact.forceBuild(); | ||
| 558 | } | ||
| 559 | |||
| 560 | if (case.link_libc) artifact.linkLibC(); | 554 | if (case.link_libc) artifact.linkLibC(); |
| 561 | 555 | ||
| 562 | switch (case.backend) { | 556 | switch (case.backend) { |
test/standalone.zig+8-8| ... | @@ -141,15 +141,15 @@ pub const build_cases = [_]BuildCase{ | ... | @@ -141,15 +141,15 @@ pub const build_cases = [_]BuildCase{ |
| 141 | .import = @import("standalone/install_raw_hex/build.zig"), | 141 | .import = @import("standalone/install_raw_hex/build.zig"), |
| 142 | }, | 142 | }, |
| 143 | // TODO take away EmitOption.emit_to option and make it give a FileSource | 143 | // TODO take away EmitOption.emit_to option and make it give a FileSource |
| 144 | // .{ | 144 | //.{ |
| 145 | // .build_root = "test/standalone/emit_asm_and_bin", | 145 | // .build_root = "test/standalone/emit_asm_and_bin", |
| 146 | // .import = @import("standalone/emit_asm_and_bin/build.zig"), | 146 | // .import = @import("standalone/emit_asm_and_bin/build.zig"), |
| 147 | // }, | 147 | //}, |
| 148 | // TODO take away EmitOption.emit_to option and make it give a FileSource | 148 | // TODO take away EmitOption.emit_to option and make it give a FileSource |
| 149 | // .{ | 149 | //.{ |
| 150 | // .build_root = "test/standalone/issue_12588", | 150 | // .build_root = "test/standalone/issue_12588", |
| 151 | // .import = @import("standalone/issue_12588/build.zig"), | 151 | // .import = @import("standalone/issue_12588/build.zig"), |
| 152 | // }, | 152 | //}, |
| 153 | .{ | 153 | .{ |
| 154 | .build_root = "test/standalone/child_process", | 154 | .build_root = "test/standalone/child_process", |
| 155 | .import = @import("standalone/child_process/build.zig"), | 155 | .import = @import("standalone/child_process/build.zig"), |
test/standalone/compiler_rt_panic/build.zig+4-1| ... | @@ -16,7 +16,10 @@ pub fn build(b: *std.Build) void { | ... | @@ -16,7 +16,10 @@ pub fn build(b: *std.Build) void { |
| 16 | .target = target, | 16 | .target = target, |
| 17 | }); | 17 | }); |
| 18 | exe.linkLibC(); | 18 | exe.linkLibC(); |
| 19 | exe.addCSourceFile("main.c", &.{}); | 19 | exe.addCSourceFile(.{ |
| 20 | .file = .{ .path = "main.c" }, | ||
| 21 | .flags = &.{}, | ||
| 22 | }); | ||
| 20 | exe.link_gc_sections = false; | 23 | exe.link_gc_sections = false; |
| 21 | exe.bundle_compiler_rt = true; | 24 | exe.bundle_compiler_rt = true; |
| 22 | 25 |
test/standalone/embed_generated_file/build.zig+2-1| ... | @@ -22,7 +22,8 @@ pub fn build(b: *std.Build) void { | ... | @@ -22,7 +22,8 @@ pub fn build(b: *std.Build) void { |
| 22 | .source_file = bootloader.getEmittedBin(), | 22 | .source_file = bootloader.getEmittedBin(), |
| 23 | }); | 23 | }); |
| 24 | 24 | ||
| 25 | exe.forceBuild(); | 25 | // TODO: actually check the output |
| 26 | _ = exe.getEmittedBin(); | ||
| 26 | 27 | ||
| 27 | test_step.dependOn(&exe.step); | 28 | test_step.dependOn(&exe.step); |
| 28 | } | 29 | } |
test/standalone/emit_asm_and_bin/build.zig+3-2| ... | @@ -8,8 +8,9 @@ pub fn build(b: *std.Build) void { | ... | @@ -8,8 +8,9 @@ pub fn build(b: *std.Build) void { |
| 8 | .root_source_file = .{ .path = "main.zig" }, | 8 | .root_source_file = .{ .path = "main.zig" }, |
| 9 | .optimize = b.standardOptimizeOption(.{}), | 9 | .optimize = b.standardOptimizeOption(.{}), |
| 10 | }); | 10 | }); |
| 11 | main.forceEmit(.bin); | 11 | // TODO: actually check these two artifacts for correctness |
| 12 | main.forceEmit(.@"asm"); | 12 | _ = main.getEmittedBin(); |
| 13 | _ = main.getEmittedAsm(); | ||
| 13 | 14 | ||
| 14 | test_step.dependOn(&b.addRunArtifact(main).step); | 15 | test_step.dependOn(&b.addRunArtifact(main).step); |
| 15 | } | 16 | } |
test/standalone/issue_339/build.zig+2-1| ... | @@ -14,7 +14,8 @@ pub fn build(b: *std.Build) void { | ... | @@ -14,7 +14,8 @@ pub fn build(b: *std.Build) void { |
| 14 | .optimize = optimize, | 14 | .optimize = optimize, |
| 15 | }); | 15 | }); |
| 16 | 16 | ||
| 17 | obj.forceBuild(); | 17 | // TODO: actually check the output |
| 18 | _ = obj.getEmittedBin(); | ||
| 18 | 19 | ||
| 19 | test_step.dependOn(&obj.step); | 20 | test_step.dependOn(&obj.step); |
| 20 | } | 21 | } |
test/standalone/issue_5825/build.zig+2-1| ... | @@ -27,7 +27,8 @@ pub fn build(b: *std.Build) void { | ... | @@ -27,7 +27,8 @@ pub fn build(b: *std.Build) void { |
| 27 | exe.linkSystemLibrary("ntdll"); | 27 | exe.linkSystemLibrary("ntdll"); |
| 28 | exe.addObject(obj); | 28 | exe.addObject(obj); |
| 29 | 29 | ||
| 30 | exe.forceBuild(); | 30 | // TODO: actually check the output |
| 31 | _ = exe.getEmittedBin(); | ||
| 31 | 32 | ||
| 32 | test_step.dependOn(&exe.step); | 33 | test_step.dependOn(&exe.step); |
| 33 | } | 34 | } |
test/standalone/issue_794/build.zig+2-1| ... | @@ -9,7 +9,8 @@ pub fn build(b: *std.Build) void { | ... | @@ -9,7 +9,8 @@ pub fn build(b: *std.Build) void { |
| 9 | }); | 9 | }); |
| 10 | test_artifact.addIncludePath(.{ .path = "a_directory" }); | 10 | test_artifact.addIncludePath(.{ .path = "a_directory" }); |
| 11 | 11 | ||
| 12 | test_artifact.forceBuild(); | 12 | // TODO: actually check the output |
| 13 | _ = test_artifact.getEmittedBin(); | ||
| 13 | 14 | ||
| 14 | test_step.dependOn(&test_artifact.step); | 15 | test_step.dependOn(&test_artifact.step); |
| 15 | } | 16 | } |
test/standalone/main_pkg_path/build.zig+1-1| ... | @@ -6,8 +6,8 @@ pub fn build(b: *std.Build) void { | ... | @@ -6,8 +6,8 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | ||
| 7 | const test_exe = b.addTest(.{ | 7 | const test_exe = b.addTest(.{ |
| 8 | .root_source_file = .{ .path = "a/test.zig" }, | 8 | .root_source_file = .{ .path = "a/test.zig" }, |
| 9 | .main_pkg_path = .{ .path = "." }, | ||
| 9 | }); | 10 | }); |
| 10 | test_exe.setMainPkgPath(.{ .path = "." }); | ||
| 11 | 11 | ||
| 12 | test_step.dependOn(&b.addRunArtifact(test_exe).step); | 12 | test_step.dependOn(&b.addRunArtifact(test_exe).step); |
| 13 | } | 13 | } |
test/standalone/strip_empty_loop/build.zig+2-1| ... | @@ -15,7 +15,8 @@ pub fn build(b: *std.Build) void { | ... | @@ -15,7 +15,8 @@ pub fn build(b: *std.Build) void { |
| 15 | }); | 15 | }); |
| 16 | main.strip = true; | 16 | main.strip = true; |
| 17 | 17 | ||
| 18 | main.forceBuild(); | 18 | // TODO: actually check the output |
| 19 | _ = main.getEmittedBin(); | ||
| 19 | 20 | ||
| 20 | test_step.dependOn(&main.step); | 21 | test_step.dependOn(&main.step); |
| 21 | } | 22 | } |
test/tests.zig+3-3| ... | @@ -588,7 +588,7 @@ pub fn addStandaloneTests( | ... | @@ -588,7 +588,7 @@ pub fn addStandaloneTests( |
| 588 | }); | 588 | }); |
| 589 | if (case.link_libc) exe.linkLibC(); | 589 | if (case.link_libc) exe.linkLibC(); |
| 590 | 590 | ||
| 591 | exe.forceBuild(); | 591 | _ = exe.getEmittedBin(); |
| 592 | 592 | ||
| 593 | step.dependOn(&exe.step); | 593 | step.dependOn(&exe.step); |
| 594 | } | 594 | } |
| ... | @@ -1008,6 +1008,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { | ... | @@ -1008,6 +1008,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1008 | .single_threaded = test_target.single_threaded, | 1008 | .single_threaded = test_target.single_threaded, |
| 1009 | .use_llvm = test_target.use_llvm, | 1009 | .use_llvm = test_target.use_llvm, |
| 1010 | .use_lld = test_target.use_lld, | 1010 | .use_lld = test_target.use_lld, |
| 1011 | .zig_lib_dir = .{ .path = "lib" }, | ||
| 1011 | }); | 1012 | }); |
| 1012 | const single_threaded_suffix = if (test_target.single_threaded == true) "-single" else ""; | 1013 | const single_threaded_suffix = if (test_target.single_threaded == true) "-single" else ""; |
| 1013 | const backend_suffix = if (test_target.use_llvm == true) | 1014 | const backend_suffix = if (test_target.use_llvm == true) |
| ... | @@ -1019,7 +1020,6 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { | ... | @@ -1019,7 +1020,6 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1019 | else | 1020 | else |
| 1020 | ""; | 1021 | ""; |
| 1021 | 1022 | ||
| 1022 | these_tests.overrideZigLibDir(.{ .path = "lib" }); | ||
| 1023 | these_tests.addIncludePath(.{ .path = "test" }); | 1023 | these_tests.addIncludePath(.{ .path = "test" }); |
| 1024 | 1024 | ||
| 1025 | const qualified_name = b.fmt("{s}-{s}-{s}{s}{s}{s}", .{ | 1025 | const qualified_name = b.fmt("{s}-{s}-{s}{s}{s}{s}", .{ |
| ... | @@ -1039,8 +1039,8 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { | ... | @@ -1039,8 +1039,8 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 1039 | .name = qualified_name, | 1039 | .name = qualified_name, |
| 1040 | .link_libc = test_target.link_libc, | 1040 | .link_libc = test_target.link_libc, |
| 1041 | .target = altered_target, | 1041 | .target = altered_target, |
| 1042 | .zig_lib_dir = .{ .path = "lib" }, | ||
| 1042 | }); | 1043 | }); |
| 1043 | compile_c.overrideZigLibDir(.{ .path = "lib" }); | ||
| 1044 | compile_c.addCSourceFile(.{ | 1044 | compile_c.addCSourceFile(.{ |
| 1045 | .file = these_tests.getEmittedBin(), | 1045 | .file = these_tests.getEmittedBin(), |
| 1046 | .flags = &.{ | 1046 | .flags = &.{ |