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 {...@@ -310,7 +310,11 @@ pub fn main(init: process.Init.Minimal) !void {
310 } else if (mem.eql(u8, arg, "--debug-pkg-config")) {310 } else if (mem.eql(u8, arg, "--debug-pkg-config")) {
311 builder.debug_pkg_config = true;311 builder.debug_pkg_config = true;
312 } else if (mem.eql(u8, arg, "--debug-rt")) {312 } 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});
314 } else if (mem.eql(u8, arg, "--debug-compile-errors")) {318 } else if (mem.eql(u8, arg, "--debug-compile-errors")) {
315 builder.debug_compile_errors = true;319 builder.debug_compile_errors = true;
316 } else if (mem.eql(u8, arg, "--debug-incremental")) {320 } else if (mem.eql(u8, arg, "--debug-incremental")) {
lib/std/Build.zig+1-1
...@@ -115,7 +115,7 @@ pub const Graph = struct {...@@ -115,7 +115,7 @@ pub const Graph = struct {
115 arena: Allocator,115 arena: Allocator,
116 system_library_options: std.StringArrayHashMapUnmanaged(SystemLibraryMode) = .empty,116 system_library_options: std.StringArrayHashMapUnmanaged(SystemLibraryMode) = .empty,
117 system_package_mode: bool = false,117 system_package_mode: bool = false,
118 debug_compiler_runtime_libs: bool = false,118 debug_compiler_runtime_libs: ?std.builtin.OptimizeMode = null,
119 cache: Cache,119 cache: Cache,
120 zig_exe: [:0]const u8,120 zig_exe: [:0]const u8,
121 environ_map: process.Environ.Map,121 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 {...@@ -1462,7 +1462,8 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
1462 try zig_args.append("--global-cache-dir");1462 try zig_args.append("--global-cache-dir");
1463 try zig_args.append(b.graph.global_cache_root.path orelse ".");1463 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
1467 try zig_args.append("--name");1468 try zig_args.append("--name");
1468 try zig_args.append(compile.name);1469 try zig_args.append(compile.name);
src/Compilation.zig+6-5
...@@ -186,7 +186,7 @@ verbose_link: bool,...@@ -186,7 +186,7 @@ verbose_link: bool,
186link_depfile: ?[]const u8,186link_depfile: ?[]const u8,
187disable_c_depfile: bool,187disable_c_depfile: bool,
188stack_report: bool,188stack_report: bool,
189debug_compiler_runtime_libs: bool,189debug_compiler_runtime_libs: ?std.builtin.OptimizeMode,
190debug_compile_errors: bool,190debug_compile_errors: bool,
191/// Do not check this field directly. Instead, use the `debugIncremental` wrapper function.191/// Do not check this field directly. Instead, use the `debugIncremental` wrapper function.
192debug_incremental: bool,192debug_incremental: bool,
...@@ -1749,7 +1749,7 @@ pub const CreateOptions = struct {...@@ -1749,7 +1749,7 @@ pub const CreateOptions = struct {
1749 link_depfile: ?[]const u8 = null,1749 link_depfile: ?[]const u8 = null,
1750 verbose_cimport: bool = false,1750 verbose_cimport: bool = false,
1751 verbose_llvm_cpu_features: bool = false,1751 verbose_llvm_cpu_features: bool = false,
1752 debug_compiler_runtime_libs: bool = false,1752 debug_compiler_runtime_libs: ?std.builtin.OptimizeMode = null,
1753 debug_compile_errors: bool = false,1753 debug_compile_errors: bool = false,
1754 debug_incremental: bool = false,1754 debug_incremental: bool = false,
1755 /// Normally when you create a `Compilation`, Zig will automatically build1755 /// 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,...@@ -2201,7 +2201,8 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
2201 cache.hash.addBytes(options.root_name);2201 cache.hash.addBytes(options.root_name);
2202 cache.hash.add(options.config.wasi_exec_model);2202 cache.hash.add(options.config.wasi_exec_model);
2203 cache.hash.add(options.config.san_cov_trace_pc_guard);2203 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);
2205 // The actual emit paths don't matter. They're only user-specified if we aren't using the2206 // The actual emit paths don't matter. They're only user-specified if we aren't using the
2206 // cache! However, it does matter whether the files are emitted at all.2207 // cache! However, it does matter whether the files are emitted at all.
2207 cache.hash.add(options.emit_bin != .no);2208 cache.hash.add(options.emit_bin != .no);
...@@ -8373,8 +8374,8 @@ pub fn addLinkLib(comp: *Compilation, lib_name: []const u8) !void {...@@ -8373,8 +8374,8 @@ pub fn addLinkLib(comp: *Compilation, lib_name: []const u8) !void {
8373/// This decides the optimization mode for all zig-provided libraries, including8374/// This decides the optimization mode for all zig-provided libraries, including
8374/// compiler-rt, libcxx, libc, libunwind, etc.8375/// compiler-rt, libcxx, libc, libunwind, etc.
8375pub fn compilerRtOptMode(comp: Compilation) std.builtin.OptimizeMode {8376pub fn compilerRtOptMode(comp: Compilation) std.builtin.OptimizeMode {
8376 if (comp.debug_compiler_runtime_libs) {8377 if (comp.debug_compiler_runtime_libs) |mode| {
8377 return .Debug;8378 return mode;
8378 }8379 }
8379 const target = &comp.root_mod.resolved_target.result;8380 const target = &comp.root_mod.resolved_target.result;
8380 switch (comp.root_mod.optimize_mode) {8381 switch (comp.root_mod.optimize_mode) {
src/main.zig+6-3
...@@ -708,7 +708,8 @@ const usage_build_generic =...@@ -708,7 +708,8 @@ const usage_build_generic =
708 \\ --debug-log [scope] Enable printing debug/info log messages for scope708 \\ --debug-log [scope] Enable printing debug/info log messages for scope
709 \\ --debug-compile-errors Crash with helpful diagnostics at the first compile error709 \\ --debug-compile-errors Crash with helpful diagnostics at the first compile error
710 \\ --debug-link-snapshot Enable dumping of the linker's state in JSON format710 \\ --debug-link-snapshot Enable dumping of the linker's state in JSON format
711 \\ --debug-rt Debug compiler runtime libraries711 \\ --debug-rt[=mode] Build compiler runtime libraries with [mode] optimization
712 \\ (Debug if [=mode] is omitted)
712 \\ --debug-incremental Enable incremental compilation debug features713 \\ --debug-incremental Enable incremental compilation debug features
713 \\714 \\
714;715;
...@@ -928,7 +929,7 @@ fn buildOutputType(...@@ -928,7 +929,7 @@ fn buildOutputType(
928 var minor_subsystem_version: ?u16 = null;929 var minor_subsystem_version: ?u16 = null;
929 var mingw_unicode_entry_point: bool = false;930 var mingw_unicode_entry_point: bool = false;
930 var enable_link_snapshots: bool = false;931 var enable_link_snapshots: bool = false;
931 var debug_compiler_runtime_libs = false;932 var debug_compiler_runtime_libs: ?std.builtin.OptimizeMode = null;
932 var install_name: ?[]const u8 = null;933 var install_name: ?[]const u8 = null;
933 var hash_style: link.File.Lld.Elf.HashStyle = .both;934 var hash_style: link.File.Lld.Elf.HashStyle = .both;
934 var entitlements: ?[]const u8 = null;935 var entitlements: ?[]const u8 = null;
...@@ -1382,7 +1383,9 @@ fn buildOutputType(...@@ -1382,7 +1383,9 @@ fn buildOutputType(
1382 enable_link_snapshots = true;1383 enable_link_snapshots = true;
1383 }1384 }
1384 } else if (mem.eql(u8, arg, "--debug-rt")) {1385 } 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);
1386 } else if (mem.eql(u8, arg, "--debug-incremental")) {1389 } else if (mem.eql(u8, arg, "--debug-incremental")) {
1387 if (build_options.enable_debug_extensions) {1390 if (build_options.enable_debug_extensions) {
1388 debug_incremental = true;1391 debug_incremental = true;