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 {...@@ -4891,6 +4891,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
4891 var fetch_mode: Package.Fetch.JobQueue.Mode = .needed;4891 var fetch_mode: Package.Fetch.JobQueue.Mode = .needed;
4892 var system_pkg_dir_path: ?[]const u8 = null;4892 var system_pkg_dir_path: ?[]const u8 = null;
4893 var debug_target: ?[]const u8 = null;4893 var debug_target: ?[]const u8 = null;
4894 var debug_libc_paths_file: ?[]const u8 = null;
48944895
4895 const argv_index_exe = child_argv.items.len;4896 const argv_index_exe = child_argv.items.len;
4896 _ = try child_argv.addOne();4897 _ = try child_argv.addOne();
...@@ -5014,6 +5015,14 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -5014,6 +5015,14 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
5014 } else {5015 } else {
5015 warn("Zig was compiled without debug extensions. --debug-target has no effect.", .{});5016 warn("Zig was compiled without debug extensions. --debug-target has no effect.", .{});
5016 }5017 }
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 }
5017 } else if (mem.eql(u8, arg, "--verbose-link")) {5026 } else if (mem.eql(u8, arg, "--verbose-link")) {
5018 verbose_link = true;5027 verbose_link = true;
5019 } else if (mem.eql(u8, arg, "--verbose-cc")) {5028 } else if (mem.eql(u8, arg, "--verbose-cc")) {
...@@ -5101,6 +5110,14 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -5101,6 +5110,14 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
5101 .is_explicit_dynamic_linker = false,5110 .is_explicit_dynamic_linker = false,
5102 };5111 };
5103 };5112 };
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
5105 process.raiseFileDescriptorLimit();5122 process.raiseFileDescriptorLimit();
51065123
...@@ -5365,6 +5382,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -5365,6 +5382,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
5365 }5382 }
53665383
5367 const comp = Compilation.create(gpa, arena, .{5384 const comp = Compilation.create(gpa, arena, .{
5385 .libc_installation = libc_installation,
5368 .dirs = dirs,5386 .dirs = dirs,
5369 .root_name = "build",5387 .root_name = "build",
5370 .config = config,5388 .config = config,