authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-10 17:05:09-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-10 18:35:14-07:00
log60eabc0eca5f678d0c6569a9565b1d6141459518
tree4865a7c2ebca0b21077e4e3b329e6ff80561dd67
parent38698f4f6aabb20639642afa58b17f31a43e162b

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

42 files changed, 57 insertions(+), 69 deletions(-)

build.zig+1-1
......@@ -181,7 +181,7 @@ pub fn build(b: *std.Build) !void {
181181 exe.sanitize_thread = sanitize_thread;
182182 exe.build_id = b.option(bool, "build-id", "Include a build id note") orelse false;
183183 exe.entitlements = entitlements;
184 exe.install();
184 b.installArtifact(exe);
185185
186186 const compile_step = b.step("compile", "Build the self-hosted compiler");
187187 compile_step.dependOn(&exe.step);
lib/std/Build/CompileStep.zig+6-10
......@@ -463,11 +463,6 @@ pub fn setOutputDir(self: *CompileStep, dir: []const u8) void {
463463 self.output_dir = b.dupePath(dir);
464464}
465465
466pub fn install(self: *CompileStep) void {
467 const b = self.step.owner;
468 b.installArtifact(self);
469}
470
471466pub fn installHeader(cs: *CompileStep, src_path: []const u8, dest_rel_path: []const u8) void {
472467 const b = cs.step.owner;
473468 const install_file = b.addInstallHeaderFile(src_path, dest_rel_path);
......@@ -555,12 +550,13 @@ pub fn addObjCopy(cs: *CompileStep, options: ObjCopyStep.Options) *ObjCopyStep {
555550 return b.addObjCopy(cs.getOutputSource(), copy);
556551}
557552
558/// Deprecated: use `std.Build.addRunArtifact`
559/// This function will run in the context of the package that created the executable,
553/// This function would run in the context of the package that created the executable,
560554/// which is undesirable when running an executable provided by a dependency package.
561pub fn run(cs: *CompileStep) *RunStep {
562 return cs.step.owner.addRunArtifact(cs);
563}
555pub const run = @compileError("deprecated; use std.Build.addRunArtifact");
556
557/// This function would install in the context of the package that created the artifact,
558/// which is undesirable when installing an artifact provided by a dependency package.
559pub const install = @compileError("deprecated; use std.Build.installArtifact");
564560
565561pub fn checkObject(self: *CompileStep) *CheckObjectStep {
566562 return CheckObjectStep.create(self.step.owner, self.getOutputSource(), self.target_info.target.ofmt);
test/link/bss/build.zig+1-1
......@@ -10,7 +10,7 @@ pub fn build(b: *std.Build) void {
1010 .optimize = .Debug,
1111 });
1212
13 const run = exe.run();
13 const run = b.addRunArtifact(exe);
1414 run.expectStdOutEqual("0, 1, 0\n");
1515
1616 test_step.dependOn(&run.step);
test/link/common_symbols/build.zig+1-1
......@@ -24,5 +24,5 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2424 });
2525 test_exe.linkLibrary(lib_a);
2626
27 test_step.dependOn(&test_exe.run().step);
27 test_step.dependOn(&b.addRunArtifact(test_exe).step);
2828}
test/link/common_symbols_alignment/build.zig+1-1
......@@ -24,5 +24,5 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2424 });
2525 test_exe.linkLibrary(lib_a);
2626
27 test_step.dependOn(&test_exe.run().step);
27 test_step.dependOn(&b.addRunArtifact(test_exe).step);
2828}
test/link/interdependent_static_c_libs/build.zig+1-1
......@@ -35,5 +35,5 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
3535 test_exe.linkLibrary(lib_b);
3636 test_exe.addIncludePath(".");
3737
38 test_step.dependOn(&test_exe.run().step);
38 test_step.dependOn(&b.addRunArtifact(test_exe).step);
3939}
test/link/macho/bugs/13056/build.zig+1-1
......@@ -31,7 +31,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
3131 });
3232 exe.addObjectFile(std.fs.path.join(b.allocator, &.{ sdk.path, "/usr/lib/libc++.tbd" }) catch unreachable);
3333
34 const run_cmd = exe.run();
34 const run_cmd = b.addRunArtifact(exe);
3535 run_cmd.expectStdErrEqual("x: 5\n");
3636
3737 test_step.dependOn(&run_cmd.step);
test/link/macho/dead_strip_dylibs/build.zig+1-1
......@@ -27,7 +27,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2727
2828 test_step.dependOn(&check.step);
2929
30 const run_cmd = exe.run();
30 const run_cmd = b.addRunArtifact(exe);
3131 test_step.dependOn(&run_cmd.step);
3232 }
3333
test/link/macho/entry_in_archive/build.zig+1-1
......@@ -29,7 +29,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2929 exe.linkLibrary(lib);
3030 exe.linkLibC();
3131
32 const run = exe.run();
32 const run = b.addRunArtifact(exe);
3333 run.skip_foreign_checks = true;
3434 run.expectExitCode(0);
3535 test_step.dependOn(&run.step);
test/link/macho/headerpad/build.zig+4-4
......@@ -36,7 +36,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
3636
3737 test_step.dependOn(&check.step);
3838
39 const run = exe.run();
39 const run = b.addRunArtifact(exe);
4040 test_step.dependOn(&run.step);
4141 }
4242
......@@ -52,7 +52,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
5252
5353 test_step.dependOn(&check.step);
5454
55 const run = exe.run();
55 const run = b.addRunArtifact(exe);
5656 test_step.dependOn(&run.step);
5757 }
5858
......@@ -69,7 +69,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
6969
7070 test_step.dependOn(&check.step);
7171
72 const run = exe.run();
72 const run = b.addRunArtifact(exe);
7373 test_step.dependOn(&run.step);
7474 }
7575
......@@ -95,7 +95,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
9595
9696 test_step.dependOn(&check.step);
9797
98 const run = exe.run();
98 const run = b.addRunArtifact(exe);
9999 test_step.dependOn(&run.step);
100100 }
101101}
test/link/macho/needed_framework/build.zig+1-1
......@@ -30,6 +30,6 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
3030 check.checkNext("name {*}Cocoa");
3131 test_step.dependOn(&check.step);
3232
33 const run_cmd = exe.run();
33 const run_cmd = b.addRunArtifact(exe);
3434 test_step.dependOn(&run_cmd.step);
3535}
test/link/macho/objcpp/build.zig+1-1
......@@ -27,7 +27,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2727 // populate paths to the sysroot here.
2828 exe.linkFramework("Foundation");
2929
30 const run_cmd = exe.run();
30 const run_cmd = b.addRunArtifact(exe);
3131 run_cmd.expectStdOutEqual("Hello from C++ and Zig");
3232
3333 test_step.dependOn(&run_cmd.step);
test/link/macho/tls/build.zig+1-1
......@@ -32,7 +32,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
3232 test_exe.linkLibrary(lib);
3333 test_exe.linkLibC();
3434
35 const run = test_exe.run();
35 const run = b.addRunArtifact(test_exe);
3636 run.skip_foreign_checks = true;
3737
3838 test_step.dependOn(&run.step);
test/link/macho/weak_framework/build.zig+1-1
......@@ -27,6 +27,6 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2727 check.checkNext("name {*}Cocoa");
2828 test_step.dependOn(&check.step);
2929
30 const run_cmd = exe.run();
30 const run_cmd = b.addRunArtifact(exe);
3131 test_step.dependOn(&run_cmd.step);
3232}
test/link/macho/weak_library/build.zig+1-1
......@@ -23,7 +23,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2323 });
2424 dylib.addCSourceFile("a.c", &.{});
2525 dylib.linkLibC();
26 dylib.install();
26 b.installArtifact(dylib);
2727
2828 const exe = b.addExecutable(.{
2929 .name = "test",
test/link/wasm/producers/build.zig+1-1
......@@ -23,7 +23,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2323 lib.use_llvm = false;
2424 lib.use_lld = false;
2525 lib.strip = false;
26 lib.install();
26 b.installArtifact(lib);
2727
2828 const version_fmt = "version " ++ builtin.zig_version_string;
2929
test/link/wasm/segments/build.zig+1-1
......@@ -22,7 +22,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2222 lib.use_llvm = false;
2323 lib.use_lld = false;
2424 lib.strip = false;
25 lib.install();
25 b.installArtifact(lib);
2626
2727 const check_lib = lib.checkObject();
2828 check_lib.checkStart("Section data");
test/link/wasm/stack_pointer/build.zig+1-1
......@@ -23,7 +23,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2323 lib.use_lld = false;
2424 lib.strip = false;
2525 lib.stack_size = std.wasm.page_size * 2; // set an explicit stack size
26 lib.install();
26 b.installArtifact(lib);
2727
2828 const check_lib = lib.checkObject();
2929
test/link/wasm/type/build.zig+1-1
......@@ -22,7 +22,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2222 lib.use_llvm = false;
2323 lib.use_lld = false;
2424 lib.strip = false;
25 lib.install();
25 b.installArtifact(lib);
2626
2727 const check_lib = lib.checkObject();
2828 check_lib.checkStart("Section type");
test/src/CompareOutput.zig+3-3
......@@ -101,7 +101,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void {
101101 });
102102 exe.addAssemblyFileSource(write_src.getFileSource(case.sources.items[0].filename).?);
103103
104 const run = exe.run();
104 const run = b.addRunArtifact(exe);
105105 run.setName(annotated_case_name);
106106 run.addArgs(case.cli_args);
107107 run.expectStdOutEqual(case.expected_output);
......@@ -128,7 +128,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void {
128128 exe.linkSystemLibrary("c");
129129 }
130130
131 const run = exe.run();
131 const run = b.addRunArtifact(exe);
132132 run.setName(annotated_case_name);
133133 run.addArgs(case.cli_args);
134134 run.expectStdOutEqual(case.expected_output);
......@@ -155,7 +155,7 @@ pub fn addCase(self: *CompareOutput, case: TestCase) void {
155155 exe.linkSystemLibrary("c");
156156 }
157157
158 const run = exe.run();
158 const run = b.addRunArtifact(exe);
159159 run.setName(annotated_case_name);
160160 run.addArgs(case.cli_args);
161161 run.expectExitCode(126);
test/src/run_translated_c.zig+1-1
......@@ -94,7 +94,7 @@ pub const RunTranslatedCContext = struct {
9494 const exe = translate_c.addExecutable(.{});
9595 exe.step.name = b.fmt("{s} build-exe", .{annotated_case_name});
9696 exe.linkLibC();
97 const run = exe.run();
97 const run = b.addRunArtifact(exe);
9898 run.step.name = b.fmt("{s} run", .{annotated_case_name});
9999 if (!case.allow_warnings) {
100100 run.expectStdErrEqual("");
test/standalone/dep_diamond/build.zig+1-2
......@@ -24,7 +24,6 @@ pub fn build(b: *std.Build) void {
2424 .dependencies = &.{.{ .name = "shared", .module = shared }},
2525 });
2626
27 const run = exe.run();
28
27 const run = b.addRunArtifact(exe);
2928 test_step.dependOn(&run.step);
3029}
test/standalone/dep_mutually_recursive/build.zig+1-2
......@@ -22,7 +22,6 @@ pub fn build(b: *std.Build) void {
2222 });
2323 exe.addModule("foo", foo);
2424
25 const run = exe.run();
26
25 const run = b.addRunArtifact(exe);
2726 test_step.dependOn(&run.step);
2827}
test/standalone/dep_recursive/build.zig+1-2
......@@ -18,7 +18,6 @@ pub fn build(b: *std.Build) void {
1818 });
1919 exe.addModule("foo", foo);
2020
21 const run = exe.run();
22
21 const run = b.addRunArtifact(exe);
2322 test_step.dependOn(&run.step);
2423}
test/standalone/dep_shared_builtin/build.zig+1-2
......@@ -15,7 +15,6 @@ pub fn build(b: *std.Build) void {
1515 .source_file = .{ .path = "foo.zig" },
1616 });
1717
18 const run = exe.run();
19
18 const run = b.addRunArtifact(exe);
2019 test_step.dependOn(&run.step);
2120}
test/standalone/dep_triangle/build.zig+1-2
......@@ -21,7 +21,6 @@ pub fn build(b: *std.Build) void {
2121 });
2222 exe.addModule("shared", shared);
2323
24 const run = exe.run();
25
24 const run = b.addRunArtifact(exe);
2625 test_step.dependOn(&run.step);
2726}
test/standalone/emit_asm_and_bin/build.zig+1-1
......@@ -11,5 +11,5 @@ pub fn build(b: *std.Build) void {
1111 main.emit_asm = .{ .emit_to = b.pathFromRoot("main.s") };
1212 main.emit_bin = .{ .emit_to = b.pathFromRoot("main") };
1313
14 test_step.dependOn(&main.run().step);
14 test_step.dependOn(&b.addRunArtifact(main).step);
1515}
test/standalone/global_linkage/build.zig+1-1
......@@ -28,5 +28,5 @@ pub fn build(b: *std.Build) void {
2828 main.linkLibrary(obj1);
2929 main.linkLibrary(obj2);
3030
31 test_step.dependOn(&main.run().step);
31 test_step.dependOn(&b.addRunArtifact(main).step);
3232}
test/standalone/issue_11595/build.zig+1-1
......@@ -19,7 +19,7 @@ pub fn build(b: *std.Build) void {
1919 .target = target,
2020 .optimize = optimize,
2121 });
22 exe.install();
22 b.installArtifact(exe);
2323
2424 const c_sources = [_][]const u8{
2525 "test.c",
test/standalone/issue_13970/build.zig+3-3
......@@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void {
1717 test2.setTestRunner("src/main.zig");
1818 test3.setTestRunner("src/main.zig");
1919
20 test_step.dependOn(&test1.run().step);
21 test_step.dependOn(&test2.run().step);
22 test_step.dependOn(&test3.run().step);
20 test_step.dependOn(&b.addRunArtifact(test1).step);
21 test_step.dependOn(&b.addRunArtifact(test2).step);
22 test_step.dependOn(&b.addRunArtifact(test3).step);
2323}
test/standalone/issue_8550/build.zig+1-1
......@@ -21,7 +21,7 @@ pub fn build(b: *std.Build) !void {
2121 });
2222 kernel.addObjectFile("./boot.S");
2323 kernel.setLinkerScriptPath(.{ .path = "./linker.ld" });
24 kernel.install();
24 b.installArtifact(kernel);
2525
2626 test_step.dependOn(&kernel.step);
2727}
test/standalone/main_pkg_path/build.zig+1-1
......@@ -9,5 +9,5 @@ pub fn build(b: *std.Build) void {
99 });
1010 test_exe.setMainPkgPath(".");
1111
12 test_step.dependOn(&test_exe.run().step);
12 test_step.dependOn(&b.addRunArtifact(test_exe).step);
1313}
test/standalone/mix_o_files/build.zig+1-2
......@@ -25,7 +25,6 @@ pub fn build(b: *std.Build) void {
2525
2626 b.default_step.dependOn(&exe.step);
2727
28 const run_cmd = exe.run();
29
28 const run_cmd = b.addRunArtifact(exe);
3029 test_step.dependOn(&run_cmd.step);
3130}
test/standalone/options/build.zig+1-1
......@@ -17,5 +17,5 @@ pub fn build(b: *std.Build) void {
1717 options.addOption([]const u8, "string", b.option([]const u8, "string", "s").?);
1818
1919 const test_step = b.step("test", "Run unit tests");
20 test_step.dependOn(&main.run().step);
20 test_step.dependOn(&b.addRunArtifact(main).step);
2121}
test/standalone/pie/build.zig+1-1
......@@ -17,7 +17,7 @@ pub fn build(b: *std.Build) void {
1717 });
1818 main.pie = true;
1919
20 const run = main.run();
20 const run = b.addRunArtifact(main);
2121 run.skip_foreign_checks = true;
2222
2323 test_step.dependOn(&run.step);
test/standalone/pkg_import/build.zig+1-2
......@@ -13,7 +13,6 @@ pub fn build(b: *std.Build) void {
1313 });
1414 exe.addAnonymousModule("my_pkg", .{ .source_file = .{ .path = "pkg.zig" } });
1515
16 const run = exe.run();
17
16 const run = b.addRunArtifact(exe);
1817 test_step.dependOn(&run.step);
1918}
test/standalone/shared_library/build.zig+1-2
......@@ -23,7 +23,6 @@ pub fn build(b: *std.Build) void {
2323 exe.linkLibrary(lib);
2424 exe.linkSystemLibrary("c");
2525
26 const run_cmd = exe.run();
27
26 const run_cmd = b.addRunArtifact(exe);
2827 test_step.dependOn(&run_cmd.step);
2928}
test/standalone/static_c_lib/build.zig+1-1
......@@ -21,5 +21,5 @@ pub fn build(b: *std.Build) void {
2121 test_exe.linkLibrary(foo);
2222 test_exe.addIncludePath(".");
2323
24 test_step.dependOn(&test_exe.run().step);
24 test_step.dependOn(&b.addRunArtifact(test_exe).step);
2525}
test/standalone/test_runner_module_imports/build.zig+1-1
......@@ -15,6 +15,6 @@ pub fn build(b: *std.Build) void {
1515 t.addModule("module2", module2);
1616
1717 const test_step = b.step("test", "Run unit tests");
18 test_step.dependOn(&t.run().step);
18 test_step.dependOn(&b.addRunArtifact(t).step);
1919 b.default_step = test_step;
2020}
test/standalone/test_runner_path/build.zig+1-2
......@@ -11,7 +11,6 @@ pub fn build(b: *std.Build) void {
1111 });
1212 test_exe.test_runner = "test_runner.zig";
1313
14 const test_run = test_exe.run();
15
14 const test_run = b.addRunArtifact(test_exe);
1615 test_step.dependOn(&test_run.step);
1716}
test/standalone/use_alias/build.zig+1-1
......@@ -12,5 +12,5 @@ pub fn build(b: *std.Build) void {
1212 });
1313 main.addIncludePath(".");
1414
15 test_step.dependOn(&main.run().step);
15 test_step.dependOn(&b.addRunArtifact(main).step);
1616}
test/tests.zig+4-3
......@@ -596,7 +596,8 @@ pub fn addStandaloneTests(
596596 });
597597 if (case.link_libc) exe.linkLibC();
598598
599 step.dependOn(&exe.run().step);
599 const run = b.addRunArtifact(exe);
600 step.dependOn(&run.step);
600601 }
601602 }
602603 }
......@@ -1004,7 +1005,7 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
10041005 },
10051006 };
10061007
1007 const run = these_tests.run();
1008 const run = b.addRunArtifact(these_tests);
10081009 run.skip_foreign_checks = true;
10091010 run.setName(b.fmt("run test {s}-{s}-{s}-{s}-{s}-{s}", .{
10101011 options.name,
......@@ -1061,7 +1062,7 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S
10611062 triple_prefix, @tagName(optimize_mode),
10621063 }));
10631064
1064 const run = test_step.run();
1065 const run = b.addRunArtifact(test_step);
10651066 run.skip_foreign_checks = true;
10661067 step.dependOn(&run.step);
10671068 }