diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 475f2e904639c..1ec331a7bf130 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -94,6 +94,11 @@ fn main() { // other crate intentionally as this is the only crate for now that we // ship with panic=abort. // + // FIXME: Remove the special case for "panic_abort" + // once https://github.com/rust-lang/rust/pull/60026 + // rides the release train into the bootstrap compiler. + // `cfg(bootstrap)`: (added to make this easier to grep for) + // // This... is a bit of a hack how we detect this. Ideally this // information should be encoded in the crate I guess? Would likely // require an RFC amendment to RFC 1513, however. diff --git a/src/libpanic_abort/build.rs b/src/libpanic_abort/build.rs new file mode 100644 index 0000000000000..0181c09c74573 --- /dev/null +++ b/src/libpanic_abort/build.rs @@ -0,0 +1,7 @@ +fn main() { + // Hack to force this crate to be compiled with the `abort` + // panic strategy, regardless of what strategy Cargo + // passes to the compiler. + // See `rustc::session::Session::panic_strategy` for more details + println!("cargo:rustc-env=RUSTC_INTERNAL_FORCE_PANIC_ABORT=1"); +} diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 92e8e92d02a74..312a60e141855 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -563,6 +563,18 @@ impl Session { /// Returns the panic strategy for this compile session. If the user explicitly selected one /// using '-C panic', use that, otherwise use the panic strategy defined by the target. pub fn panic_strategy(&self) -> PanicStrategy { + // This is a hack to support `libpanic_abort`. We require `libpanic_abort` + // to always be built with `PanicStrategy::Abort`, regardless of what panic + // strategy is suppplied to the compiler. Ideally, this would be an intenral + // attribute in `libpanic_abort` - howevver, emscripten needs to access + // the panic strategy before we even start parsing the crate: + // https://github.com/rust-lang/rust/blob/3fc30d8/src/librustc_codegen_llvm/llvm_util.rs#L77 + // + // As a result, we need to use a special environment variable, which is set from + // the `build.rs` of `libpanic_abort` + if env::var("RUSTC_INTERNAL_FORCE_PANIC_ABORT").is_ok() { + return PanicStrategy::Abort; + } self.opts .cg .panic