Skip to content

Commit 7e58a46

Browse files
committed
Make rustc implicitly use panic=abort for the panic_abort crate
The panic_abort crate must be compiled with panic=abort, but cargo doesn't allow setting the panic strategy for a single crate. Bootstrap handles this in its rustc wrapper, but for example the build systems of cg_clif and cg_gcc don't use a rustc wrapper, so they would either need to add one or be unable to build a sysroot suitable for both panic=abort and panic=unwind (as is currently the case).
1 parent 86d0aef commit 7e58a46

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

compiler/rustc_session/src/session.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,11 @@ impl Session {
693693
/// Returns the panic strategy for this compile session. If the user explicitly selected one
694694
/// using '-C panic', use that, otherwise use the panic strategy defined by the target.
695695
pub fn panic_strategy(&self) -> PanicStrategy {
696+
if self.opts.crate_name.as_deref() == Some("panic_abort") {
697+
// The panic_abort crate must always be compiled with panic=abort.
698+
return PanicStrategy::Abort;
699+
}
700+
696701
self.opts.cg.panic.unwrap_or(self.target.panic_strategy)
697702
}
698703

src/bootstrap/src/bin/rustc.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,6 @@ fn main() {
151151
cmd.arg("--sysroot").arg(&sysroot);
152152
}
153153

154-
// If we're compiling specifically the `panic_abort` crate then we pass
155-
// the `-C panic=abort` option. Note that we do not do this for any
156-
// other crate intentionally as this is the only crate for now that we
157-
// ship with panic=abort.
158-
//
159-
// This... is a bit of a hack how we detect this. Ideally this
160-
// information should be encoded in the crate I guess? Would likely
161-
// require an RFC amendment to RFC 1513, however.
162-
if crate_name == Some("panic_abort") {
163-
cmd.arg("-C").arg("panic=abort");
164-
}
165-
166154
let crate_type = parse_value_from_args(&orig_args, "--crate-type");
167155
// `-Ztls-model=initial-exec` must not be applied to proc-macros, see
168156
// issue https://github.com/rust-lang/rust/issues/100530

0 commit comments

Comments
 (0)