mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
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
This commit is contained in:
parent
38698f4f6a
commit
60eabc0eca
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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("");
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user