mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std.Build: support running build artifacts from packages
Deprecate CompileStep.run. The problem with this function is that it does the RunStep with the same build.zig context as the CompileStep, but this is not desirable when running an executable that is provided by a dependency package. Instead, users should use `b.addRunArtifact`. This has the additional benefit of conforming to the existing naming conventions. Additionally, support enum literals in config header options values.
This commit is contained in:
parent
27317eaff0
commit
dad6039092
2 changed files with 27 additions and 20 deletions
|
|
@ -348,7 +348,7 @@ fn applyArgs(b: *Build, args: anytype) !void {
|
|||
.used = false,
|
||||
});
|
||||
},
|
||||
.Enum => {
|
||||
.Enum, .EnumLiteral => {
|
||||
try b.user_input_options.put(field.name, .{
|
||||
.name = field.name,
|
||||
.value = .{ .scalar = @tagName(v) },
|
||||
|
|
@ -599,6 +599,28 @@ pub fn addSystemCommand(self: *Build, argv: []const []const u8) *RunStep {
|
|||
return run_step;
|
||||
}
|
||||
|
||||
/// Creates a `RunStep` with an executable built with `addExecutable`.
|
||||
/// Add command line arguments with methods of `RunStep`.
|
||||
pub fn addRunArtifact(b: *Build, exe: *CompileStep) *RunStep {
|
||||
assert(exe.kind == .exe or exe.kind == .test_exe);
|
||||
|
||||
// It doesn't have to be native. We catch that if you actually try to run it.
|
||||
// Consider that this is declarative; the run step may not be run unless a user
|
||||
// option is supplied.
|
||||
const run_step = RunStep.create(b, b.fmt("run {s}", .{exe.step.name}));
|
||||
run_step.addArtifactArg(exe);
|
||||
|
||||
if (exe.kind == .test_exe) {
|
||||
run_step.addArg(b.zig_exe);
|
||||
}
|
||||
|
||||
if (exe.vcpkg_bin_path) |path| {
|
||||
run_step.addPathDir(path);
|
||||
}
|
||||
|
||||
return run_step;
|
||||
}
|
||||
|
||||
/// Using the `values` provided, produces a C header file, possibly based on a
|
||||
/// template input file (e.g. config.h.in).
|
||||
/// When an input template file is provided, this function will fail the build
|
||||
|
|
|
|||
|
|
@ -506,26 +506,11 @@ pub fn installLibraryHeaders(a: *CompileStep, l: *CompileStep) void {
|
|||
a.installed_headers.appendSlice(l.installed_headers.items) catch @panic("OOM");
|
||||
}
|
||||
|
||||
/// Creates a `RunStep` with an executable built with `addExecutable`.
|
||||
/// Add command line arguments with `addArg`.
|
||||
/// Deprecated: use `std.Build.addRunArtifact`
|
||||
/// This function will 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(exe: *CompileStep) *RunStep {
|
||||
assert(exe.kind == .exe or exe.kind == .test_exe);
|
||||
|
||||
// It doesn't have to be native. We catch that if you actually try to run it.
|
||||
// Consider that this is declarative; the run step may not be run unless a user
|
||||
// option is supplied.
|
||||
const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {s}", .{exe.step.name}));
|
||||
run_step.addArtifactArg(exe);
|
||||
|
||||
if (exe.kind == .test_exe) {
|
||||
run_step.addArg(exe.builder.zig_exe);
|
||||
}
|
||||
|
||||
if (exe.vcpkg_bin_path) |path| {
|
||||
run_step.addPathDir(path);
|
||||
}
|
||||
|
||||
return run_step;
|
||||
return exe.builder.addRunArtifact(exe);
|
||||
}
|
||||
|
||||
/// Creates an `EmulatableRunStep` with an executable built with `addExecutable`.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue