authorgravatar for goon.pri.low@gmail.comKendall Condon <goon.pri.low@gmail.com> 2025-11-23 13:54:13-05:00
committergravatar for goon.pri.low@gmail.comKendall Condon <goon.pri.low@gmail.com> 2026-02-13 17:58:09-05:00
loge40557b1f75863d9a66af301e83c8c48f0df81d5
treea3b80f2f47add44dec6abbaa22b5083074a341c8
parent1a9d75ebe0037bd908ed263bb7f4228f9a8681ef

allow specifying mode in --debug-rt

The motivation is that libfuzzer is slow in Debug mode and bugs usually manifest late into fuzzing, which makes testing it in ReleaseSafe useful.

5 files changed, 20 insertions(+), 11 deletions(-)

lib/compiler/build_runner.zig+5-1
......@@ -310,7 +310,11 @@ pub fn main(init: process.Init.Minimal) !void {
310310 } else if (mem.eql(u8, arg, "--debug-pkg-config")) {
311311 builder.debug_pkg_config = true;
312312 } else if (mem.eql(u8, arg, "--debug-rt")) {
313 graph.debug_compiler_runtime_libs = true;
313 graph.debug_compiler_runtime_libs = .Debug;
314 } else if (mem.cutPrefix(u8, arg, "--debug-rt=")) |rest| {
315 graph.debug_compiler_runtime_libs =
316 std.meta.stringToEnum(std.builtin.OptimizeMode, rest) orelse
317 fatal("unrecognized optimization mode: '{s}'", .{rest});
314318 } else if (mem.eql(u8, arg, "--debug-compile-errors")) {
315319 builder.debug_compile_errors = true;
316320 } else if (mem.eql(u8, arg, "--debug-incremental")) {
lib/std/Build.zig+1-1
......@@ -115,7 +115,7 @@ pub const Graph = struct {
115115 arena: Allocator,
116116 system_library_options: std.StringArrayHashMapUnmanaged(SystemLibraryMode) = .empty,
117117 system_package_mode: bool = false,
118 debug_compiler_runtime_libs: bool = false,
118 debug_compiler_runtime_libs: ?std.builtin.OptimizeMode = null,
119119 cache: Cache,
120120 zig_exe: [:0]const u8,
121121 environ_map: process.Environ.Map,
lib/std/Build/Step/Compile.zig+2-1
......@@ -1462,7 +1462,8 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
14621462 try zig_args.append("--global-cache-dir");
14631463 try zig_args.append(b.graph.global_cache_root.path orelse ".");
14641464
1465 if (b.graph.debug_compiler_runtime_libs) try zig_args.append("--debug-rt");
1465 if (b.graph.debug_compiler_runtime_libs) |mode|
1466 try zig_args.append(b.fmt("--debug-rt={t}", .{mode}));
14661467
14671468 try zig_args.append("--name");
14681469 try zig_args.append(compile.name);
src/Compilation.zig+6-5
......@@ -186,7 +186,7 @@ verbose_link: bool,
186186link_depfile: ?[]const u8,
187187disable_c_depfile: bool,
188188stack_report: bool,
189debug_compiler_runtime_libs: bool,
189debug_compiler_runtime_libs: ?std.builtin.OptimizeMode,
190190debug_compile_errors: bool,
191191/// Do not check this field directly. Instead, use the `debugIncremental` wrapper function.
192192debug_incremental: bool,
......@@ -1749,7 +1749,7 @@ pub const CreateOptions = struct {
17491749 link_depfile: ?[]const u8 = null,
17501750 verbose_cimport: bool = false,
17511751 verbose_llvm_cpu_features: bool = false,
1752 debug_compiler_runtime_libs: bool = false,
1752 debug_compiler_runtime_libs: ?std.builtin.OptimizeMode = null,
17531753 debug_compile_errors: bool = false,
17541754 debug_incremental: bool = false,
17551755 /// Normally when you create a `Compilation`, Zig will automatically build
......@@ -2201,7 +2201,8 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
22012201 cache.hash.addBytes(options.root_name);
22022202 cache.hash.add(options.config.wasi_exec_model);
22032203 cache.hash.add(options.config.san_cov_trace_pc_guard);
2204 cache.hash.add(options.debug_compiler_runtime_libs);
2204 cache.hash.add(options.debug_compiler_runtime_libs != null);
2205 if (options.debug_compiler_runtime_libs) |mode| cache.hash.add(mode);
22052206 // The actual emit paths don't matter. They're only user-specified if we aren't using the
22062207 // cache! However, it does matter whether the files are emitted at all.
22072208 cache.hash.add(options.emit_bin != .no);
......@@ -8373,8 +8374,8 @@ pub fn addLinkLib(comp: *Compilation, lib_name: []const u8) !void {
83738374/// This decides the optimization mode for all zig-provided libraries, including
83748375/// compiler-rt, libcxx, libc, libunwind, etc.
83758376pub fn compilerRtOptMode(comp: Compilation) std.builtin.OptimizeMode {
8376 if (comp.debug_compiler_runtime_libs) {
8377 return .Debug;
8377 if (comp.debug_compiler_runtime_libs) |mode| {
8378 return mode;
83788379 }
83798380 const target = &comp.root_mod.resolved_target.result;
83808381 switch (comp.root_mod.optimize_mode) {
src/main.zig+6-3
......@@ -708,7 +708,8 @@ const usage_build_generic =
708708 \\ --debug-log [scope] Enable printing debug/info log messages for scope
709709 \\ --debug-compile-errors Crash with helpful diagnostics at the first compile error
710710 \\ --debug-link-snapshot Enable dumping of the linker's state in JSON format
711 \\ --debug-rt Debug compiler runtime libraries
711 \\ --debug-rt[=mode] Build compiler runtime libraries with [mode] optimization
712 \\ (Debug if [=mode] is omitted)
712713 \\ --debug-incremental Enable incremental compilation debug features
713714 \\
714715;
......@@ -928,7 +929,7 @@ fn buildOutputType(
928929 var minor_subsystem_version: ?u16 = null;
929930 var mingw_unicode_entry_point: bool = false;
930931 var enable_link_snapshots: bool = false;
931 var debug_compiler_runtime_libs = false;
932 var debug_compiler_runtime_libs: ?std.builtin.OptimizeMode = null;
932933 var install_name: ?[]const u8 = null;
933934 var hash_style: link.File.Lld.Elf.HashStyle = .both;
934935 var entitlements: ?[]const u8 = null;
......@@ -1382,7 +1383,9 @@ fn buildOutputType(
13821383 enable_link_snapshots = true;
13831384 }
13841385 } else if (mem.eql(u8, arg, "--debug-rt")) {
1385 debug_compiler_runtime_libs = true;
1386 debug_compiler_runtime_libs = .Debug;
1387 } else if (mem.cutPrefix(u8, arg, "--debug-rt=")) |rest| {
1388 debug_compiler_runtime_libs = parseOptimizeMode(rest);
13861389 } else if (mem.eql(u8, arg, "--debug-incremental")) {
13871390 if (build_options.enable_debug_extensions) {
13881391 debug_incremental = true;