Skip to content

Commit 013a228

Browse files
committed
std.Build: add build-id option
1 parent 4cefd1b commit 013a228

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
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: 13 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});
@@ -1364,6 +1373,10 @@ fn usage(b: *std.Build, out_stream: anytype) !void {
13641373
\\ --zig-lib-dir [arg] Override path to Zig lib directory
13651374
\\ --build-runner [file] Override path to build runner
13661375
\\ --seed [integer] For shuffling dependency traversal order (default: random)
1376+
\\ --build-id[=style] At a minor link-time expense, coordinates stripped binaries
1377+
\\ fast, uuid, sha1, md5 with debug symbols via a '.note.gnu.build-id' section
1378+
\\ 0x[hexstring] Maximum 32 bytes
1379+
\\ none (default) Disable build-id
13671380
\\ --debug-log [scope] Enable debugging the compiler
13681381
\\ --debug-pkg-config Fail if unknown pkg-config flags encountered
13691382
\\ --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
@@ -1681,7 +1681,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
16811681

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

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

0 commit comments

Comments
 (0)