introduce ZIG_DEBUG_CMD to choose debug mode

for lazily built commands such as `zig fmt` and `zig reduce`. Useful if
you want to test a patch to them.
This commit is contained in:
Andrew Kelley 2024-02-26 23:48:56 -07:00
parent 1a01151a4e
commit 97f2a8b5cb
2 changed files with 7 additions and 2 deletions

View File

@ -153,6 +153,7 @@ pub const EnvVar = enum {
ZIG_VERBOSE_LINK,
ZIG_VERBOSE_CC,
ZIG_BTRFS_WORKAROUND,
ZIG_DEBUG_CMD,
CC,
NO_COLOR,
XDG_CACHE_HOME,

View File

@ -5735,6 +5735,10 @@ fn jitCmd(
fatal("unable to find self exe path: {s}", .{@errorName(err)});
};
const optimize_mode: std.builtin.OptimizeMode = if (EnvVar.ZIG_DEBUG_CMD.isSet())
.Debug
else
.ReleaseFast;
const override_lib_dir: ?[]const u8 = try EnvVar.ZIG_LIB_DIR.get(arena);
const override_global_cache_dir: ?[]const u8 = try EnvVar.ZIG_GLOBAL_CACHE_DIR.get(arena);
@ -5777,7 +5781,7 @@ fn jitCmd(
const config = try Compilation.Config.resolve(.{
.output_mode = .Exe,
.root_optimize_mode = .ReleaseFast,
.root_optimize_mode = optimize_mode,
.resolved_target = resolved_target,
.have_zcu = true,
.emit_bin = true,
@ -5791,7 +5795,7 @@ fn jitCmd(
.cc_argv = &.{},
.inherited = .{
.resolved_target = resolved_target,
.optimize_mode = .ReleaseFast,
.optimize_mode = optimize_mode,
},
.global = config,
.parent = null,