From fb9d5529dad8356de51f09da5da5f36c8fd8bf9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20=28xq=29=20Quei=C3=9Fner?= Date: Sat, 25 Jul 2020 18:36:55 +0200 Subject: [PATCH] Adds support for RunStep to use the result of a WriteFileStep. --- lib/std/build/run.zig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/std/build/run.zig b/lib/std/build/run.zig index 5af2c2d075..839e177edd 100644 --- a/lib/std/build/run.zig +++ b/lib/std/build/run.zig @@ -4,6 +4,7 @@ const build = std.build; const Step = build.Step; const Builder = build.Builder; const LibExeObjStep = build.LibExeObjStep; +const WriteFileStep = build.WriteFileStep; const fs = std.fs; const mem = std.mem; const process = std.process; @@ -42,6 +43,10 @@ pub const RunStep = struct { pub const Arg = union(enum) { Artifact: *LibExeObjStep, + WriteFile: struct { + step: *WriteFileStep, + file_name: []const u8, + }, Bytes: []u8, }; @@ -62,6 +67,16 @@ pub const RunStep = struct { self.step.dependOn(&artifact.step); } + pub fn addWriteFileArg(self: *RunStep, write_file: *WriteFileStep, file_name: []const u8) void { + self.argv.append(Arg{ + .WriteFile = .{ + .step = write_file, + .file_name = file_name, + }, + }) catch unreachable; + self.step.dependOn(&write_file.step); + } + pub fn addArg(self: *RunStep, arg: []const u8) void { self.argv.append(Arg{ .Bytes = self.builder.dupe(arg) }) catch unreachable; } @@ -142,6 +157,9 @@ pub const RunStep = struct { for (self.argv.span()) |arg| { switch (arg) { Arg.Bytes => |bytes| try argv_list.append(bytes), + Arg.WriteFile => |file| { + try argv_list.append(file.step.getOutputPath(file.file_name)); + }, Arg.Artifact => |artifact| { if (artifact.target.isWindows()) { // On Windows we don't have rpaths so we have to add .dll search paths to PATH