objcopy: support multiple only sections

This commit is contained in:
binarycraft007 2024-03-01 09:18:33 +08:00 committed by Andrew Kelley
parent 9e402704e2
commit a7a5f4cf4d
2 changed files with 13 additions and 6 deletions

View File

@ -245,6 +245,11 @@ pub const HashHelper = struct {
for (list_of_bytes) |bytes| hh.addBytes(bytes); for (list_of_bytes) |bytes| hh.addBytes(bytes);
} }
pub fn addOptionalListOfBytes(hh: *HashHelper, optional_list_of_bytes: ?[]const []const u8) void {
hh.add(optional_list_of_bytes != null);
hh.addListOfBytes(optional_list_of_bytes orelse return);
}
/// Convert the input value into bytes and record it as a dependency of the process being cached. /// Convert the input value into bytes and record it as a dependency of the process being cached.
pub fn add(hh: *HashHelper, x: anytype) void { pub fn add(hh: *HashHelper, x: anytype) void {
switch (@TypeOf(x)) { switch (@TypeOf(x)) {

View File

@ -33,7 +33,7 @@ output_file: std.Build.GeneratedFile,
output_file_debug: ?std.Build.GeneratedFile, output_file_debug: ?std.Build.GeneratedFile,
format: ?RawFormat, format: ?RawFormat,
only_section: ?[]const u8, only_sections: ?[]const []const u8,
pad_to: ?u64, pad_to: ?u64,
strip: Strip, strip: Strip,
compress_debug: bool, compress_debug: bool,
@ -41,7 +41,7 @@ compress_debug: bool,
pub const Options = struct { pub const Options = struct {
basename: ?[]const u8 = null, basename: ?[]const u8 = null,
format: ?RawFormat = null, format: ?RawFormat = null,
only_section: ?[]const u8 = null, only_sections: ?[]const []const u8 = null,
pad_to: ?u64 = null, pad_to: ?u64 = null,
compress_debug: bool = false, compress_debug: bool = false,
@ -71,7 +71,7 @@ pub fn create(
.output_file = std.Build.GeneratedFile{ .step = &self.step }, .output_file = std.Build.GeneratedFile{ .step = &self.step },
.output_file_debug = if (options.strip != .none and options.extract_to_separate_file) std.Build.GeneratedFile{ .step = &self.step } else null, .output_file_debug = if (options.strip != .none and options.extract_to_separate_file) std.Build.GeneratedFile{ .step = &self.step } else null,
.format = options.format, .format = options.format,
.only_section = options.only_section, .only_sections = options.only_sections,
.pad_to = options.pad_to, .pad_to = options.pad_to,
.strip = options.strip, .strip = options.strip,
.compress_debug = options.compress_debug, .compress_debug = options.compress_debug,
@ -103,7 +103,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
const full_src_path = self.input_file.getPath(b); const full_src_path = self.input_file.getPath(b);
_ = try man.addFile(full_src_path, null); _ = try man.addFile(full_src_path, null);
man.hash.addOptionalBytes(self.only_section); man.hash.addOptionalListOfBytes(self.only_sections);
man.hash.addOptional(self.pad_to); man.hash.addOptional(self.pad_to);
man.hash.addOptional(self.format); man.hash.addOptional(self.format);
man.hash.add(self.compress_debug); man.hash.add(self.compress_debug);
@ -135,8 +135,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
var argv = std.ArrayList([]const u8).init(b.allocator); var argv = std.ArrayList([]const u8).init(b.allocator);
try argv.appendSlice(&.{ b.graph.zig_exe, "objcopy" }); try argv.appendSlice(&.{ b.graph.zig_exe, "objcopy" });
if (self.only_section) |only_section| { if (self.only_sections) |only_sections| {
try argv.appendSlice(&.{ "-j", only_section }); for (only_sections) |only_section| {
try argv.appendSlice(&.{ "-j", only_section });
}
} }
switch (self.strip) { switch (self.strip) {
.none => {}, .none => {},