authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-29 23:57:52-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-30 11:19:32-07:00
log38840e2e586d71f2b38ed825ea02529f615c5f0c
tree5c31180307056823d2fc8a5aab73f094ad4d729d
parentf8386de7ae12fca1e50e7920964fd7c47301fc05

build system: follow-up enhancements regarding LazyPath

* 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 {
4545 const docgen_cmd = b.addRunArtifact(docgen_exe);
4646 docgen_cmd.addArgs(&.{ "--zig", b.zig_exe });
4747 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);
4950 }
5051 docgen_cmd.addFileArg(.{ .path = "doc/langref.html.in" });
5152 const langref_file = docgen_cmd.addOutputFileArg("langref.html");
......@@ -57,8 +58,8 @@ pub fn build(b: *std.Build) !void {
5758 const autodoc_test = b.addTest(.{
5859 .root_source_file = .{ .path = "lib/std/std.zig" },
5960 .target = target,
61 .zig_lib_dir = .{ .path = "lib" },
6062 });
61 autodoc_test.overrideZigLibDir(.{ .path = "lib" });
6263 const install_std_docs = b.addInstallDirectory(.{
6364 .source_dir = autodoc_test.getEmittedDocs(),
6465 .install_dir = .prefix,
......@@ -87,8 +88,8 @@ pub fn build(b: *std.Build) !void {
8788 .name = "check-case",
8889 .root_source_file = .{ .path = "test/src/Cases.zig" },
8990 .optimize = optimize,
91 .main_pkg_path = .{ .path = "." },
9092 });
91 check_case_exe.setMainPkgPath(.{ .path = "." });
9293 check_case_exe.stack_size = stack_size;
9394 check_case_exe.single_threaded = single_threaded;
9495
......@@ -203,7 +204,7 @@ pub fn build(b: *std.Build) !void {
203204 );
204205
205206 if (!no_bin) {
206 const install_exe = b.addInstallArtifact(exe);
207 const install_exe = b.addInstallArtifact(exe, .{});
207208 if (flat) {
208209 install_exe.dest_dir = .prefix;
209210 }
......@@ -357,8 +358,8 @@ pub fn build(b: *std.Build) !void {
357358 else
358359 &[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };
359360
360 exe.addIncludePath(.{ .path = tracy_path });
361 exe.addCSourceFile(.{ .file = .{ .path = client_cpp }, .flags = tracy_c_flags });
361 exe.addIncludePath(.{ .cwd_relative = tracy_path });
362 exe.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags });
362363 if (!enable_llvm) {
363364 exe.linkSystemLibraryName("c++");
364365 }
......@@ -597,7 +598,7 @@ fn addCmakeCfgOptionsToExe(
597598 // useful for package maintainers
598599 exe.headerpad_max_install_names = true;
599600 }
600 exe.addObjectFile(.{ .path = b.pathJoin(&[_][]const u8{
601 exe.addObjectFile(.{ .cwd_relative = b.pathJoin(&[_][]const u8{
601602 cfg.cmake_binary_dir,
602603 "zigcpp",
603604 b.fmt("{s}{s}{s}", .{
......@@ -607,9 +608,9 @@ fn addCmakeCfgOptionsToExe(
607608 }),
608609 }) });
609610 assert(cfg.lld_include_dir.len != 0);
610 exe.addIncludePath(.{ .path = cfg.lld_include_dir });
611 exe.addIncludePath(.{ .path = cfg.llvm_include_dir });
612 exe.addLibraryPath(.{ .path = cfg.llvm_lib_dir });
611 exe.addIncludePath(.{ .cwd_relative = cfg.lld_include_dir });
612 exe.addIncludePath(.{ .cwd_relative = cfg.llvm_include_dir });
613 exe.addLibraryPath(.{ .cwd_relative = cfg.llvm_lib_dir });
613614 addCMakeLibraryList(exe, cfg.clang_libraries);
614615 addCMakeLibraryList(exe, cfg.lld_libraries);
615616 addCMakeLibraryList(exe, cfg.llvm_libraries);
......@@ -665,7 +666,7 @@ fn addCmakeCfgOptionsToExe(
665666 }
666667
667668 if (cfg.dia_guids_lib.len != 0) {
668 exe.addObjectFile(.{ .path = cfg.dia_guids_lib });
669 exe.addObjectFile(.{ .cwd_relative = cfg.dia_guids_lib });
669670 }
670671}
671672
......@@ -726,7 +727,7 @@ fn addCxxKnownPath(
726727 }
727728 return error.RequiredLibraryNotFound;
728729 }
729 exe.addObjectFile(.{ .path = path_unpadded });
730 exe.addObjectFile(.{ .cwd_relative = path_unpadded });
730731
731732 // TODO a way to integrate with system c++ include files here
732733 // c++ -E -Wp,-v -xc++ /dev/null
......@@ -746,7 +747,7 @@ fn addCMakeLibraryList(exe: *std.Build.Step.Compile, list: []const u8) void {
746747 } else if (exe.target.isWindows() and mem.endsWith(u8, lib, ".lib") and !fs.path.isAbsolute(lib)) {
747748 exe.linkSystemLibrary(lib[0 .. lib.len - ".lib".len]);
748749 } else {
749 exe.addObjectFile(.{ .path = lib });
750 exe.addObjectFile(.{ .cwd_relative = lib });
750751 }
751752 }
752753}
lib/build_runner.zig+2-2
......@@ -188,10 +188,10 @@ pub fn main() !void {
188188 usageAndErr(builder, false, stderr_stream);
189189 };
190190 } 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 {
192192 std.debug.print("Expected argument after {s}\n\n", .{arg});
193193 usageAndErr(builder, false, stderr_stream);
194 };
194 } };
195195 } else if (mem.eql(u8, arg, "--debug-log")) {
196196 const next_arg = nextArg(args, &arg_idx) orelse {
197197 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;
1919const Sha256 = std.crypto.hash.sha2.Sha256;
2020const Build = @This();
2121
22const build_util = @import("Build/util.zig");
23
2422pub const Cache = @import("Build/Cache.zig");
2523
2624/// deprecated: use `Step.Compile`.
......@@ -59,6 +57,8 @@ pub const RunStep = @import("Build/Step/Run.zig");
5957pub const TranslateCStep = @import("Build/Step/TranslateC.zig");
6058/// deprecated: use `Step.WriteFile`.
6159pub const WriteFileStep = @import("Build/Step/WriteFile.zig");
60/// deprecated: use `LazyPath`.
61pub const FileSource = LazyPath;
6262
6363install_tls: TopLevelStep,
6464uninstall_tls: TopLevelStep,
......@@ -95,8 +95,7 @@ build_root: Cache.Directory,
9595cache_root: Cache.Directory,
9696global_cache_root: Cache.Directory,
9797cache: *Cache,
98/// If non-null, overrides the default zig lib dir.
99zig_lib_dir: ?[]const u8,
98zig_lib_dir: ?LazyPath,
10099vcpkg_root: VcpkgRoot = .unattempted,
101100pkg_config_pkg_list: ?(PkgConfigError![]const PkgConfigPkg) = null,
102101args: ?[][]const u8 = null,
......@@ -483,6 +482,8 @@ pub const ExecutableOptions = struct {
483482 single_threaded: ?bool = null,
484483 use_llvm: ?bool = null,
485484 use_lld: ?bool = null,
485 zig_lib_dir: ?LazyPath = null,
486 main_pkg_path: ?LazyPath = null,
486487};
487488
488489pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {
......@@ -499,6 +500,8 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {
499500 .single_threaded = options.single_threaded,
500501 .use_llvm = options.use_llvm,
501502 .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,
502505 });
503506}
504507
......@@ -512,6 +515,8 @@ pub const ObjectOptions = struct {
512515 single_threaded: ?bool = null,
513516 use_llvm: ?bool = null,
514517 use_lld: ?bool = null,
518 zig_lib_dir: ?LazyPath = null,
519 main_pkg_path: ?LazyPath = null,
515520};
516521
517522pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {
......@@ -526,6 +531,8 @@ pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {
526531 .single_threaded = options.single_threaded,
527532 .use_llvm = options.use_llvm,
528533 .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,
529536 });
530537}
531538
......@@ -540,6 +547,8 @@ pub const SharedLibraryOptions = struct {
540547 single_threaded: ?bool = null,
541548 use_llvm: ?bool = null,
542549 use_lld: ?bool = null,
550 zig_lib_dir: ?LazyPath = null,
551 main_pkg_path: ?LazyPath = null,
543552};
544553
545554pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile {
......@@ -556,6 +565,8 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile
556565 .single_threaded = options.single_threaded,
557566 .use_llvm = options.use_llvm,
558567 .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,
559570 });
560571}
561572
......@@ -570,6 +581,8 @@ pub const StaticLibraryOptions = struct {
570581 single_threaded: ?bool = null,
571582 use_llvm: ?bool = null,
572583 use_lld: ?bool = null,
584 zig_lib_dir: ?LazyPath = null,
585 main_pkg_path: ?LazyPath = null,
573586};
574587
575588pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile {
......@@ -586,6 +599,8 @@ pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile
586599 .single_threaded = options.single_threaded,
587600 .use_llvm = options.use_llvm,
588601 .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,
589604 });
590605}
591606
......@@ -602,6 +617,8 @@ pub const TestOptions = struct {
602617 single_threaded: ?bool = null,
603618 use_llvm: ?bool = null,
604619 use_lld: ?bool = null,
620 zig_lib_dir: ?LazyPath = null,
621 main_pkg_path: ?LazyPath = null,
605622};
606623
607624pub fn addTest(b: *Build, options: TestOptions) *Step.Compile {
......@@ -618,6 +635,8 @@ pub fn addTest(b: *Build, options: TestOptions) *Step.Compile {
618635 .single_threaded = options.single_threaded,
619636 .use_llvm = options.use_llvm,
620637 .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,
621640 });
622641}
623642
......@@ -627,6 +646,7 @@ pub const AssemblyOptions = struct {
627646 target: CrossTarget,
628647 optimize: std.builtin.Mode,
629648 max_rss: usize = 0,
649 zig_lib_dir: ?LazyPath = null,
630650};
631651
632652pub fn addAssembly(b: *Build, options: AssemblyOptions) *Step.Compile {
......@@ -637,6 +657,7 @@ pub fn addAssembly(b: *Build, options: AssemblyOptions) *Step.Compile {
637657 .target = options.target,
638658 .optimize = options.optimize,
639659 .max_rss = options.max_rss,
660 .zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir,
640661 });
641662 obj_step.addAssemblyLazyPath(options.source_file.dupe(b));
642663 return obj_step;
......@@ -1259,12 +1280,21 @@ fn printCmd(ally: Allocator, cwd: ?[]const u8, argv: []const []const u8) void {
12591280 std.debug.print("{s}\n", .{text});
12601281}
12611282
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.
12621286pub fn installArtifact(self: *Build, artifact: *Step.Compile) void {
1263 self.getInstallStep().dependOn(&self.addInstallArtifact(artifact).step);
1287 self.getInstallStep().dependOn(&self.addInstallArtifact(artifact, .{}).step);
12641288}
12651289
1266pub fn addInstallArtifact(self: *Build, artifact: *Step.Compile) *Step.InstallArtifact {
1267 return Step.InstallArtifact.create(self, artifact);
1290/// This merely creates the step; it does not add it to the dependencies of the
1291/// top-level install step.
1292pub 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);
12681298}
12691299
12701300///`dest_rel_path` is relative to prefix path
......@@ -1330,6 +1360,7 @@ pub fn addCheckFile(
13301360 return Step.CheckFile.create(b, file_source, options);
13311361}
13321362
1363/// deprecated: https://github.com/ziglang/zig/issues/14943
13331364pub fn pushInstalledFile(self: *Build, dir: InstallDir, dest_rel_path: []const u8) void {
13341365 const file = InstalledFile{
13351366 .dir = dir,
......@@ -1632,19 +1663,27 @@ pub const GeneratedFile = struct {
16321663 }
16331664};
16341665
1635pub const FileSource = LazyPath; // DEPRECATED, use LazyPath now
1636
16371666/// A reference to an existing or future path.
16381667pub 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`.
16401671 path: []const u8,
16411672
16421673 /// A file that is generated by an interface. Those files usually are
16431674 /// not available until built by a build step.
16441675 generated: *const GeneratedFile,
16451676
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
16461685 /// 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.
16481687 pub fn relative(path: []const u8) LazyPath {
16491688 std.debug.assert(!std.fs.path.isAbsolute(path));
16501689 return LazyPath{ .path = path };
......@@ -1654,7 +1693,7 @@ pub const LazyPath = union(enum) {
16541693 /// Either returns the path or `"generated"`.
16551694 pub fn getDisplayName(self: LazyPath) []const u8 {
16561695 return switch (self) {
1657 .path => self.path,
1696 .path, .cwd_relative => self.path,
16581697 .generated => "generated",
16591698 };
16601699 }
......@@ -1662,26 +1701,34 @@ pub const LazyPath = union(enum) {
16621701 /// Adds dependencies this file source implies to the given step.
16631702 pub fn addStepDependencies(self: LazyPath, other_step: *Step) void {
16641703 switch (self) {
1665 .path => {},
1704 .path, .cwd_relative => {},
16661705 .generated => |gen| other_step.dependOn(gen.step),
16671706 }
16681707 }
16691708
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.
16711713 pub fn getPath(self: LazyPath, src_builder: *Build) []const u8 {
16721714 return getPath2(self, src_builder, null);
16731715 }
16741716
1675 /// Should only be called during make(), returns a path relative to the build root or absolute.
1676 /// asking_step is only used for debugging purposes; it's the step being run that is asking for
1677 /// the path.
1717 /// Returns a path relative to the current process's current working directory, suitable
1718 /// for direct file system operations.
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.
16781724 pub fn getPath2(self: LazyPath, src_builder: *Build, asking_step: ?*Step) []const u8 {
16791725 switch (self) {
16801726 .path => |p| return src_builder.pathFromRoot(p),
1727 .cwd_relative => |p| return p,
16811728 .generated => |gen| return gen.path orelse {
16821729 std.debug.getStderrMutex().lock();
16831730 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 {};
16851732 @panic("misconfigured build script");
16861733 },
16871734 }
......@@ -1691,11 +1738,60 @@ pub const LazyPath = union(enum) {
16911738 pub fn dupe(self: LazyPath, b: *Build) LazyPath {
16921739 return switch (self) {
16931740 .path => |p| .{ .path = b.dupePath(p) },
1741 .cwd_relative => |p| .{ .cwd_relative = b.dupePath(p) },
16941742 .generated => |gen| .{ .generated = gen },
16951743 };
16961744 }
16971745};
16981746
1747/// In this function the stderr mutex has already been locked.
1748pub 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
16991795/// Allocates a new string for assigning a value to a named macro.
17001796/// If the value is omitted, it is set to 1.
17011797/// `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(
423423 });
424424 }
425425
426 if (s.cast(Compile)) |compile| {
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 );
426 return result;
435427}
436428
437429fn 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;
2121const GeneratedFile = std.Build.GeneratedFile;
2222const Compile = @This();
2323
24const build_util = @import("../util.zig");
25
2624pub const base_id: Step.Id = .compile;
2725
2826step: Step,
......@@ -68,7 +66,9 @@ max_memory: ?u64 = null,
6866shared_memory: bool = false,
6967global_base: ?u64 = null,
7068c_std: std.Build.CStd,
69/// Set via options; intended to be read-only after that.
7170zig_lib_dir: ?LazyPath,
71/// Set via options; intended to be read-only after that.
7272main_pkg_path: ?LazyPath,
7373exec_cmd_args: ?[]const ?[]const u8,
7474filter: ?[]const u8,
......@@ -80,12 +80,7 @@ wasi_exec_model: ?std.builtin.WasiExecModel = null,
8080export_symbol_names: []const []const u8 = &.{},
8181
8282root_src: ?LazyPath,
83out_h_filename: []const u8,
84out_ll_filename: []const u8,
85out_bc_filename: []const u8,
86out_asm_filename: []const u8,
8783out_lib_filename: []const u8,
88out_pdb_filename: []const u8,
8984modules: std.StringArrayHashMap(*Module),
9085
9186link_objects: ArrayList(LinkObject),
......@@ -96,8 +91,6 @@ is_linking_libc: bool,
9691is_linking_libcpp: bool,
9792vcpkg_bin_path: ?[]const u8 = null,
9893
99/// This may be set in order to override the default install directory
100override_dest_dir: ?InstallDir,
10194installed_path: ?[]const u8,
10295
10396/// Base address for an executable image.
......@@ -207,9 +200,7 @@ use_lld: ?bool,
207200/// otherwise.
208201expect_errors: []const []const u8 = &.{},
209202
210force_build: bool,
211
212emit_directory: GeneratedFile,
203emit_directory: ?*GeneratedFile,
213204
214205generated_docs: ?*GeneratedFile,
215206generated_asm: ?*GeneratedFile,
......@@ -221,6 +212,7 @@ generated_llvm_ir: ?*GeneratedFile,
221212generated_h: ?*GeneratedFile,
222213
223214pub const CSourceFiles = struct {
215 /// Relative to the build root.
224216 files: []const []const u8,
225217 flags: []const []const u8,
226218};
......@@ -289,6 +281,8 @@ pub const Options = struct {
289281 single_threaded: ?bool = null,
290282 use_llvm: ?bool = null,
291283 use_lld: ?bool = null,
284 zig_lib_dir: ?LazyPath = null,
285 main_pkg_path: ?LazyPath = null,
292286};
293287
294288pub const BuildId = union(enum) {
......@@ -376,17 +370,6 @@ pub const Kind = enum {
376370
377371pub const Linkage = enum { dynamic, static };
378372
379pub const EmitOption = enum {
380 docs,
381 @"asm",
382 bin,
383 pdb,
384 implib,
385 llvm_bc,
386 llvm_ir,
387 h,
388};
389
390373pub fn create(owner: *std.Build, options: Options) *Compile {
391374 const name = owner.dupe(options.name);
392375 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 {
451434 }),
452435 .version = options.version,
453436 .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}),
458437 .out_lib_filename = undefined,
459 .out_pdb_filename = owner.fmt("{s}.pdb", .{name}),
460438 .major_only_filename = null,
461439 .name_only_filename = null,
462440 .modules = std.StringArrayHashMap(*Module).init(owner.allocator),
......@@ -477,14 +455,10 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
477455 .disable_sanitize_c = false,
478456 .sanitize_thread = false,
479457 .rdynamic = false,
480 .override_dest_dir = null,
481458 .installed_path = null,
482459 .force_undefined_symbols = StringHashMap(void).init(owner.allocator),
483460
484 .force_build = false,
485
486 .emit_directory = GeneratedFile{ .step = &self.step },
487
461 .emit_directory = null,
488462 .generated_docs = null,
489463 .generated_asm = null,
490464 .generated_bin = null,
......@@ -503,6 +477,16 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
503477 .use_lld = options.use_lld,
504478 };
505479
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
506490 if (self.kind == .lib) {
507491 if (self.linkage != null and self.linkage.? == .static) {
508492 self.out_lib_filename = self.out_filename;
......@@ -636,7 +620,8 @@ pub fn checkObject(self: *Compile) *Step.CheckObject {
636620 return Step.CheckObject.create(self.step.owner, self.getEmittedBin(), self.target_info.target.ofmt);
637621}
638622
639pub const setLinkerScriptPath = setLinkerScript; // DEPRECATED, use setLinkerScript
623/// deprecated: use `setLinkerScript`
624pub const setLinkerScriptPath = setLinkerScript;
640625
641626pub fn setLinkerScript(self: *Compile, source: LazyPath) void {
642627 const b = self.step.owner;
......@@ -700,12 +685,17 @@ pub fn isStaticLibrary(self: *Compile) bool {
700685
701686pub fn producesPdbFile(self: *Compile) bool {
702687 // TODO: Is this right? Isn't PDB for *any* PE/COFF file?
688 // TODO: just share this logic with the compiler, silly!
703689 if (!self.target.isWindows() and !self.target.isUefi()) return false;
704690 if (self.target.getObjectFormat() == .c) return false;
705691 if (self.strip == true or (self.strip == null and self.optimize == .ReleaseSmall)) return false;
706692 return self.isDynamicLibrary() or self.kind == .exe or self.kind == .@"test";
707693}
708694
695pub fn producesImplib(self: *Compile) bool {
696 return self.isDynamicLibrary() and self.target.isWindows();
697}
698
709699pub fn linkLibC(self: *Compile) void {
710700 self.is_linking_libc = true;
711701}
......@@ -961,16 +951,6 @@ pub fn setVerboseCC(self: *Compile, value: bool) void {
961951 self.verbose_cc = value;
962952}
963953
964pub 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
969pub 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
974954pub fn setLibCFile(self: *Compile, libc_file: ?LazyPath) void {
975955 const b = self.step.owner;
976956 self.libc_file = if (libc_file) |f| f.dupe(b) else null;
......@@ -987,34 +967,17 @@ fn getEmittedFileGeneric(self: *Compile, output_file: *?*GeneratedFile) LazyPath
987967 return .{ .generated = generated_file };
988968}
989969
990/// Disables the panic in the build evaluation if nothing is emitted.
991///
992/// Unless for compilation tests this is a code smell.
993pub fn forceBuild(self: *Compile) void {
994 self.force_build = true;
995}
970/// deprecated: use `getEmittedBinDirectory`
971pub const getOutputDirectorySource = getEmittedBinDirectory;
996972
997pub fn forceEmit(self: *Compile, emit: EmitOption) void {
998 switch (emit) {
999 .docs => _ = self.getEmittedDocs(),
1000 .@"asm" => _ = self.getEmittedAsm(),
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 }
973/// Returns the path to the directory that contains the emitted binary file.
974pub fn getEmittedBinDirectory(self: *Compile) LazyPath {
975 _ = self.getEmittedBin();
976 return self.getEmittedFileGeneric(&self.emit_directory);
1008977}
1009978
1010pub const getOutputDirectorySource = getEmitDirectory; // DEPRECATED, use getEmitDirectory
1011
1012/// Returns the path to the output directory.
1013pub fn getEmitDirectory(self: *Compile) LazyPath {
1014 return .{ .generated = &self.emit_directory };
1015}
1016
1017pub const getOutputSource = getEmittedBin; // DEPRECATED, use getEmittedBin
979/// deprecated: use `getEmittedBin`
980pub const getOutputSource = getEmittedBin;
1018981
1019982/// Returns the path to the generated executable, library or object file.
1020983/// 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 {
1022985 return self.getEmittedFileGeneric(&self.generated_bin);
1023986}
1024987
1025pub const getOutputLibSource = getEmittedImplib; // DEPRECATED, use getEmittedImplib
988/// deprecated: use `getEmittedImplib`
989pub const getOutputLibSource = getEmittedImplib;
1026990
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.
1028993pub fn getEmittedImplib(self: *Compile) LazyPath {
1029994 assert(self.kind == .lib);
1030995 return self.getEmittedFileGeneric(&self.generated_implib);
1031996}
1032997
1033pub const getOutputHSource = getEmittedH; // DEPRECATED, use getEmittedH
998/// deprecated: use `getEmittedH`
999pub const getOutputHSource = getEmittedH;
10341000
10351001/// Returns the path to the generated header file.
10361002/// This function can only be called for libraries or objects.
......@@ -1039,11 +1005,14 @@ pub fn getEmittedH(self: *Compile) LazyPath {
10391005 return self.getEmittedFileGeneric(&self.generated_h);
10401006}
10411007
1042pub const getOutputPdbSource = getEmittedPdb; // DEPRECATED, use getEmittedPdb
1008/// deprecated: use `getEmittedPdb`.
1009pub const getOutputPdbSource = getEmittedPdb;
10431010
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.
10451014pub fn getEmittedPdb(self: *Compile) LazyPath {
1046 assert(self.producesPdbFile());
1015 _ = self.getEmittedBin();
10471016 return self.getEmittedFileGeneric(&self.generated_pdb);
10481017}
10491018
......@@ -1198,13 +1167,11 @@ pub fn setExecCmd(self: *Compile, args: []const ?[]const u8) void {
11981167}
11991168
12001169fn linkLibraryOrObject(self: *Compile, other: *Compile) void {
1201 other.forceEmit(.bin);
1202
1203 if (other.target.isWindows() and other.isDynamicLibrary()) { // TODO(xq): Is this the correct logic here?
1204 other.forceEmit(.implib);
1170 other.getEmittedBin().addStepDependencies(&self.step);
1171 if (other.target.isWindows() and other.isDynamicLibrary()) {
1172 other.getEmittedImplib().addStepDependencies(&self.step);
12051173 }
12061174
1207 self.step.dependOn(&other.step);
12081175 self.link_objects.append(.{ .other_step = other }) catch @panic("OOM");
12091176 self.include_dirs.append(.{ .other_step = other }) catch @panic("OOM");
12101177
......@@ -1330,7 +1297,7 @@ fn getGeneratedFilePath(self: *Compile, comptime tag_name: []const u8, asking_st
13301297 std.debug.getStderrMutex().lock();
13311298 const stderr = std.io.getStdErr();
13321299
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 {};
13341301
13351302 @panic("missing emit option for " ++ tag_name);
13361303 };
......@@ -1339,7 +1306,7 @@ fn getGeneratedFilePath(self: *Compile, comptime tag_name: []const u8, asking_st
13391306 std.debug.getStderrMutex().lock();
13401307 const stderr = std.io.getStdErr();
13411308
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 {};
13431310
13441311 @panic(tag_name ++ " is null. Is there a missing step dependency?");
13451312 };
......@@ -1432,11 +1399,12 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
14321399 break :l;
14331400 }
14341401
1435 // TODO(xq): Is that the right way?
1436 const full_path_lib = if (other.isDynamicLibrary() and other.target.isWindows())
1437 other.getGeneratedFilePath("generated_implib", &self.step) // For DLLs, we gotta link against the implib,
1402 // For DLLs, we gotta link against the implib. For
1403 // everything else, we directly link against the library file.
1404 const full_path_lib = if (other.producesImplib())
1405 other.getGeneratedFilePath("generated_implib", &self.step)
14381406 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);
14401408 try zig_args.append(full_path_lib);
14411409
14421410 if (other.linkage == Linkage.dynamic and !self.target.isWindows()) {
......@@ -1579,36 +1547,13 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
15791547 if (b.verbose_cc or self.verbose_cc) try zig_args.append("--verbose-cc");
15801548 if (b.verbose_llvm_cpu_features) try zig_args.append("--verbose-llvm-cpu-features");
15811549
1582 const Emitter = struct {
1583 ptr: ?*GeneratedFile,
1584 emit_suffix: []const u8,
1585 };
1586
1587 const generated_files = [_]Emitter{
1588 .{ .ptr = self.generated_asm, .emit_suffix = "asm" },
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 }
1550 if (self.generated_asm != null) try zig_args.append("-femit-asm");
1551 if (self.generated_bin == null) try zig_args.append("-fno-emit-bin");
1552 if (self.generated_docs != null) try zig_args.append("-femit-docs");
1553 if (self.generated_implib != null) try zig_args.append("-femit-implib");
1554 if (self.generated_llvm_bc != null) try zig_args.append("-femit-llvm-bc");
1555 if (self.generated_llvm_ir != null) try zig_args.append("-femit-llvm-ir");
1556 if (self.generated_h != null) try zig_args.append("-femit-h");
16121557
16131558 try addFlag(&zig_args, "strip", self.strip);
16141559 try addFlag(&zig_args, "unwind-tables", self.unwind_tables);
......@@ -1895,7 +1840,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
18951840 zig_args.appendAssumeCapacity("-rpath");
18961841
18971842 if (self.target_info.target.isDarwin()) switch (rpath) {
1898 .path => |path| {
1843 .path, .cwd_relative => |path| {
18991844 // On Darwin, we should not try to expand special runtime paths such as
19001845 // * @executable_path
19011846 // * @loader_path
......@@ -1993,9 +1938,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
19931938 if (self.zig_lib_dir) |dir| {
19941939 try zig_args.append("--zig-lib-dir");
19951940 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);
19991941 }
20001942
20011943 if (self.main_pkg_path) |dir| {
......@@ -2093,37 +2035,30 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
20932035 if (maybe_output_bin_path) |output_bin_path| {
20942036 const output_dir = fs.path.dirname(output_bin_path).?;
20952037
2096 self.emit_directory.path = output_dir;
2038 if (self.emit_directory) |lp| {
2039 lp.path = output_dir;
2040 }
20972041
20982042 // -femit-bin[=path] (default) Output machine code
20992043 if (self.generated_bin) |bin| {
2100 bin.path = b.pathJoin(
2101 &.{ output_dir, self.out_filename },
2102 );
2044 bin.path = b.pathJoin(&.{ output_dir, self.out_filename });
21032045 }
21042046
2047 const sep = std.fs.path.sep;
2048
21052049 // output PDB if someone requested it
21062050 if (self.generated_pdb) |pdb| {
2107 std.debug.assert(self.producesPdbFile());
2108 pdb.path = b.pathJoin(
2109 &.{ output_dir, self.out_pdb_filename },
2110 );
2051 pdb.path = b.fmt("{s}{c}{s}.pdb", .{ output_dir, sep, self.name });
21112052 }
21122053
21132054 // -femit-implib[=path] (default) Produce an import .lib when building a Windows DLL
2114 if (self.kind == .lib) {
2115 if (self.generated_implib) |lib| {
2116 lib.path = b.pathJoin(
2117 &.{ output_dir, self.out_lib_filename },
2118 );
2119 }
2055 if (self.generated_implib) |implib| {
2056 implib.path = b.fmt("{s}{c}{s}.lib", .{ output_dir, sep, self.name });
21202057 }
21212058
21222059 // -femit-h[=path] Generate a C header file (.h)
2123 if (self.generated_h) |lazy_path| {
2124 lazy_path.path = b.pathJoin(
2125 &.{ output_dir, self.out_h_filename },
2126 );
2060 if (self.generated_h) |lp| {
2061 lp.path = b.fmt("{s}{c}{s}.h", .{ output_dir, sep, self.name });
21272062 }
21282063
21292064 // -femit-docs[=path] Create a docs/ dir with html documentation
......@@ -2132,24 +2067,18 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
21322067 }
21332068
21342069 // -femit-asm[=path] Output .s (assembly code)
2135 if (self.generated_asm) |lazy_path| {
2136 lazy_path.path = b.pathJoin(
2137 &.{ output_dir, self.out_asm_filename },
2138 );
2070 if (self.generated_asm) |lp| {
2071 lp.path = b.fmt("{s}{c}{s}.s", .{ output_dir, sep, self.name });
21392072 }
21402073
21412074 // -femit-llvm-ir[=path] Produce a .ll file with optimized LLVM IR (requires LLVM extensions)
2142 if (self.generated_llvm_ir) |lazy_path| {
2143 lazy_path.path = b.pathJoin(
2144 &.{ output_dir, self.out_ll_filename },
2145 );
2075 if (self.generated_llvm_ir) |lp| {
2076 lp.path = b.fmt("{s}{c}{s}.ll", .{ output_dir, sep, self.name });
21462077 }
21472078
21482079 // -femit-llvm-bc[=path] Produce an optimized LLVM module as a .bc file (requires LLVM extensions)
2149 if (self.generated_llvm_bc) |lazy_path| {
2150 lazy_path.path = b.pathJoin(
2151 &.{ output_dir, self.out_bc_filename },
2152 );
2080 if (self.generated_llvm_bc) |lp| {
2081 lp.path = b.fmt("{s}{c}{s}.bc", .{ output_dir, sep, self.name });
21532082 }
21542083 }
21552084
lib/std/Build/Step/ConfigHeader.zig+5-3
......@@ -15,7 +15,8 @@ pub const Style = union(enum) {
1515 /// Start with nothing, like blank, and output a nasm .asm file.
1616 nasm,
1717
18 pub const getFileSource = getPath; // DEPRECATED, use getPath
18 /// deprecated: use `getPath`
19 pub const getFileSource = getPath;
1920
2021 pub fn getPath(style: Style) ?std.Build.LazyPath {
2122 switch (style) {
......@@ -100,9 +101,10 @@ pub fn addValues(self: *ConfigHeader, values: anytype) void {
100101 return addValuesInner(self, values) catch @panic("OOM");
101102}
102103
103pub const getFileSource = getTemplate; // DEPRECATED, use getOutput
104/// deprecated: use `getOutput`
105pub const getFileSource = getOutput;
104106
105pub fn getTemplate(self: *ConfigHeader) std.Build.LazyPath {
107pub fn getOutput(self: *ConfigHeader) std.Build.LazyPath {
106108 return .{ .generated = &self.output_file };
107109}
108110
lib/std/Build/Step/InstallArtifact.zig+112-65
......@@ -3,67 +3,117 @@ const Step = std.Build.Step;
33const InstallDir = std.Build.InstallDir;
44const InstallArtifact = @This();
55const fs = std.fs;
6
7pub const base_id = .install_artifact;
6const LazyPath = std.Build.LazyPath;
87
98step: Step,
10artifact: *Step.Compile,
11dest_dir: InstallDir,
9
10dest_dir: ?InstallDir,
11dest_sub_path: []const u8,
12emitted_bin: ?LazyPath,
13
14implib_dir: ?InstallDir,
15emitted_implib: ?LazyPath,
16
1217pdb_dir: ?InstallDir,
18emitted_pdb: ?LazyPath,
19
1320h_dir: ?InstallDir,
14/// If non-null, adds additional path components relative to dest_dir, and
15/// overrides the basename of the Compile step.
16dest_sub_path: ?[]const u8,
21emitted_h: ?LazyPath,
22
23dylib_symlinks: ?DylibSymlinkInfo,
24
25artifact: *Step.Compile,
26
27const DylibSymlinkInfo = struct {
28 major_only_filename: []const u8,
29 name_only_filename: []const u8,
30};
31
32pub const base_id = .install_artifact;
33
34pub 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,
1746
18pub 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
54pub fn create(owner: *std.Build, artifact: *Step.Compile, options: Options) *InstallArtifact {
1955 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.* = .{
2166 .step = Step.init(.{
2267 .id = base_id,
2368 .name = owner.fmt("install {s}", .{artifact.name}),
2469 .owner = owner,
2570 .makeFn = make,
2671 }),
27 .artifact = artifact,
28 .dest_dir = artifact.override_dest_dir orelse switch (artifact.kind) {
29 .obj => @panic("Cannot install a .obj build artifact."),
30 .exe, .@"test" => InstallDir{ .bin = {} },
31 .lib => InstallDir{ .lib = {} },
72 .dest_dir = dest_dir,
73 .pdb_dir = switch (options.pdb_dir) {
74 .disabled => null,
75 .default => if (artifact.producesPdbFile()) dest_dir else null,
76 .override => |o| o,
3277 },
33 .pdb_dir = if (artifact.producesPdbFile()) blk: {
34 if (artifact.kind == .exe or artifact.kind == .@"test") {
35 break :blk InstallDir{ .bin = {} };
36 } else {
37 break :blk InstallDir{ .lib = {} };
38 }
78 .h_dir = switch (options.h_dir) {
79 .disabled => null,
80 .default => switch (artifact.kind) {
81 .lib => .header,
82 else => null,
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.?,
3998 } else null,
40 .h_dir = if (artifact.kind == .lib and artifact.generated_h != null) .header else null,
41 .dest_sub_path = null,
99
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,
42108 };
109
43110 self.step.dependOn(&artifact.step);
44111
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();
46116
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 }
67117 return self;
68118}
69119
......@@ -71,35 +121,30 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
71121 _ = prog_node;
72122 const self = @fieldParentPtr(InstallArtifact, "step", step);
73123 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);
77124 const cwd = fs.cwd();
78125
79126 var all_cached = true;
80127
81 {
82 const full_src_path = self.artifact.generated_bin.?.path.?;
128 if (self.dest_dir) |dest_dir| {
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);
83131 const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_dest_path, .{}) catch |err| {
84132 return step.fail("unable to update file from '{s}' to '{s}': {s}", .{
85133 full_src_path, full_dest_path, @errorName(err),
86134 });
87135 };
88136 all_cached = all_cached and p == .fresh;
89 }
90137
91 if (self.artifact.isDynamicLibrary() and
92 self.artifact.version != null and
93 self.artifact.target.wantSharedLibSymLinks())
94 {
95 try Step.Compile.doAtomicSymLinks(step, full_dest_path, self.artifact.major_only_filename.?, self.artifact.name_only_filename.?);
138 if (self.dylib_symlinks) |dls| {
139 try Step.Compile.doAtomicSymLinks(step, full_dest_path, dls.major_only_filename, dls.name_only_filename);
140 }
141
142 self.artifact.installed_path = full_dest_path;
96143 }
97 if (self.artifact.isDynamicLibrary() and
98 self.artifact.target.isWindows() and
99 self.artifact.generated_implib != null)
100 {
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);
144
145 if (self.implib_dir) |implib_dir| {
146 const full_src_path = self.emitted_implib.?.getPath2(step.owner, step);
147 const full_implib_path = dest_builder.getInstallPath(implib_dir, fs.path.basename(full_src_path));
103148 const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_implib_path, .{}) catch |err| {
104149 return step.fail("unable to update file from '{s}' to '{s}': {s}", .{
105150 full_src_path, full_implib_path, @errorName(err),
......@@ -107,9 +152,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
107152 };
108153 all_cached = all_cached and p == .fresh;
109154 }
155
110156 if (self.pdb_dir) |pdb_dir| {
111 const full_src_path = self.artifact.generated_pdb.?.path.?;
112 const full_pdb_path = dest_builder.getInstallPath(pdb_dir, self.artifact.out_pdb_filename);
157 const full_src_path = self.emitted_pdb.?.getPath2(step.owner, step);
158 const full_pdb_path = dest_builder.getInstallPath(pdb_dir, fs.path.basename(full_src_path));
113159 const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_pdb_path, .{}) catch |err| {
114160 return step.fail("unable to update file from '{s}' to '{s}': {s}", .{
115161 full_src_path, full_pdb_path, @errorName(err),
......@@ -117,9 +163,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
117163 };
118164 all_cached = all_cached and p == .fresh;
119165 }
166
120167 if (self.h_dir) |h_dir| {
121 const full_src_path = self.artifact.generated_h.?.path.?;
122 const full_h_path = dest_builder.getInstallPath(h_dir, self.artifact.out_h_filename);
168 const full_src_path = self.emitted_h.?.getPath2(step.owner, step);
169 const full_h_path = dest_builder.getInstallPath(h_dir, fs.path.basename(full_src_path));
123170 const p = fs.Dir.updateFile(cwd, full_src_path, cwd, full_h_path, .{}) catch |err| {
124171 return step.fail("unable to update file from '{s}' to '{s}': {s}", .{
125172 full_src_path, full_h_path, @errorName(err),
......@@ -127,6 +174,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
127174 };
128175 all_cached = all_cached and p == .fresh;
129176 }
130 self.artifact.installed_path = full_dest_path;
177
131178 step.result_cached = all_cached;
132179}
lib/std/Build/Step/ObjCopy.zig+2-1
......@@ -60,7 +60,8 @@ pub fn create(
6060 return self;
6161}
6262
63pub const getOutputSource = getOutput; // DEPRECATED, use getOutput
63/// deprecated: use getOutput
64pub const getOutputSource = getOutput;
6465
6566pub fn getOutput(self: *const ObjCopy) std.Build.LazyPath {
6667 return .{ .generated = &self.output_file };
lib/std/Build/Step/Options.zig+10-13
......@@ -13,7 +13,7 @@ step: Step,
1313generated_file: GeneratedFile,
1414
1515contents: std.ArrayList(u8),
16args: std.ArrayList(OptionLazyPathArg),
16args: std.ArrayList(Arg),
1717
1818pub fn create(owner: *std.Build) *Options {
1919 const self = owner.allocator.create(Options) catch @panic("OOM");
......@@ -26,7 +26,7 @@ pub fn create(owner: *std.Build) *Options {
2626 }),
2727 .generated_file = undefined,
2828 .contents = std.ArrayList(u8).init(owner.allocator),
29 .args = std.ArrayList(OptionLazyPathArg).init(owner.allocator),
29 .args = std.ArrayList(Arg).init(owner.allocator),
3030 };
3131 self.generated_file = .{ .step = &self.step };
3232
......@@ -166,7 +166,8 @@ fn printLiteral(out: anytype, val: anytype, indent: u8) !void {
166166 }
167167}
168168
169pub const addOptionFileSource = addOptionPath; // DEPRECATED, use addPathOption
169/// deprecated: use `addOptionPath`
170pub const addOptionFileSource = addOptionPath;
170171
171172/// The value is the path in the cache dir.
172173/// Adds a dependency automatically.
......@@ -182,14 +183,9 @@ pub fn addOptionPath(
182183 path.addStepDependencies(&self.step);
183184}
184185
185/// The value is the path in the cache dir.
186/// Adds a dependency automatically.
186/// Deprecated: use `addOptionPath(options, name, artifact.getEmittedBin())` instead.
187187pub fn addOptionArtifact(self: *Options, name: []const u8, artifact: *Step.Compile) void {
188 self.args.append(.{
189 .name = self.step.owner.dupe(name),
190 .artifact = artifact.getEmittedBin,
191 }) catch @panic("OOM");
192 self.step.dependOn(&artifact.step);
188 return addOptionPath(self, name, artifact.getEmittedBin());
193189}
194190
195191pub fn createModule(self: *Options) *std.Build.Module {
......@@ -199,7 +195,8 @@ pub fn createModule(self: *Options) *std.Build.Module {
199195 });
200196}
201197
202pub const getSource = getOutput; // DEPRECATED, use getOutput
198/// deprecated: use `getOutput`
199pub const getSource = getOutput;
203200
204201pub fn getOutput(self: *Options) LazyPath {
205202 return .{ .generated = &self.generated_file };
......@@ -226,7 +223,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
226223 var hash = b.cache.hash;
227224 // Random bytes to make unique. Refresh this with new random bytes when
228225 // implementation is modified in a non-backwards-compatible way.
229 hash.add(@as(u32, 0x38845ef8));
226 hash.add(@as(u32, 0xad95e922));
230227 hash.addBytes(self.contents.items);
231228 const sub_path = "c" ++ fs.path.sep_str ++ hash.final() ++ fs.path.sep_str ++ basename;
232229
......@@ -291,7 +288,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
291288 }
292289}
293290
294const OptionLazyPathArg = struct {
291const Arg = struct {
295292 name: []const u8,
296293 path: LazyPath,
297294};
lib/std/Build/Step/Run.zig+13-12
......@@ -164,12 +164,9 @@ pub fn enableTestRunnerMode(self: *Run) void {
164164}
165165
166166pub fn addArtifactArg(self: *Run, artifact: *Step.Compile) void {
167 // enforce creation of the binary file by invoking getEmittedBin
168167 const bin_file = artifact.getEmittedBin();
169168 bin_file.addStepDependencies(&self.step);
170
171169 self.argv.append(Arg{ .artifact = artifact }) catch @panic("OOM");
172 self.step.dependOn(&artifact.step);
173170}
174171
175172/// This provides file path as a command line argument to the command being
......@@ -201,32 +198,36 @@ pub fn addPrefixedOutputFileArg(
201198 return .{ .generated = &output.generated_file };
202199}
203200
204pub const addFileSourceArg = addFileArg; // DEPRECATED, use addFileArg
201/// deprecated: use `addFileArg`
202pub const addFileSourceArg = addFileArg;
205203
206pub fn addFileArg(self: *Run, file_source: std.Build.LazyPath) void {
207 self.addPrefixedFileArg("", file_source);
204pub fn addFileArg(self: *Run, lp: std.Build.LazyPath) void {
205 self.addPrefixedFileArg("", lp);
208206}
209207
210pub const addPrefixedFileSourceArg = addPrefixedFileArg; // DEPRECATED, use addPrefixedFileArg
208// deprecated: use `addPrefixedFileArg`
209pub const addPrefixedFileSourceArg = addPrefixedFileArg;
211210
212pub fn addPrefixedFileArg(self: *Run, prefix: []const u8, file_source: std.Build.LazyPath) void {
211pub fn addPrefixedFileArg(self: *Run, prefix: []const u8, lp: std.Build.LazyPath) void {
213212 const b = self.step.owner;
214213
215214 const prefixed_file_source: PrefixedLazyPath = .{
216215 .prefix = b.dupe(prefix),
217 .file_source = file_source.dupe(b),
216 .file_source = lp.dupe(b),
218217 };
219218 self.argv.append(.{ .file_source = prefixed_file_source }) catch @panic("OOM");
220 file_source.addStepDependencies(&self.step);
219 lp.addStepDependencies(&self.step);
221220}
222221
223pub const addDirectorySourceArg = addDirectoryArg; // DEPRECATED, use addDirectoryArg
222/// deprecated: use `addDirectoryArg`
223pub const addDirectorySourceArg = addDirectoryArg;
224224
225225pub fn addDirectoryArg(self: *Run, directory_source: std.Build.LazyPath) void {
226226 self.addPrefixedDirectoryArg("", directory_source);
227227}
228228
229pub const addPrefixedDirectorySourceArg = addPrefixedDirectoryArg; // DEPRECATED, use addPrefixedDirectoryArg
229// deprecated: use `addPrefixedDirectoryArg`
230pub const addPrefixedDirectorySourceArg = addPrefixedDirectoryArg;
230231
231232pub fn addPrefixedDirectoryArg(self: *Run, prefix: []const u8, directory_source: std.Build.LazyPath) void {
232233 const b = self.step.owner;
lib/std/Build/Step/WriteFile.zig+2-1
......@@ -28,7 +28,8 @@ pub const File = struct {
2828 sub_path: []const u8,
2929 contents: Contents,
3030
31 pub const getFileSource = getPath; // DEPRECATED, use getPath
31 /// deprecated: use `getPath`
32 pub const getFileSource = getPath;
3233
3334 pub fn getPath(self: *File) std.Build.LazyPath {
3435 return .{ .generated = &self.generated_file };
lib/std/Build/util.zig deleted-53
......@@ -1,53 +0,0 @@
1const std = @import("std");
2const fs = std.fs;
3
4const Build = std.Build;
5const Step = std.Build.Step;
6
7/// In this function the stderr mutex has already been locked.
8pub 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 {
44 const test_step = b.step("test", "Test");
55 b.default_step = test_step;
66
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| {
88 const exe = b.addExecutable(.{
99 .name = t,
1010 .root_source_file = .{ .path = "main.c" },
......@@ -13,7 +13,8 @@ pub fn build(b: *std.Build) void {
1313 ) catch unreachable,
1414 });
1515 exe.linkLibC();
16 exe.forceBuild();
16 // TODO: actually test the output
17 _ = exe.getEmittedBin();
1718 test_step.dependOn(&exe.step);
1819 }
1920}
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
4141 });
4242 exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
4343 exe.linkSystemLibrary("a");
44 exe.addLibraryPath(dylib.getEmitDirectory());
45 exe.addRPath(dylib.getEmitDirectory());
44 exe.addLibraryPath(dylib.getEmittedBinDirectory());
45 exe.addRPath(dylib.getEmittedBinDirectory());
4646 exe.linkLibC();
4747
4848 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
2323 });
2424 dylib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} });
2525 dylib.linkLibC();
26 dylib.forceEmit(.bin); // enforce library creation, we import it below
2726
2827 // -dead_strip_dylibs
2928 // -needed-la
......@@ -35,8 +34,8 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
3534 exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
3635 exe.linkLibC();
3736 exe.linkSystemLibraryNeeded("a");
38 exe.addLibraryPath(dylib.getEmitDirectory());
39 exe.addRPath(dylib.getEmitDirectory());
37 exe.addLibraryPath(dylib.getEmittedBinDirectory());
38 exe.addRPath(dylib.getEmittedBinDirectory());
4039 exe.dead_strip_dylibs = true;
4140
4241 const check = exe.checkObject();
test/link/macho/search_strategy/build.zig+3-11
......@@ -57,10 +57,6 @@ fn createScenario(
5757 });
5858 static.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} });
5959 static.linkLibC();
60 static.override_dest_dir = std.Build.InstallDir{
61 .custom = "static",
62 };
63 static.forceEmit(.bin);
6460
6561 const dylib = b.addSharedLibrary(.{
6662 .name = name,
......@@ -70,10 +66,6 @@ fn createScenario(
7066 });
7167 dylib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} });
7268 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
7769
7870 const exe = b.addExecutable(.{
7971 .name = name,
......@@ -83,8 +75,8 @@ fn createScenario(
8375 exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &.{} });
8476 exe.linkSystemLibraryName(name);
8577 exe.linkLibC();
86 exe.addLibraryPath(static.getEmitDirectory());
87 exe.addLibraryPath(dylib.getEmitDirectory());
88 exe.addRPath(dylib.getEmitDirectory());
78 exe.addLibraryPath(static.getEmittedBinDirectory());
79 exe.addLibraryPath(dylib.getEmittedBinDirectory());
80 exe.addRPath(dylib.getEmittedBinDirectory());
8981 return exe;
9082}
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
2525 });
2626 lib.addCSourceFile(.{ .file = .{ .path = "a.c" }, .flags = &.{} });
2727 lib.linkLibC();
28 lib.forceEmit(.bin); // will be referenced by the tbd file
2928
3029 const tbd_file = b.addWriteFile("liba.tbd",
3130 \\--- !tapi-tbd-v3
......@@ -47,7 +46,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
4746 exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
4847 exe.linkSystemLibrary("a");
4948 exe.addLibraryPath(tbd_file.getDirectory());
50 exe.addRPath(lib.getEmitDirectory());
49 exe.addRPath(lib.getEmittedBinDirectory());
5150 exe.linkLibC();
5251
5352 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
3333 exe.addCSourceFile(.{ .file = .{ .path = "main.c" }, .flags = &[0][]const u8{} });
3434 exe.linkLibC();
3535 exe.linkSystemLibraryWeak("a");
36 exe.addLibraryPath(dylib.getEmitDirectory());
37 exe.addRPath(dylib.getEmitDirectory());
36 exe.addLibraryPath(dylib.getEmittedBinDirectory());
37 exe.addRPath(dylib.getEmittedBinDirectory());
3838
3939 const check = exe.checkObject();
4040 check.checkStart();
test/src/Cases.zig-6
......@@ -551,12 +551,6 @@ pub fn lowerToBuildSteps(
551551 }),
552552 };
553553
554 if (case.emit_bin) {
555 artifact.forceEmit(.bin);
556 } else {
557 artifact.forceBuild();
558 }
559
560554 if (case.link_libc) artifact.linkLibC();
561555
562556 switch (case.backend) {
test/standalone.zig+8-8
......@@ -141,15 +141,15 @@ pub const build_cases = [_]BuildCase{
141141 .import = @import("standalone/install_raw_hex/build.zig"),
142142 },
143143 // TODO take away EmitOption.emit_to option and make it give a FileSource
144 // .{
145 // .build_root = "test/standalone/emit_asm_and_bin",
146 // .import = @import("standalone/emit_asm_and_bin/build.zig"),
147 // },
144 //.{
145 // .build_root = "test/standalone/emit_asm_and_bin",
146 // .import = @import("standalone/emit_asm_and_bin/build.zig"),
147 //},
148148 // TODO take away EmitOption.emit_to option and make it give a FileSource
149 // .{
150 // .build_root = "test/standalone/issue_12588",
151 // .import = @import("standalone/issue_12588/build.zig"),
152 // },
149 //.{
150 // .build_root = "test/standalone/issue_12588",
151 // .import = @import("standalone/issue_12588/build.zig"),
152 //},
153153 .{
154154 .build_root = "test/standalone/child_process",
155155 .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 {
1616 .target = target,
1717 });
1818 exe.linkLibC();
19 exe.addCSourceFile("main.c", &.{});
19 exe.addCSourceFile(.{
20 .file = .{ .path = "main.c" },
21 .flags = &.{},
22 });
2023 exe.link_gc_sections = false;
2124 exe.bundle_compiler_rt = true;
2225
test/standalone/embed_generated_file/build.zig+2-1
......@@ -22,7 +22,8 @@ pub fn build(b: *std.Build) void {
2222 .source_file = bootloader.getEmittedBin(),
2323 });
2424
25 exe.forceBuild();
25 // TODO: actually check the output
26 _ = exe.getEmittedBin();
2627
2728 test_step.dependOn(&exe.step);
2829}
test/standalone/emit_asm_and_bin/build.zig+3-2
......@@ -8,8 +8,9 @@ pub fn build(b: *std.Build) void {
88 .root_source_file = .{ .path = "main.zig" },
99 .optimize = b.standardOptimizeOption(.{}),
1010 });
11 main.forceEmit(.bin);
12 main.forceEmit(.@"asm");
11 // TODO: actually check these two artifacts for correctness
12 _ = main.getEmittedBin();
13 _ = main.getEmittedAsm();
1314
1415 test_step.dependOn(&b.addRunArtifact(main).step);
1516}
test/standalone/issue_339/build.zig+2-1
......@@ -14,7 +14,8 @@ pub fn build(b: *std.Build) void {
1414 .optimize = optimize,
1515 });
1616
17 obj.forceBuild();
17 // TODO: actually check the output
18 _ = obj.getEmittedBin();
1819
1920 test_step.dependOn(&obj.step);
2021}
test/standalone/issue_5825/build.zig+2-1
......@@ -27,7 +27,8 @@ pub fn build(b: *std.Build) void {
2727 exe.linkSystemLibrary("ntdll");
2828 exe.addObject(obj);
2929
30 exe.forceBuild();
30 // TODO: actually check the output
31 _ = exe.getEmittedBin();
3132
3233 test_step.dependOn(&exe.step);
3334}
test/standalone/issue_794/build.zig+2-1
......@@ -9,7 +9,8 @@ pub fn build(b: *std.Build) void {
99 });
1010 test_artifact.addIncludePath(.{ .path = "a_directory" });
1111
12 test_artifact.forceBuild();
12 // TODO: actually check the output
13 _ = test_artifact.getEmittedBin();
1314
1415 test_step.dependOn(&test_artifact.step);
1516}
test/standalone/main_pkg_path/build.zig+1-1
......@@ -6,8 +6,8 @@ pub fn build(b: *std.Build) void {
66
77 const test_exe = b.addTest(.{
88 .root_source_file = .{ .path = "a/test.zig" },
9 .main_pkg_path = .{ .path = "." },
910 });
10 test_exe.setMainPkgPath(.{ .path = "." });
1111
1212 test_step.dependOn(&b.addRunArtifact(test_exe).step);
1313}
test/standalone/strip_empty_loop/build.zig+2-1
......@@ -15,7 +15,8 @@ pub fn build(b: *std.Build) void {
1515 });
1616 main.strip = true;
1717
18 main.forceBuild();
18 // TODO: actually check the output
19 _ = main.getEmittedBin();
1920
2021 test_step.dependOn(&main.step);
2122}
test/tests.zig+3-3
......@@ -588,7 +588,7 @@ pub fn addStandaloneTests(
588588 });
589589 if (case.link_libc) exe.linkLibC();
590590
591 exe.forceBuild();
591 _ = exe.getEmittedBin();
592592
593593 step.dependOn(&exe.step);
594594 }
......@@ -1008,6 +1008,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
10081008 .single_threaded = test_target.single_threaded,
10091009 .use_llvm = test_target.use_llvm,
10101010 .use_lld = test_target.use_lld,
1011 .zig_lib_dir = .{ .path = "lib" },
10111012 });
10121013 const single_threaded_suffix = if (test_target.single_threaded == true) "-single" else "";
10131014 const backend_suffix = if (test_target.use_llvm == true)
......@@ -1019,7 +1020,6 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
10191020 else
10201021 "";
10211022
1022 these_tests.overrideZigLibDir(.{ .path = "lib" });
10231023 these_tests.addIncludePath(.{ .path = "test" });
10241024
10251025 const qualified_name = b.fmt("{s}-{s}-{s}{s}{s}{s}", .{
......@@ -1039,8 +1039,8 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
10391039 .name = qualified_name,
10401040 .link_libc = test_target.link_libc,
10411041 .target = altered_target,
1042 .zig_lib_dir = .{ .path = "lib" },
10421043 });
1043 compile_c.overrideZigLibDir(.{ .path = "lib" });
10441044 compile_c.addCSourceFile(.{
10451045 .file = these_tests.getEmittedBin(),
10461046 .flags = &.{