aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorJonathan Marler <johnnymarler@gmail.com>2021-10-18 11:05:47 -0600
committerAndrew Kelley <andrew@ziglang.org>2021-12-03 12:56:49 -0800
commit7659229edcc9b0455010188fafdce26ac26de9b2 (patch)
tree4aa38b58957acdf747dd2289f4a867f5dc5b5e8e /lib/std
parent1cac99c90a34bc2cab96d75017a337ddd3479b50 (diff)
downloadzig-7659229edcc9b0455010188fafdce26ac26de9b2.tar.gz
zig-7659229edcc9b0455010188fafdce26ac26de9b2.zip
std.build.InstallRawStep: allow custom dest_dir
I'm working on a build.zig file where I'm leveraging InstallRawStep but I'd like to change the install dir. This allows the install dir to be changd and also enhances InstallRawStep to add more options in the future by putting them into a struct with default values. This also removes the need for an extra addInstallStepWithFormat function in build.zig.
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/build.zig24
-rw-r--r--lib/std/build/InstallRawStep.zig11
2 files changed, 14 insertions, 21 deletions
diff --git a/lib/std/build.zig b/lib/std/build.zig
index c8ff1e4c87..30296081b7 100644
--- a/lib/std/build.zig
+++ b/lib/std/build.zig
@@ -1018,12 +1018,8 @@ pub const Builder = struct {
}
/// Output format (BIN vs Intel HEX) determined by filename
- pub fn installRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) void {
- self.getInstallStep().dependOn(&self.addInstallRaw(artifact, dest_filename).step);
- }
-
- pub fn installRawWithFormat(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8, format: InstallRawStep.RawFormat) void {
- self.getInstallStep().dependOn(&self.addInstallRawWithFormat(artifact, dest_filename, format).step);
+ pub fn installRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8, options: InstallRawStep.CreateOptions) void {
+ self.getInstallStep().dependOn(&self.addInstallRaw(artifact, dest_filename, options).step);
}
///`dest_rel_path` is relative to install prefix path
@@ -1041,12 +1037,8 @@ pub const Builder = struct {
return self.addInstallFileWithDir(source.dupe(self), .lib, dest_rel_path);
}
- pub fn addInstallRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) *InstallRawStep {
- return InstallRawStep.create(self, artifact, dest_filename, null);
- }
-
- pub fn addInstallRawWithFormat(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8, format: InstallRawStep.RawFormat) *InstallRawStep {
- return InstallRawStep.create(self, artifact, dest_filename, format);
+ pub fn addInstallRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8, options: InstallRawStep.CreateOptions) *InstallRawStep {
+ return InstallRawStep.create(self, artifact, dest_filename, options);
}
pub fn addInstallFileWithDir(
@@ -1740,12 +1732,8 @@ pub const LibExeObjStep = struct {
self.builder.installArtifact(self);
}
- pub fn installRaw(self: *LibExeObjStep, dest_filename: []const u8) void {
- self.builder.installRaw(self, dest_filename);
- }
-
- pub fn installRawWithFormat(self: *LibExeObjStep, dest_filename: []const u8, format: InstallRawStep.RawFormat) void {
- self.builder.installRawWithFormat(self, dest_filename, format);
+ pub fn installRaw(self: *LibExeObjStep, dest_filename: []const u8, options: InstallRawStep.CreateOptions) void {
+ self.builder.installRaw(self, dest_filename, options);
}
/// Creates a `RunStep` with an executable built with `addExecutable`.
diff --git a/lib/std/build/InstallRawStep.zig b/lib/std/build/InstallRawStep.zig
index 0f921d6622..17a23931e2 100644
--- a/lib/std/build/InstallRawStep.zig
+++ b/lib/std/build/InstallRawStep.zig
@@ -355,20 +355,25 @@ fn detectFormat(filename: []const u8) RawFormat {
return .bin;
}
-pub fn create(builder: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8, format: ?RawFormat) *InstallRawStep {
+pub const CreateOptions = struct {
+ format: ?RawFormat = null,
+ dest_dir: ?InstallDir = null,
+};
+
+pub fn create(builder: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8, options: CreateOptions) *InstallRawStep {
const self = builder.allocator.create(InstallRawStep) catch unreachable;
self.* = InstallRawStep{
.step = Step.init(.install_raw, builder.fmt("install raw binary {s}", .{artifact.step.name}), builder.allocator, make),
.builder = builder,
.artifact = artifact,
- .dest_dir = switch (artifact.kind) {
+ .dest_dir = if (options.dest_dir) |d| d else switch (artifact.kind) {
.obj => unreachable,
.@"test" => unreachable,
.exe => .bin,
.lib => unreachable,
},
.dest_filename = dest_filename,
- .format = format orelse detectFormat(dest_filename),
+ .format = if (options.format) |f| f else detectFormat(dest_filename),
.output_file = std.build.GeneratedFile{ .step = &self.step },
};
self.step.dependOn(&artifact.step);