Skip to content

Commit 4e700fd

Browse files
authored
Merge pull request #22516 from Jan200101/PR/build_id_option
std.Build: add build-id option
2 parents 65bd8d5 + 1a5dcff commit 4e700fd

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

build.zig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,6 @@ pub fn build(b: *std.Build) !void {
197197
exe.pie = pie;
198198
exe.entitlements = entitlements;
199199

200-
exe.build_id = b.option(
201-
std.zig.BuildId,
202-
"build-id",
203-
"Request creation of '.note.gnu.build-id' section",
204-
);
205-
206200
if (no_bin) {
207201
b.getInstallStep().dependOn(&exe.step);
208202
} else {

lib/compiler/build_runner.zig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ pub fn main() !void {
202202
next_arg, @errorName(err),
203203
});
204204
};
205+
} else if (mem.eql(u8, arg, "--build-id")) {
206+
builder.build_id = .fast;
207+
} else if (mem.startsWith(u8, arg, "--build-id=")) {
208+
const style = arg["--build-id=".len..];
209+
builder.build_id = std.zig.BuildId.parse(style) catch |err| {
210+
fatal("unable to parse --build-id style '{s}': {s}", .{
211+
style, @errorName(err),
212+
});
213+
};
205214
} else if (mem.eql(u8, arg, "--debounce")) {
206215
const next_arg = nextArg(args, &arg_idx) orelse
207216
fatalWithHint("expected u16 after '{s}'", .{arg});
@@ -1366,6 +1375,13 @@ fn usage(b: *std.Build, out_stream: anytype) !void {
13661375
\\ --zig-lib-dir [arg] Override path to Zig lib directory
13671376
\\ --build-runner [file] Override path to build runner
13681377
\\ --seed [integer] For shuffling dependency traversal order (default: random)
1378+
\\ --build-id[=style] At a minor link-time expense, embeds a build ID in binaries
1379+
\\ fast 8-byte non-cryptographic hash (COFF, ELF, WASM)
1380+
\\ sha1, tree 20-byte cryptographic hash (ELF, WASM)
1381+
\\ md5 16-byte cryptographic hash (ELF)
1382+
\\ uuid 16-byte random UUID (ELF, WASM)
1383+
\\ 0x[hexstring] Constant ID, maximum 32 bytes (ELF, WASM)
1384+
\\ none (default) No build ID
13691385
\\ --debug-log [scope] Enable debugging the compiler
13701386
\\ --debug-pkg-config Fail if unknown pkg-config flags encountered
13711387
\\ --debug-rt Debug compiler runtime libraries

lib/std/Build.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ available_deps: AvailableDeps,
9494

9595
release_mode: ReleaseMode,
9696

97+
build_id: ?std.zig.BuildId = null,
98+
9799
pub const ReleaseMode = enum {
98100
off,
99101
any,

lib/std/Build/Step/Compile.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
16941694

16951695
try addFlag(&zig_args, "each-lib-rpath", compile.each_lib_rpath);
16961696

1697-
if (compile.build_id) |build_id| {
1697+
if (compile.build_id orelse b.build_id) |build_id| {
16981698
try zig_args.append(switch (build_id) {
16991699
.hexstring => |hs| b.fmt("--build-id=0x{s}", .{
17001700
std.fmt.fmtSliceHexLower(hs.toSlice()),

src/main.zig

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,13 @@ const usage_build_generic =
580580
\\ -fno-allow-shlib-undefined Disallows undefined symbols in shared libraries
581581
\\ -fallow-so-scripts Allows .so files to be GNU ld scripts
582582
\\ -fno-allow-so-scripts (default) .so files must be ELF files
583-
\\ --build-id[=style] At a minor link-time expense, coordinates stripped binaries
584-
\\ fast, uuid, sha1, md5 with debug symbols via a '.note.gnu.build-id' section
585-
\\ 0x[hexstring] Maximum 32 bytes
586-
\\ none (default) Disable build-id
583+
\\ --build-id[=style] At a minor link-time expense, embeds a build ID in binaries
584+
\\ fast 8-byte non-cryptographic hash (COFF, ELF, WASM)
585+
\\ sha1, tree 20-byte cryptographic hash (ELF, WASM)
586+
\\ md5 16-byte cryptographic hash (ELF)
587+
\\ uuid 16-byte random UUID (ELF, WASM)
588+
\\ 0x[hexstring] Constant ID, maximum 32 bytes (ELF, WASM)
589+
\\ none (default) No build ID
587590
\\ --eh-frame-hdr Enable C++ exception handling by passing --eh-frame-hdr to linker
588591
\\ --no-eh-frame-hdr Disable C++ exception handling by passing --no-eh-frame-hdr to linker
589592
\\ --emit-relocs Enable output of relocation sections for post build tools

0 commit comments

Comments
 (0)