Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 6 additions & 18 deletions lib/std/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -994,12 +994,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
Expand All @@ -1017,12 +1013,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(
Expand Down Expand Up @@ -1718,12 +1710,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`.
Expand Down
11 changes: 8 additions & 3 deletions lib/std/build/InstallRawStep.zig
Original file line number Diff line number Diff line change
Expand Up @@ -356,20 +356,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);
Expand Down
4 changes: 2 additions & 2 deletions test/standalone/install_raw_hex/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ pub fn build(b: *Builder) void {
const test_step = b.step("test", "Test the program");
b.default_step.dependOn(test_step);

const hex_step = b.addInstallRaw(elf, "hello.hex");
const hex_step = b.addInstallRaw(elf, "hello.hex", .{});
test_step.dependOn(&hex_step.step);

const explicit_format_hex_step = b.addInstallRawWithFormat(elf, "hello.foo", .hex);
const explicit_format_hex_step = b.addInstallRaw(elf, "hello.foo", .{ .format = .hex });
test_step.dependOn(&explicit_format_hex_step.step);

const expected_hex = &[_][]const u8{
Expand Down