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 {...@@ -197,12 +197,6 @@ pub fn build(b: *std.Build) !void {
197 exe.pie = pie;197 exe.pie = pie;
198 exe.entitlements = entitlements;198 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
206 if (no_bin) {200 if (no_bin) {
207 b.getInstallStep().dependOn(&exe.step);201 b.getInstallStep().dependOn(&exe.step);
208 } else {202 } else {
lib/compiler/build_runner.zig+16
...@@ -202,6 +202,15 @@ pub fn main() !void {...@@ -202,6 +202,15 @@ pub fn main() !void {
202 next_arg, @errorName(err),202 next_arg, @errorName(err),
203 });203 });
204 };204 };
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 };
205 } else if (mem.eql(u8, arg, "--debounce")) {214 } else if (mem.eql(u8, arg, "--debounce")) {
206 const next_arg = nextArg(args, &arg_idx) orelse215 const next_arg = nextArg(args, &arg_idx) orelse
207 fatalWithHint("expected u16 after '{s}'", .{arg});216 fatalWithHint("expected u16 after '{s}'", .{arg});
...@@ -1366,6 +1375,13 @@ fn usage(b: *std.Build, out_stream: anytype) !void {...@@ -1366,6 +1375,13 @@ fn usage(b: *std.Build, out_stream: anytype) !void {
1366 \\ --zig-lib-dir [arg] Override path to Zig lib directory1375 \\ --zig-lib-dir [arg] Override path to Zig lib directory
1367 \\ --build-runner [file] Override path to build runner1376 \\ --build-runner [file] Override path to build runner
1368 \\ --seed [integer] For shuffling dependency traversal order (default: random)1377 \\ --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
1369 \\ --debug-log [scope] Enable debugging the compiler1385 \\ --debug-log [scope] Enable debugging the compiler
1370 \\ --debug-pkg-config Fail if unknown pkg-config flags encountered1386 \\ --debug-pkg-config Fail if unknown pkg-config flags encountered
1371 \\ --debug-rt Debug compiler runtime libraries1387 \\ --debug-rt Debug compiler runtime libraries
lib/std/Build.zig+2
...@@ -94,6 +94,8 @@ available_deps: AvailableDeps,...@@ -94,6 +94,8 @@ available_deps: AvailableDeps,
9494
95release_mode: ReleaseMode,95release_mode: ReleaseMode,
9696
97build_id: ?std.zig.BuildId = null,
98
97pub const ReleaseMode = enum {99pub const ReleaseMode = enum {
98 off,100 off,
99 any,101 any,
lib/std/Build/Step/Compile.zig+1-1
...@@ -1694,7 +1694,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {...@@ -1694,7 +1694,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
16941694
1695 try addFlag(&zig_args, "each-lib-rpath", compile.each_lib_rpath);1695 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| {
1698 try zig_args.append(switch (build_id) {1698 try zig_args.append(switch (build_id) {
1699 .hexstring => |hs| b.fmt("--build-id=0x{s}", .{1699 .hexstring => |hs| b.fmt("--build-id=0x{s}", .{
1700 std.fmt.fmtSliceHexLower(hs.toSlice()),1700 std.fmt.fmtSliceHexLower(hs.toSlice()),
src/main.zig+7-4
...@@ -580,10 +580,13 @@ const usage_build_generic =...@@ -580,10 +580,13 @@ const usage_build_generic =
580 \\ -fno-allow-shlib-undefined Disallows undefined symbols in shared libraries580 \\ -fno-allow-shlib-undefined Disallows undefined symbols in shared libraries
581 \\ -fallow-so-scripts Allows .so files to be GNU ld scripts581 \\ -fallow-so-scripts Allows .so files to be GNU ld scripts
582 \\ -fno-allow-so-scripts (default) .so files must be ELF files582 \\ -fno-allow-so-scripts (default) .so files must be ELF files
583 \\ --build-id[=style] At a minor link-time expense, coordinates stripped binaries583 \\ --build-id[=style] At a minor link-time expense, embeds a build ID in binaries
584 \\ fast, uuid, sha1, md5 with debug symbols via a '.note.gnu.build-id' section584 \\ fast 8-byte non-cryptographic hash (COFF, ELF, WASM)
585 \\ 0x[hexstring] Maximum 32 bytes585 \\ sha1, tree 20-byte cryptographic hash (ELF, WASM)
586 \\ none (default) Disable build-id586 \\ 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
587 \\ --eh-frame-hdr Enable C++ exception handling by passing --eh-frame-hdr to linker590 \\ --eh-frame-hdr Enable C++ exception handling by passing --eh-frame-hdr to linker
588 \\ --no-eh-frame-hdr Disable C++ exception handling by passing --no-eh-frame-hdr to linker591 \\ --no-eh-frame-hdr Disable C++ exception handling by passing --no-eh-frame-hdr to linker
589 \\ --emit-relocs Enable output of relocation sections for post build tools592 \\ --emit-relocs Enable output of relocation sections for post build tools