authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-04-11 16:37:46-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-04-11 16:37:46-04:00
log4e700fdf8ed01e7fc856e631ceffd6006e6f48df
tree98a476316d9427be65779edaf6c27468f0e12ccc
parent65bd8d52c8260ad8b5d37285b1d29c1516676c01
parent1a5dcff8e440fab2d7e9bdefe646ba3943fc122a
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #22516 from Jan200101/PR/build_id_option

std.Build: add build-id option

5 files changed, 26 insertions(+), 11 deletions(-)

build.zig-6
......@@ -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+16
......@@ -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+2
......@@ -94,6 +94,8 @@ available_deps: AvailableDeps,
9494
9595release_mode: ReleaseMode,
9696
97build_id: ?std.zig.BuildId = null,
98
9799pub const ReleaseMode = enum {
98100 off,
99101 any,
lib/std/Build/Step/Compile.zig+1-1
......@@ -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+7-4
......@@ -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