From 32a069f909a34b22a2049dca39ef5a1965cba21b Mon Sep 17 00:00:00 2001 From: mlugg Date: Mon, 4 Aug 2025 09:00:41 +0100 Subject: [PATCH 1/2] 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. --- src/main.zig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main.zig b/src/main.zig index 2a143c30ae..e757b58be5 100644 --- a/src/main.zig +++ b/src/main.zig @@ -4891,6 +4891,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { var fetch_mode: Package.Fetch.JobQueue.Mode = .needed; var system_pkg_dir_path: ?[]const u8 = null; var debug_target: ?[]const u8 = null; + var debug_libc_paths_file: ?[]const u8 = null; const argv_index_exe = child_argv.items.len; _ = try child_argv.addOne(); @@ -5014,6 +5015,14 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { } else { warn("Zig was compiled without debug extensions. --debug-target has no effect.", .{}); } + } else if (mem.eql(u8, arg, "--debug-libc")) { + if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg}); + i += 1; + if (build_options.enable_debug_extensions) { + debug_libc_paths_file = args[i]; + } else { + warn("Zig was compiled without debug extensions. --debug-libc has no effect.", .{}); + } } else if (mem.eql(u8, arg, "--verbose-link")) { verbose_link = true; } else if (mem.eql(u8, arg, "--verbose-cc")) { @@ -5101,6 +5110,14 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { .is_explicit_dynamic_linker = false, }; }; + // Likewise, `--debug-libc` allows overriding the libc installation. + const libc_installation: ?*const LibCInstallation = lci: { + const paths_file = debug_libc_paths_file orelse break :lci null; + if (!build_options.enable_debug_extensions) unreachable; + const lci = try arena.create(LibCInstallation); + lci.* = try .parse(arena, paths_file, &resolved_target.result); + break :lci lci; + }; process.raiseFileDescriptorLimit(); @@ -5365,6 +5382,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { } const comp = Compilation.create(gpa, arena, .{ + .libc_installation = libc_installation, .dirs = dirs, .root_name = "build", .config = config, From 422e8d476c4f407abe2915932fc01012682051fe Mon Sep 17 00:00:00 2001 From: mlugg Date: Mon, 4 Aug 2025 09:37:18 +0100 Subject: [PATCH 2/2] build runner: fix FTBFS on targets without `--watch` implementation This was a regression in #24588. I have verified that this patch works by confirming that with the downstream patches SerenityOS apply to the Zig source tree (sans the one working around this regression), I can build the build runner for SerenityOS. Resolves: #24682 --- lib/compiler/build_runner.zig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/compiler/build_runner.zig b/lib/compiler/build_runner.zig index e97b7aa313..f1a0caf47c 100644 --- a/lib/compiler/build_runner.zig +++ b/lib/compiler/build_runner.zig @@ -502,6 +502,9 @@ pub fn main() !void { }; } + // Comptime-known guard to prevent including the logic below when `!Watch.have_impl`. + if (!Watch.have_impl) unreachable; + try w.update(gpa, run.step_stack.keys()); // Wait until a file system notification arrives. Read all such events