Skip to content

Commit 1ed8703

Browse files
committed
std.Build: add build-id option
1 parent 8fa47bb commit 1ed8703

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

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});
@@ -1351,6 +1360,10 @@ fn usage(b: *std.Build, out_stream: anytype) !void {
13511360
\\ --zig-lib-dir [arg] Override path to Zig lib directory
13521361
\\ --build-runner [file] Override path to build runner
13531362
\\ --seed [integer] For shuffling dependency traversal order (default: random)
1363+
\\ --build-id[=style] At a minor link-time expense, coordinates stripped binaries
1364+
\\ fast, uuid, sha1, md5 with debug symbols via a '.note.gnu.build-id' section
1365+
\\ 0x[hexstring] Maximum 32 bytes
1366+
\\ none (default) Disable build-id
13541367
\\ --debug-log [scope] Enable debugging the compiler
13551368
\\ --debug-pkg-config Fail if unknown pkg-config flags encountered
13561369
\\ --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
@@ -1664,7 +1664,7 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
16641664

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

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

0 commit comments

Comments
 (0)