Skip to content

Commit cf305ca

Browse files
committed
Fix incorrect NDEBUG handling in LLVM bindings
We currently compile our LLVM bindings using `-DNDEBUG` if debuginfo for LLVM is disabled. However, `NDEBUG` doesn't have any relation to debuginfo, it controls whether assertions are enabled. Split the LLVM_NDEBUG environment variable into two, so that assertions and debuginfo are controlled independently.
1 parent 0fdfb61 commit cf305ca

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

compiler/rustc_llvm/build.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,11 @@ fn main() {
197197
cfg.define("LLVM_RUSTLLVM", None);
198198
}
199199

200-
if tracked_env_var_os("LLVM_NDEBUG").is_some() {
200+
if tracked_env_var_os("LLVM_ASSERTIONS").is_none() {
201201
cfg.define("NDEBUG", None);
202+
}
203+
204+
if tracked_env_var_os("LLVM_NO_DEBUGINFO").is_some() {
202205
cfg.debug(false);
203206
}
204207

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,8 +1213,11 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
12131213
if builder.config.llvm_use_libcxx {
12141214
cargo.env("LLVM_USE_LIBCXX", "1");
12151215
}
1216+
if builder.config.llvm_assertions {
1217+
cargo.env("LLVM_ASSERTIONS", "1");
1218+
}
12161219
if builder.config.llvm_optimize && !builder.config.llvm_release_debuginfo {
1217-
cargo.env("LLVM_NDEBUG", "1");
1220+
cargo.env("LLVM_NO_DEBUGINFO", "1");
12181221
}
12191222
}
12201223

0 commit comments

Comments
 (0)