std.Build: add build-id option

This commit is contained in:
Jan200101 2025-01-17 20:53:30 +01:00 committed by Jan
parent 4cefd1bd1b
commit 013a228960
4 changed files with 16 additions and 7 deletions

View file

@ -197,12 +197,6 @@ pub fn build(b: *std.Build) !void {
exe.pie = pie;
exe.entitlements = entitlements;
exe.build_id = b.option(
std.zig.BuildId,
"build-id",
"Request creation of '.note.gnu.build-id' section",
);
if (no_bin) {
b.getInstallStep().dependOn(&exe.step);
} else {

View file

@ -202,6 +202,15 @@ pub fn main() !void {
next_arg, @errorName(err),
});
};
} else if (mem.eql(u8, arg, "--build-id")) {
builder.build_id = .fast;
} else if (mem.startsWith(u8, arg, "--build-id=")) {
const style = arg["--build-id=".len..];
builder.build_id = std.zig.BuildId.parse(style) catch |err| {
fatal("unable to parse --build-id style '{s}': {s}", .{
style, @errorName(err),
});
};
} else if (mem.eql(u8, arg, "--debounce")) {
const next_arg = nextArg(args, &arg_idx) orelse
fatalWithHint("expected u16 after '{s}'", .{arg});
@ -1364,6 +1373,10 @@ fn usage(b: *std.Build, out_stream: anytype) !void {
\\ --zig-lib-dir [arg] Override path to Zig lib directory
\\ --build-runner [file] Override path to build runner
\\ --seed [integer] For shuffling dependency traversal order (default: random)
\\ --build-id[=style] At a minor link-time expense, coordinates stripped binaries
\\ fast, uuid, sha1, md5 with debug symbols via a '.note.gnu.build-id' section
\\ 0x[hexstring] Maximum 32 bytes
\\ none (default) Disable build-id
\\ --debug-log [scope] Enable debugging the compiler
\\ --debug-pkg-config Fail if unknown pkg-config flags encountered
\\ --debug-rt Debug compiler runtime libraries

View file

@ -94,6 +94,8 @@ available_deps: AvailableDeps,
release_mode: ReleaseMode,
build_id: ?std.zig.BuildId = null,
pub const ReleaseMode = enum {
off,
any,

View file

@ -1681,7 +1681,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
try addFlag(&zig_args, "each-lib-rpath", compile.each_lib_rpath);
if (compile.build_id) |build_id| {
if (compile.build_id orelse b.build_id) |build_id| {
try zig_args.append(switch (build_id) {
.hexstring => |hs| b.fmt("--build-id=0x{s}", .{
std.fmt.fmtSliceHexLower(hs.toSlice()),