Commit 60eabc0eca

Andrew Kelley <andrew@ziglang.org>
2023-04-11 02:05:09
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
1 parent 38698f4
Changed files (42)
lib
std
test
link
bss
common_symbols
common_symbols_alignment
interdependent_static_c_libs
macho
bugs
13056
dead_strip_dylibs
entry_in_archive
headerpad
needed_framework
objcpp
tls
weak_framework
weak_library
wasm
producers
segments
stack_pointer
type
src
standalone
dep_diamond
dep_mutually_recursive
dep_recursive
dep_shared_builtin
dep_triangle
emit_asm_and_bin
global_linkage
issue_11595
issue_13970
issue_8550
main_pkg_path
mix_o_files
options
pie
pkg_import
shared_library
static_c_lib
test_runner_module_imports
test_runner_path
use_alias
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);
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);
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);
 }
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);
 }
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);
 }
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);
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);
     }
 
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);
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);
     }
 }
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);
 }
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);
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);
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);
 }
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",
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;
 
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");
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();
 
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");
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);
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("");
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);
 }
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);
 }
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);
 }
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);
 }
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);
 }
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);
 }
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);
 }
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",
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);
 }
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);
 }
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);
 }
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);
 }
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);
 }
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);
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);
 }
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);
 }
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);
 }
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;
 }
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);
 }
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);
 }
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);
         }
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);