From d2ad3f5074877475c8f0ec0fbbb323a05fe8cf78 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 10 Apr 2023 16:36:21 -0700 Subject: [PATCH 1/5] std.Build.CompileStep: remove redundant dest_builder field The destination *Build object is already known to be step.owner, while the source object is artifact.step.owner. --- lib/std/Build/CompileStep.zig | 2 +- lib/std/Build/InstallArtifactStep.zig | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/std/Build/CompileStep.zig b/lib/std/Build/CompileStep.zig index 0ee6e32826..d1beff69fc 100644 --- a/lib/std/Build/CompileStep.zig +++ b/lib/std/Build/CompileStep.zig @@ -533,7 +533,7 @@ pub fn installLibraryHeaders(cs: *CompileStep, l: *CompileStep) void { const T = id.Type(); const ptr = b.allocator.create(T) catch @panic("OOM"); ptr.* = step.cast(T).?.*; - ptr.dest_builder = b; + ptr.step.owner = b; break :blk &ptr.step; }, else => unreachable, diff --git a/lib/std/Build/InstallArtifactStep.zig b/lib/std/Build/InstallArtifactStep.zig index 445f1e8ea8..b3ebcad89e 100644 --- a/lib/std/Build/InstallArtifactStep.zig +++ b/lib/std/Build/InstallArtifactStep.zig @@ -8,7 +8,6 @@ const fs = std.fs; pub const base_id = .install_artifact; step: Step, -dest_builder: *std.Build, artifact: *CompileStep, dest_dir: InstallDir, pdb_dir: ?InstallDir, @@ -28,7 +27,6 @@ pub fn create(owner: *std.Build, artifact: *CompileStep) *InstallArtifactStep { .owner = owner, .makeFn = make, }), - .dest_builder = owner, .artifact = artifact, .dest_dir = artifact.override_dest_dir orelse switch (artifact.kind) { .obj => @panic("Cannot install a .obj build artifact."), @@ -71,9 +69,9 @@ pub fn create(owner: *std.Build, artifact: *CompileStep) *InstallArtifactStep { fn make(step: *Step, prog_node: *std.Progress.Node) !void { _ = prog_node; - const src_builder = step.owner; const self = @fieldParentPtr(InstallArtifactStep, "step", step); - const dest_builder = self.dest_builder; + const src_builder = self.artifact.step.owner; + const dest_builder = step.owner; const dest_sub_path = if (self.dest_sub_path) |sub_path| sub_path else self.artifact.out_filename; const full_dest_path = dest_builder.getInstallPath(self.dest_dir, dest_sub_path); From 38698f4f6aabb20639642afa58b17f31a43e162b Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 10 Apr 2023 16:38:24 -0700 Subject: [PATCH 2/5] std.Build.CompileStep: delete install_step field This was used to ensure that an artifact would only be installed once, but this is not only unnecessary, but actively harmful, in the face of dependencies. see #15079 --- lib/std/Build/CompileStep.zig | 2 -- lib/std/Build/InstallArtifactStep.zig | 3 --- 2 files changed, 5 deletions(-) diff --git a/lib/std/Build/CompileStep.zig b/lib/std/Build/CompileStep.zig index d1beff69fc..bdb0ed8aae 100644 --- a/lib/std/Build/CompileStep.zig +++ b/lib/std/Build/CompileStep.zig @@ -111,7 +111,6 @@ vcpkg_bin_path: ?[]const u8 = null, /// This may be set in order to override the default install directory override_dest_dir: ?InstallDir, installed_path: ?[]const u8, -install_step: ?*InstallArtifactStep, /// Base address for an executable image. image_base: ?u64 = null, @@ -390,7 +389,6 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { .output_dir = null, .override_dest_dir = null, .installed_path = null, - .install_step = null, .force_undefined_symbols = StringHashMap(void).init(owner.allocator), .output_path_source = GeneratedFile{ .step = &self.step }, diff --git a/lib/std/Build/InstallArtifactStep.zig b/lib/std/Build/InstallArtifactStep.zig index b3ebcad89e..50cf6ff323 100644 --- a/lib/std/Build/InstallArtifactStep.zig +++ b/lib/std/Build/InstallArtifactStep.zig @@ -17,8 +17,6 @@ h_dir: ?InstallDir, dest_sub_path: ?[]const u8, pub fn create(owner: *std.Build, artifact: *CompileStep) *InstallArtifactStep { - if (artifact.install_step) |s| return s; - const self = owner.allocator.create(InstallArtifactStep) catch @panic("OOM"); self.* = InstallArtifactStep{ .step = Step.init(.{ @@ -44,7 +42,6 @@ pub fn create(owner: *std.Build, artifact: *CompileStep) *InstallArtifactStep { .dest_sub_path = null, }; self.step.dependOn(&artifact.step); - artifact.install_step = self; owner.pushInstalledFile(self.dest_dir, artifact.out_filename); if (self.artifact.isDynamicLibrary()) { From 60eabc0eca5f678d0c6569a9565b1d6141459518 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 10 Apr 2023 17:05:09 -0700 Subject: [PATCH 3/5] std.Build.CompileStep: remove run() and install() These functions are problematic in light of dependencies because they run and install, respectively, for the *owner* package rather than for the *user* package. By removing these functions, the build script is forced to provide the *Build object to associate the new step with, making everything less surprising. Unfortunately, this is a widely breaking change. see #15079 --- build.zig | 2 +- lib/std/Build/CompileStep.zig | 16 ++++++---------- test/link/bss/build.zig | 2 +- test/link/common_symbols/build.zig | 2 +- test/link/common_symbols_alignment/build.zig | 2 +- test/link/interdependent_static_c_libs/build.zig | 2 +- test/link/macho/bugs/13056/build.zig | 2 +- test/link/macho/dead_strip_dylibs/build.zig | 2 +- test/link/macho/entry_in_archive/build.zig | 2 +- test/link/macho/headerpad/build.zig | 8 ++++---- test/link/macho/needed_framework/build.zig | 2 +- test/link/macho/objcpp/build.zig | 2 +- test/link/macho/tls/build.zig | 2 +- test/link/macho/weak_framework/build.zig | 2 +- test/link/macho/weak_library/build.zig | 2 +- test/link/wasm/producers/build.zig | 2 +- test/link/wasm/segments/build.zig | 2 +- test/link/wasm/stack_pointer/build.zig | 2 +- test/link/wasm/type/build.zig | 2 +- test/src/CompareOutput.zig | 6 +++--- test/src/run_translated_c.zig | 2 +- test/standalone/dep_diamond/build.zig | 3 +-- test/standalone/dep_mutually_recursive/build.zig | 3 +-- test/standalone/dep_recursive/build.zig | 3 +-- test/standalone/dep_shared_builtin/build.zig | 3 +-- test/standalone/dep_triangle/build.zig | 3 +-- test/standalone/emit_asm_and_bin/build.zig | 2 +- test/standalone/global_linkage/build.zig | 2 +- test/standalone/issue_11595/build.zig | 2 +- test/standalone/issue_13970/build.zig | 6 +++--- test/standalone/issue_8550/build.zig | 2 +- test/standalone/main_pkg_path/build.zig | 2 +- test/standalone/mix_o_files/build.zig | 3 +-- test/standalone/options/build.zig | 2 +- test/standalone/pie/build.zig | 2 +- test/standalone/pkg_import/build.zig | 3 +-- test/standalone/shared_library/build.zig | 3 +-- test/standalone/static_c_lib/build.zig | 2 +- .../test_runner_module_imports/build.zig | 2 +- test/standalone/test_runner_path/build.zig | 3 +-- test/standalone/use_alias/build.zig | 2 +- test/tests.zig | 7 ++++--- 42 files changed, 57 insertions(+), 69 deletions(-) diff --git a/build.zig b/build.zig index 04f1eed6b5..1a82a1d105 100644 --- a/build.zig +++ b/build.zig @@ -181,7 +181,7 @@ pub fn build(b: *std.Build) !void { exe.sanitize_thread = sanitize_thread; exe.build_id = b.option(bool, "build-id", "Include a build id note") orelse false; exe.entitlements = entitlements; - exe.install(); + b.installArtifact(exe); const compile_step = b.step("compile", "Build the self-hosted compiler"); compile_step.dependOn(&exe.step); diff --git a/lib/std/Build/CompileStep.zig b/lib/std/Build/CompileStep.zig index bdb0ed8aae..29cdaa523b 100644 --- a/lib/std/Build/CompileStep.zig +++ b/lib/std/Build/CompileStep.zig @@ -463,11 +463,6 @@ pub fn setOutputDir(self: *CompileStep, dir: []const u8) void { self.output_dir = b.dupePath(dir); } -pub fn install(self: *CompileStep) void { - const b = self.step.owner; - b.installArtifact(self); -} - pub fn installHeader(cs: *CompileStep, src_path: []const u8, dest_rel_path: []const u8) void { const b = cs.step.owner; const install_file = b.addInstallHeaderFile(src_path, dest_rel_path); @@ -555,12 +550,13 @@ pub fn addObjCopy(cs: *CompileStep, options: ObjCopyStep.Options) *ObjCopyStep { return b.addObjCopy(cs.getOutputSource(), copy); } -/// Deprecated: use `std.Build.addRunArtifact` -/// This function will run in the context of the package that created the executable, +/// This function would run in the context of the package that created the executable, /// which is undesirable when running an executable provided by a dependency package. -pub fn run(cs: *CompileStep) *RunStep { - return cs.step.owner.addRunArtifact(cs); -} +pub const run = @compileError("deprecated; use std.Build.addRunArtifact"); + +/// This function would install in the context of the package that created the artifact, +/// which is undesirable when installing an artifact provided by a dependency package. +pub const install = @compileError("deprecated; use std.Build.installArtifact"); pub fn checkObject(self: *CompileStep) *CheckObjectStep { return CheckObjectStep.create(self.step.owner, self.getOutputSource(), self.target_info.target.ofmt); diff --git a/test/link/bss/build.zig b/test/link/bss/build.zig index 86600b58f5..3c7964fae1 100644 --- a/test/link/bss/build.zig +++ b/test/link/bss/build.zig @@ -10,7 +10,7 @@ pub fn build(b: *std.Build) void { .optimize = .Debug, }); - const run = exe.run(); + const run = b.addRunArtifact(exe); run.expectStdOutEqual("0, 1, 0\n"); test_step.dependOn(&run.step); diff --git a/test/link/common_symbols/build.zig b/test/link/common_symbols/build.zig index a8c276d1f3..a2104e1ac2 100644 --- a/test/link/common_symbols/build.zig +++ b/test/link/common_symbols/build.zig @@ -24,5 +24,5 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize }); test_exe.linkLibrary(lib_a); - test_step.dependOn(&test_exe.run().step); + test_step.dependOn(&b.addRunArtifact(test_exe).step); } diff --git a/test/link/common_symbols_alignment/build.zig b/test/link/common_symbols_alignment/build.zig index 83548f2d8a..4cb253dc05 100644 --- a/test/link/common_symbols_alignment/build.zig +++ b/test/link/common_symbols_alignment/build.zig @@ -24,5 +24,5 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize }); test_exe.linkLibrary(lib_a); - test_step.dependOn(&test_exe.run().step); + test_step.dependOn(&b.addRunArtifact(test_exe).step); } diff --git a/test/link/interdependent_static_c_libs/build.zig b/test/link/interdependent_static_c_libs/build.zig index 0d06410a79..2eb8fa27b4 100644 --- a/test/link/interdependent_static_c_libs/build.zig +++ b/test/link/interdependent_static_c_libs/build.zig @@ -35,5 +35,5 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize test_exe.linkLibrary(lib_b); test_exe.addIncludePath("."); - test_step.dependOn(&test_exe.run().step); + test_step.dependOn(&b.addRunArtifact(test_exe).step); } diff --git a/test/link/macho/bugs/13056/build.zig b/test/link/macho/bugs/13056/build.zig index bcee22504f..1ac50a61c6 100644 --- a/test/link/macho/bugs/13056/build.zig +++ b/test/link/macho/bugs/13056/build.zig @@ -31,7 +31,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize }); exe.addObjectFile(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/lib/libc++.tbd" }) catch unreachable); - const run_cmd = exe.run(); + const run_cmd = b.addRunArtifact(exe); run_cmd.expectStdErrEqual("x: 5\n"); test_step.dependOn(&run_cmd.step); diff --git a/test/link/macho/dead_strip_dylibs/build.zig b/test/link/macho/dead_strip_dylibs/build.zig index b9b97949c1..47e53f853e 100644 --- a/test/link/macho/dead_strip_dylibs/build.zig +++ b/test/link/macho/dead_strip_dylibs/build.zig @@ -27,7 +27,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize test_step.dependOn(&check.step); - const run_cmd = exe.run(); + const run_cmd = b.addRunArtifact(exe); test_step.dependOn(&run_cmd.step); } diff --git a/test/link/macho/entry_in_archive/build.zig b/test/link/macho/entry_in_archive/build.zig index 5d244a93fc..f4b04bd162 100644 --- a/test/link/macho/entry_in_archive/build.zig +++ b/test/link/macho/entry_in_archive/build.zig @@ -29,7 +29,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize exe.linkLibrary(lib); exe.linkLibC(); - const run = exe.run(); + const run = b.addRunArtifact(exe); run.skip_foreign_checks = true; run.expectExitCode(0); test_step.dependOn(&run.step); diff --git a/test/link/macho/headerpad/build.zig b/test/link/macho/headerpad/build.zig index 0c9275b8d8..22cfcc90ec 100644 --- a/test/link/macho/headerpad/build.zig +++ b/test/link/macho/headerpad/build.zig @@ -36,7 +36,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize test_step.dependOn(&check.step); - const run = exe.run(); + const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); } @@ -52,7 +52,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize test_step.dependOn(&check.step); - const run = exe.run(); + const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); } @@ -69,7 +69,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize test_step.dependOn(&check.step); - const run = exe.run(); + const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); } @@ -95,7 +95,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize test_step.dependOn(&check.step); - const run = exe.run(); + const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); } } diff --git a/test/link/macho/needed_framework/build.zig b/test/link/macho/needed_framework/build.zig index 3de96efbc7..fc80a44f73 100644 --- a/test/link/macho/needed_framework/build.zig +++ b/test/link/macho/needed_framework/build.zig @@ -30,6 +30,6 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize check.checkNext("name {*}Cocoa"); test_step.dependOn(&check.step); - const run_cmd = exe.run(); + const run_cmd = b.addRunArtifact(exe); test_step.dependOn(&run_cmd.step); } diff --git a/test/link/macho/objcpp/build.zig b/test/link/macho/objcpp/build.zig index 06876247a9..aebf0e17fd 100644 --- a/test/link/macho/objcpp/build.zig +++ b/test/link/macho/objcpp/build.zig @@ -27,7 +27,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize // populate paths to the sysroot here. exe.linkFramework("Foundation"); - const run_cmd = exe.run(); + const run_cmd = b.addRunArtifact(exe); run_cmd.expectStdOutEqual("Hello from C++ and Zig"); test_step.dependOn(&run_cmd.step); diff --git a/test/link/macho/tls/build.zig b/test/link/macho/tls/build.zig index 5981fea194..f155f514f8 100644 --- a/test/link/macho/tls/build.zig +++ b/test/link/macho/tls/build.zig @@ -32,7 +32,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize test_exe.linkLibrary(lib); test_exe.linkLibC(); - const run = test_exe.run(); + const run = b.addRunArtifact(test_exe); run.skip_foreign_checks = true; test_step.dependOn(&run.step); diff --git a/test/link/macho/weak_framework/build.zig b/test/link/macho/weak_framework/build.zig index 7cc08f5b9d..5dfd421243 100644 --- a/test/link/macho/weak_framework/build.zig +++ b/test/link/macho/weak_framework/build.zig @@ -27,6 +27,6 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize check.checkNext("name {*}Cocoa"); test_step.dependOn(&check.step); - const run_cmd = exe.run(); + const run_cmd = b.addRunArtifact(exe); test_step.dependOn(&run_cmd.step); } diff --git a/test/link/macho/weak_library/build.zig b/test/link/macho/weak_library/build.zig index b12ec087f5..88d72ad487 100644 --- a/test/link/macho/weak_library/build.zig +++ b/test/link/macho/weak_library/build.zig @@ -23,7 +23,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize }); dylib.addCSourceFile("a.c", &.{}); dylib.linkLibC(); - dylib.install(); + b.installArtifact(dylib); const exe = b.addExecutable(.{ .name = "test", diff --git a/test/link/wasm/producers/build.zig b/test/link/wasm/producers/build.zig index 7b7cefd7e0..439a66cfa5 100644 --- a/test/link/wasm/producers/build.zig +++ b/test/link/wasm/producers/build.zig @@ -23,7 +23,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize lib.use_llvm = false; lib.use_lld = false; lib.strip = false; - lib.install(); + b.installArtifact(lib); const version_fmt = "version " ++ builtin.zig_version_string; diff --git a/test/link/wasm/segments/build.zig b/test/link/wasm/segments/build.zig index 281d8ae32b..59fab9bb84 100644 --- a/test/link/wasm/segments/build.zig +++ b/test/link/wasm/segments/build.zig @@ -22,7 +22,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize lib.use_llvm = false; lib.use_lld = false; lib.strip = false; - lib.install(); + b.installArtifact(lib); const check_lib = lib.checkObject(); check_lib.checkStart("Section data"); diff --git a/test/link/wasm/stack_pointer/build.zig b/test/link/wasm/stack_pointer/build.zig index 794b7d27fb..bf643c1e3a 100644 --- a/test/link/wasm/stack_pointer/build.zig +++ b/test/link/wasm/stack_pointer/build.zig @@ -23,7 +23,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize lib.use_lld = false; lib.strip = false; lib.stack_size = std.wasm.page_size * 2; // set an explicit stack size - lib.install(); + b.installArtifact(lib); const check_lib = lib.checkObject(); diff --git a/test/link/wasm/type/build.zig b/test/link/wasm/type/build.zig index 4a8395645f..4038a3c4b1 100644 --- a/test/link/wasm/type/build.zig +++ b/test/link/wasm/type/build.zig @@ -22,7 +22,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize lib.use_llvm = false; lib.use_lld = false; lib.strip = false; - lib.install(); + b.installArtifact(lib); const check_lib = lib.checkObject(); check_lib.checkStart("Section type"); diff --git a/test/src/CompareOutput.zig b/test/src/CompareOutput.zig index 854bd11f9c..fb89082def 100644 --- a/test/src/CompareOutput.zig +++ b/test/src/CompareOutput.zig @@ -101,7 +101,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { }); exe.addAssemblyFileSource(write_src.getFileSource(case.sources.items[0].filename).?); - const run = exe.run(); + const run = b.addRunArtifact(exe); run.setName(annotated_case_name); run.addArgs(case.cli_args); run.expectStdOutEqual(case.expected_output); @@ -128,7 +128,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { exe.linkSystemLibrary("c"); } - const run = exe.run(); + const run = b.addRunArtifact(exe); run.setName(annotated_case_name); run.addArgs(case.cli_args); run.expectStdOutEqual(case.expected_output); @@ -155,7 +155,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void { exe.linkSystemLibrary("c"); } - const run = exe.run(); + const run = b.addRunArtifact(exe); run.setName(annotated_case_name); run.addArgs(case.cli_args); run.expectExitCode(126); diff --git a/test/src/run_translated_c.zig b/test/src/run_translated_c.zig index 2103172ed6..946e56f512 100644 --- a/test/src/run_translated_c.zig +++ b/test/src/run_translated_c.zig @@ -94,7 +94,7 @@ pub const RunTranslatedCContext = struct { const exe = translate_c.addExecutable(.{}); exe.step.name = b.fmt("{s} build-exe", .{annotated_case_name}); exe.linkLibC(); - const run = exe.run(); + const run = b.addRunArtifact(exe); run.step.name = b.fmt("{s} run", .{annotated_case_name}); if (!case.allow_warnings) { run.expectStdErrEqual(""); diff --git a/test/standalone/dep_diamond/build.zig b/test/standalone/dep_diamond/build.zig index 12eda4ec5d..6c6d9b6d1a 100644 --- a/test/standalone/dep_diamond/build.zig +++ b/test/standalone/dep_diamond/build.zig @@ -24,7 +24,6 @@ pub fn build(b: *std.Build) void { .dependencies = &.{.{ .name = "shared", .module = shared }}, }); - const run = exe.run(); - + const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); } diff --git a/test/standalone/dep_mutually_recursive/build.zig b/test/standalone/dep_mutually_recursive/build.zig index 1a6bff8501..e70e775401 100644 --- a/test/standalone/dep_mutually_recursive/build.zig +++ b/test/standalone/dep_mutually_recursive/build.zig @@ -22,7 +22,6 @@ pub fn build(b: *std.Build) void { }); exe.addModule("foo", foo); - const run = exe.run(); - + const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); } diff --git a/test/standalone/dep_recursive/build.zig b/test/standalone/dep_recursive/build.zig index 35b9f3cc47..2e2cf4ea4d 100644 --- a/test/standalone/dep_recursive/build.zig +++ b/test/standalone/dep_recursive/build.zig @@ -18,7 +18,6 @@ pub fn build(b: *std.Build) void { }); exe.addModule("foo", foo); - const run = exe.run(); - + const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); } diff --git a/test/standalone/dep_shared_builtin/build.zig b/test/standalone/dep_shared_builtin/build.zig index 776794f95e..175118d331 100644 --- a/test/standalone/dep_shared_builtin/build.zig +++ b/test/standalone/dep_shared_builtin/build.zig @@ -15,7 +15,6 @@ pub fn build(b: *std.Build) void { .source_file = .{ .path = "foo.zig" }, }); - const run = exe.run(); - + const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); } diff --git a/test/standalone/dep_triangle/build.zig b/test/standalone/dep_triangle/build.zig index 14163df84c..63eed997ce 100644 --- a/test/standalone/dep_triangle/build.zig +++ b/test/standalone/dep_triangle/build.zig @@ -21,7 +21,6 @@ pub fn build(b: *std.Build) void { }); exe.addModule("shared", shared); - const run = exe.run(); - + const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); } diff --git a/test/standalone/emit_asm_and_bin/build.zig b/test/standalone/emit_asm_and_bin/build.zig index 594bf6552e..1a608b40a9 100644 --- a/test/standalone/emit_asm_and_bin/build.zig +++ b/test/standalone/emit_asm_and_bin/build.zig @@ -11,5 +11,5 @@ pub fn build(b: *std.Build) void { main.emit_asm = .{ .emit_to = b.pathFromRoot("main.s") }; main.emit_bin = .{ .emit_to = b.pathFromRoot("main") }; - test_step.dependOn(&main.run().step); + test_step.dependOn(&b.addRunArtifact(main).step); } diff --git a/test/standalone/global_linkage/build.zig b/test/standalone/global_linkage/build.zig index ddcddd612a..d560027265 100644 --- a/test/standalone/global_linkage/build.zig +++ b/test/standalone/global_linkage/build.zig @@ -28,5 +28,5 @@ pub fn build(b: *std.Build) void { main.linkLibrary(obj1); main.linkLibrary(obj2); - test_step.dependOn(&main.run().step); + test_step.dependOn(&b.addRunArtifact(main).step); } diff --git a/test/standalone/issue_11595/build.zig b/test/standalone/issue_11595/build.zig index 7d9530c690..b03d3c66ce 100644 --- a/test/standalone/issue_11595/build.zig +++ b/test/standalone/issue_11595/build.zig @@ -19,7 +19,7 @@ pub fn build(b: *std.Build) void { .target = target, .optimize = optimize, }); - exe.install(); + b.installArtifact(exe); const c_sources = [_][]const u8{ "test.c", diff --git a/test/standalone/issue_13970/build.zig b/test/standalone/issue_13970/build.zig index 1eb8a5a121..7d2799e29e 100644 --- a/test/standalone/issue_13970/build.zig +++ b/test/standalone/issue_13970/build.zig @@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void { test2.setTestRunner("src/main.zig"); test3.setTestRunner("src/main.zig"); - test_step.dependOn(&test1.run().step); - test_step.dependOn(&test2.run().step); - test_step.dependOn(&test3.run().step); + test_step.dependOn(&b.addRunArtifact(test1).step); + test_step.dependOn(&b.addRunArtifact(test2).step); + test_step.dependOn(&b.addRunArtifact(test3).step); } diff --git a/test/standalone/issue_8550/build.zig b/test/standalone/issue_8550/build.zig index 8f7631e68f..32bb3e10eb 100644 --- a/test/standalone/issue_8550/build.zig +++ b/test/standalone/issue_8550/build.zig @@ -21,7 +21,7 @@ pub fn build(b: *std.Build) !void { }); kernel.addObjectFile("./boot.S"); kernel.setLinkerScriptPath(.{ .path = "./linker.ld" }); - kernel.install(); + b.installArtifact(kernel); test_step.dependOn(&kernel.step); } diff --git a/test/standalone/main_pkg_path/build.zig b/test/standalone/main_pkg_path/build.zig index a4dd301c43..f3eacce767 100644 --- a/test/standalone/main_pkg_path/build.zig +++ b/test/standalone/main_pkg_path/build.zig @@ -9,5 +9,5 @@ pub fn build(b: *std.Build) void { }); test_exe.setMainPkgPath("."); - test_step.dependOn(&test_exe.run().step); + test_step.dependOn(&b.addRunArtifact(test_exe).step); } diff --git a/test/standalone/mix_o_files/build.zig b/test/standalone/mix_o_files/build.zig index 17ce55a8aa..2d9323ff00 100644 --- a/test/standalone/mix_o_files/build.zig +++ b/test/standalone/mix_o_files/build.zig @@ -25,7 +25,6 @@ pub fn build(b: *std.Build) void { b.default_step.dependOn(&exe.step); - const run_cmd = exe.run(); - + const run_cmd = b.addRunArtifact(exe); test_step.dependOn(&run_cmd.step); } diff --git a/test/standalone/options/build.zig b/test/standalone/options/build.zig index 28e7e31eb7..d87610ba22 100644 --- a/test/standalone/options/build.zig +++ b/test/standalone/options/build.zig @@ -17,5 +17,5 @@ pub fn build(b: *std.Build) void { options.addOption([]const u8, "string", b.option([]const u8, "string", "s").?); const test_step = b.step("test", "Run unit tests"); - test_step.dependOn(&main.run().step); + test_step.dependOn(&b.addRunArtifact(main).step); } diff --git a/test/standalone/pie/build.zig b/test/standalone/pie/build.zig index e7ef5f97cc..1efcd5c26e 100644 --- a/test/standalone/pie/build.zig +++ b/test/standalone/pie/build.zig @@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void { }); main.pie = true; - const run = main.run(); + const run = b.addRunArtifact(main); run.skip_foreign_checks = true; test_step.dependOn(&run.step); diff --git a/test/standalone/pkg_import/build.zig b/test/standalone/pkg_import/build.zig index 42799ab896..30f4b2ede4 100644 --- a/test/standalone/pkg_import/build.zig +++ b/test/standalone/pkg_import/build.zig @@ -13,7 +13,6 @@ pub fn build(b: *std.Build) void { }); exe.addAnonymousModule("my_pkg", .{ .source_file = .{ .path = "pkg.zig" } }); - const run = exe.run(); - + const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); } diff --git a/test/standalone/shared_library/build.zig b/test/standalone/shared_library/build.zig index 63370af0cc..377bf81862 100644 --- a/test/standalone/shared_library/build.zig +++ b/test/standalone/shared_library/build.zig @@ -23,7 +23,6 @@ pub fn build(b: *std.Build) void { exe.linkLibrary(lib); exe.linkSystemLibrary("c"); - const run_cmd = exe.run(); - + const run_cmd = b.addRunArtifact(exe); test_step.dependOn(&run_cmd.step); } diff --git a/test/standalone/static_c_lib/build.zig b/test/standalone/static_c_lib/build.zig index 794b813b75..3feae705fc 100644 --- a/test/standalone/static_c_lib/build.zig +++ b/test/standalone/static_c_lib/build.zig @@ -21,5 +21,5 @@ pub fn build(b: *std.Build) void { test_exe.linkLibrary(foo); test_exe.addIncludePath("."); - test_step.dependOn(&test_exe.run().step); + test_step.dependOn(&b.addRunArtifact(test_exe).step); } diff --git a/test/standalone/test_runner_module_imports/build.zig b/test/standalone/test_runner_module_imports/build.zig index 685a6b1e3d..307957faee 100644 --- a/test/standalone/test_runner_module_imports/build.zig +++ b/test/standalone/test_runner_module_imports/build.zig @@ -15,6 +15,6 @@ pub fn build(b: *std.Build) void { t.addModule("module2", module2); const test_step = b.step("test", "Run unit tests"); - test_step.dependOn(&t.run().step); + test_step.dependOn(&b.addRunArtifact(t).step); b.default_step = test_step; } diff --git a/test/standalone/test_runner_path/build.zig b/test/standalone/test_runner_path/build.zig index ce5b668054..352a18efe0 100644 --- a/test/standalone/test_runner_path/build.zig +++ b/test/standalone/test_runner_path/build.zig @@ -11,7 +11,6 @@ pub fn build(b: *std.Build) void { }); test_exe.test_runner = "test_runner.zig"; - const test_run = test_exe.run(); - + const test_run = b.addRunArtifact(test_exe); test_step.dependOn(&test_run.step); } diff --git a/test/standalone/use_alias/build.zig b/test/standalone/use_alias/build.zig index db47fe6692..6fa0a1f3a5 100644 --- a/test/standalone/use_alias/build.zig +++ b/test/standalone/use_alias/build.zig @@ -12,5 +12,5 @@ pub fn build(b: *std.Build) void { }); main.addIncludePath("."); - test_step.dependOn(&main.run().step); + test_step.dependOn(&b.addRunArtifact(main).step); } diff --git a/test/tests.zig b/test/tests.zig index 26e684cd0d..a9bed635e2 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -596,7 +596,8 @@ pub fn addStandaloneTests( }); if (case.link_libc) exe.linkLibC(); - step.dependOn(&exe.run().step); + const run = b.addRunArtifact(exe); + step.dependOn(&run.step); } } } @@ -1004,7 +1005,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { }, }; - const run = these_tests.run(); + const run = b.addRunArtifact(these_tests); run.skip_foreign_checks = true; run.setName(b.fmt("run test {s}-{s}-{s}-{s}-{s}-{s}", .{ options.name, @@ -1061,7 +1062,7 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S triple_prefix, @tagName(optimize_mode), })); - const run = test_step.run(); + const run = b.addRunArtifact(test_step); run.skip_foreign_checks = true; step.dependOn(&run.step); } From 7221e9560ef03e8298f8fe8f9b1610459fceb5c7 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 10 Apr 2023 18:33:54 -0700 Subject: [PATCH 4/5] std.Build.RunStep: don't close stdin Instead, ignore stdin. Otherwise this interfers with a sub-process which expects to have a stdin file descriptor open. --- lib/std/Build/RunStep.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/std/Build/RunStep.zig b/lib/std/Build/RunStep.zig index 36b409d907..5658c5936f 100644 --- a/lib/std/Build/RunStep.zig +++ b/lib/std/Build/RunStep.zig @@ -866,9 +866,9 @@ fn spawnChildAndCollect( child.request_resource_usage_statistics = true; child.stdin_behavior = switch (self.stdio) { - .infer_from_args => if (has_side_effects) .Inherit else .Close, + .infer_from_args => if (has_side_effects) .Inherit else .Ignore, .inherit => .Inherit, - .check => .Close, + .check => .Ignore, .zig_test => .Pipe, }; child.stdout_behavior = switch (self.stdio) { From 406706fe6b5e969028a7c70247ebd1cb2b93102d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 10 Apr 2023 18:34:33 -0700 Subject: [PATCH 5/5] init-exe/init-lib template: fix use of install() and run() And while we're at it, make the unit tests be actually executed. --- lib/init-exe/build.zig | 13 ++++++++----- lib/init-lib/build.zig | 9 ++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/init-exe/build.zig b/lib/init-exe/build.zig index 2ef5b21fe9..abf8654f0f 100644 --- a/lib/init-exe/build.zig +++ b/lib/init-exe/build.zig @@ -27,12 +27,12 @@ pub fn build(b: *std.Build) void { // This declares intent for the executable to be installed into the // standard location when the user invokes the "install" step (the default // step when running `zig build`). - exe.install(); + b.installArtifact(exe); // This *creates* a RunStep in the build graph, to be executed when another // step is evaluated that depends on it. The next line below will establish // such a dependency. - const run_cmd = exe.run(); + const run_cmd = b.addRunArtifact(exe); // By making the run step depend on the install step, it will be run from the // installation directory rather than directly from within the cache directory. @@ -52,16 +52,19 @@ pub fn build(b: *std.Build) void { const run_step = b.step("run", "Run the app"); run_step.dependOn(&run_cmd.step); - // Creates a step for unit testing. - const exe_tests = b.addTest(.{ + // Creates a step for unit testing. This only builds the test executable + // but does not run it. + const unit_tests = b.addTest(.{ .root_source_file = .{ .path = "src/main.zig" }, .target = target, .optimize = optimize, }); + const run_unit_tests = b.addRunArtifact(unit_tests); + // Similar to creating the run step earlier, this exposes a `test` step to // the `zig build --help` menu, providing a way for the user to request // running the unit tests. const test_step = b.step("test", "Run unit tests"); - test_step.dependOn(&exe_tests.step); + test_step.dependOn(&run_unit_tests.step); } diff --git a/lib/init-lib/build.zig b/lib/init-lib/build.zig index 2887c170e6..70592d896d 100644 --- a/lib/init-lib/build.zig +++ b/lib/init-lib/build.zig @@ -27,18 +27,21 @@ pub fn build(b: *std.Build) void { // This declares intent for the library to be installed into the standard // location when the user invokes the "install" step (the default step when // running `zig build`). - lib.install(); + b.installArtifact(lib); - // Creates a step for unit testing. + // Creates a step for unit testing. This only builds the test executable + // but does not run it. const main_tests = b.addTest(.{ .root_source_file = .{ .path = "src/main.zig" }, .target = target, .optimize = optimize, }); + const run_main_tests = b.addRunArtifact(main_tests); + // This creates a build step. It will be visible in the `zig build --help` menu, // and can be selected like this: `zig build test` // This will evaluate the `test` step rather than the default, which is "install". const test_step = b.step("test", "Run library tests"); - test_step.dependOn(&main_tests.step); + test_step.dependOn(&run_main_tests.step); }