Skip to content

Commit 0d79aa0

Browse files
authored
std.Build.Step.Run: support prefixed artifact args
Just like how addPrefixedFileArg and addPrefixedDirectoryArg works, we can make it for artifacts. Signed-off-by: Bingwu Zhang <[email protected]>
1 parent 3bf0d2e commit 0d79aa0

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

lib/std/Build/Step/Run.zig

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,19 @@ pub const StdIo = union(enum) {
126126
};
127127

128128
pub const Arg = union(enum) {
129-
artifact: *Step.Compile,
129+
artifact: PrefixedArtifact,
130130
lazy_path: PrefixedLazyPath,
131131
directory_source: PrefixedLazyPath,
132132
bytes: []u8,
133133
output_file: *Output,
134134
output_directory: *Output,
135135
};
136136

137+
pub const PrefixedArtifact = struct {
138+
prefix: []const u8,
139+
artifact: *Step.Compile,
140+
};
141+
137142
pub const PrefixedLazyPath = struct {
138143
prefix: []const u8,
139144
lazy_path: std.Build.LazyPath,
@@ -185,10 +190,20 @@ pub fn enableTestRunnerMode(run: *Run) void {
185190
}
186191

187192
pub fn addArtifactArg(run: *Run, artifact: *Step.Compile) void {
193+
run.addPrefixedArtifactArg("", artifact);
194+
}
195+
196+
pub fn addPrefixedArtifactArg(run: *Run, prefix: []const u8, artifact: *Step.Compile) void {
188197
const b = run.step.owner;
198+
199+
const prefixed_artifact: PrefixedArtifact = .{
200+
.prefix = b.dupe(prefix),
201+
.artifact = artifact,
202+
};
203+
run.argv.append(b.allocator, .{ .artifact = prefixed_artifact }) catch @panic("OOM");
204+
189205
const bin_file = artifact.getEmittedBin();
190206
bin_file.addStepDependencies(&run.step);
191-
run.argv.append(b.allocator, Arg{ .artifact = artifact }) catch @panic("OOM");
192207
}
193208

194209
/// Provides a file path as a command line argument to the command being run.
@@ -610,14 +625,16 @@ fn make(step: *Step, prog_node: std.Progress.Node) !void {
610625
man.hash.addBytes(file.prefix);
611626
man.hash.addBytes(file_path);
612627
},
613-
.artifact => |artifact| {
628+
.artifact => |pa| {
629+
const artifact = pa.artifact;
630+
614631
if (artifact.rootModuleTarget().os.tag == .windows) {
615632
// On Windows we don't have rpaths so we have to add .dll search paths to PATH
616633
run.addPathForDynLibs(artifact);
617634
}
618635
const file_path = artifact.installed_path orelse artifact.generated_bin.?.path.?; // the path is guaranteed to be set
619636

620-
try argv_list.append(file_path);
637+
try argv_list.append(b.fmt("{s}{s}", .{ pa.prefix, file_path }));
621638

622639
_ = try man.addFile(file_path, null);
623640
},
@@ -912,7 +929,7 @@ fn runCommand(
912929
// work even for the edge case that the binary was produced by a
913930
// third party.
914931
const exe = switch (run.argv.items[0]) {
915-
.artifact => |exe| exe,
932+
.artifact => |exe| exe.artifact,
916933
else => break :interpret,
917934
};
918935
switch (exe.kind) {

0 commit comments

Comments
 (0)