From 013a22896015619e23858ae3fbfc92317af574eb Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Fri, 17 Jan 2025 20:53:30 +0100 Subject: [PATCH 1/2] std.Build: add build-id option --- build.zig | 6 ------ lib/compiler/build_runner.zig | 13 +++++++++++++ lib/std/Build.zig | 2 ++ lib/std/Build/Step/Compile.zig | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/build.zig b/build.zig index 9a52a35275feab67667bcbf9de540ef633d874a4..ebe9899a8f0a2e51472592ac5bd4fcc13e9e134a 100644 --- a/build.zig +++ b/build.zig @@ -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 { diff --git a/lib/compiler/build_runner.zig b/lib/compiler/build_runner.zig index 8702acb329779b504b9b5623deee4663195ae590..81393610be16746ca6822a1ba02999a4ed972914 100644 --- a/lib/compiler/build_runner.zig +++ b/lib/compiler/build_runner.zig @@ -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 diff --git a/lib/std/Build.zig b/lib/std/Build.zig index 4afdcd2bff8c03dc2fe060b0509e054ed730ae73..d31d9f3ee071d9a3765ff513c4012ba1a32fa5f3 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -94,6 +94,8 @@ available_deps: AvailableDeps, release_mode: ReleaseMode, +build_id: ?std.zig.BuildId = null, + pub const ReleaseMode = enum { off, any, diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 616e8f76b450bbe77aebcda3c4bfaa95c3e6ee3a..f70410f612da8c5d806f9c502a4c35fe35429b03 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -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()), -- 2.54.0 From 1a5dcff8e440fab2d7e9bdefe646ba3943fc122a Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Sat, 5 Apr 2025 22:11:07 +0200 Subject: [PATCH 2/2] std.Build: update build-id flag description it now denotes: - all supported styles - what a given style outputs - what formats a given style supports --- lib/compiler/build_runner.zig | 11 +++++++---- src/main.zig | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/compiler/build_runner.zig b/lib/compiler/build_runner.zig index 81393610be16746ca6822a1ba02999a4ed972914..913572129f2f48e80e1a67f3e45edb9c992845ba 100644 --- a/lib/compiler/build_runner.zig +++ b/lib/compiler/build_runner.zig @@ -1373,10 +1373,13 @@ 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 + \\ --build-id[=style] At a minor link-time expense, embeds a build ID in binaries + \\ fast 8-byte non-cryptographic hash (COFF, ELF, WASM) + \\ sha1, tree 20-byte cryptographic hash (ELF, WASM) + \\ md5 16-byte cryptographic hash (ELF) + \\ uuid 16-byte random UUID (ELF, WASM) + \\ 0x[hexstring] Constant ID, maximum 32 bytes (ELF, WASM) + \\ none (default) No 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 diff --git a/src/main.zig b/src/main.zig index 1075993846b857d43bf11838c1591294b8890a0d..88206ef89a68dbb54731bc6b120ec127b3c0743b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -570,10 +570,13 @@ const usage_build_generic = \\ -fno-allow-shlib-undefined Disallows undefined symbols in shared libraries \\ -fallow-so-scripts Allows .so files to be GNU ld scripts \\ -fno-allow-so-scripts (default) .so files must be ELF files - \\ --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 + \\ --build-id[=style] At a minor link-time expense, embeds a build ID in binaries + \\ fast 8-byte non-cryptographic hash (COFF, ELF, WASM) + \\ sha1, tree 20-byte cryptographic hash (ELF, WASM) + \\ md5 16-byte cryptographic hash (ELF) + \\ uuid 16-byte random UUID (ELF, WASM) + \\ 0x[hexstring] Constant ID, maximum 32 bytes (ELF, WASM) + \\ none (default) No build ID \\ --eh-frame-hdr Enable C++ exception handling by passing --eh-frame-hdr to linker \\ --no-eh-frame-hdr Disable C++ exception handling by passing --no-eh-frame-hdr to linker \\ --emit-relocs Enable output of relocation sections for post build tools -- 2.54.0