authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-08-04 09:00:41+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2025-08-04 09:47:56+01:00
log32a069f909a34b22a2049dca39ef5a1965cba21b
tree65dcaeee21ef8fd226be43e7441ad5f63612a91f
parentdabae3f9dc868af92e7608d897befc39e5db5c33
signaturelock-open Commit is signed but in an unrecognized format.

cli: add `--debug-libc` to `zig build`

This option is similar to `--debug-target` in letting us override details of the build runner target when debugging the build system. While `--debug-target` lets us override the target query, this option lets us override the libc installation. This option is only usable in a compiler built with debug extensions. I am using this to (try to) test the build runner targeting SerenityOS.

1 files changed, 18 insertions(+), 0 deletions(-)

src/main.zig+18
......@@ -4891,6 +4891,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
48914891 var fetch_mode: Package.Fetch.JobQueue.Mode = .needed;
48924892 var system_pkg_dir_path: ?[]const u8 = null;
48934893 var debug_target: ?[]const u8 = null;
4894 var debug_libc_paths_file: ?[]const u8 = null;
48944895
48954896 const argv_index_exe = child_argv.items.len;
48964897 _ = try child_argv.addOne();
......@@ -5014,6 +5015,14 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
50145015 } else {
50155016 warn("Zig was compiled without debug extensions. --debug-target has no effect.", .{});
50165017 }
5018 } else if (mem.eql(u8, arg, "--debug-libc")) {
5019 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
5020 i += 1;
5021 if (build_options.enable_debug_extensions) {
5022 debug_libc_paths_file = args[i];
5023 } else {
5024 warn("Zig was compiled without debug extensions. --debug-libc has no effect.", .{});
5025 }
50175026 } else if (mem.eql(u8, arg, "--verbose-link")) {
50185027 verbose_link = true;
50195028 } else if (mem.eql(u8, arg, "--verbose-cc")) {
......@@ -5101,6 +5110,14 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
51015110 .is_explicit_dynamic_linker = false,
51025111 };
51035112 };
5113 // Likewise, `--debug-libc` allows overriding the libc installation.
5114 const libc_installation: ?*const LibCInstallation = lci: {
5115 const paths_file = debug_libc_paths_file orelse break :lci null;
5116 if (!build_options.enable_debug_extensions) unreachable;
5117 const lci = try arena.create(LibCInstallation);
5118 lci.* = try .parse(arena, paths_file, &resolved_target.result);
5119 break :lci lci;
5120 };
51045121
51055122 process.raiseFileDescriptorLimit();
51065123
......@@ -5365,6 +5382,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
53655382 }
53665383
53675384 const comp = Compilation.create(gpa, arena, .{
5385 .libc_installation = libc_installation,
53685386 .dirs = dirs,
53695387 .root_name = "build",
53705388 .config = config,