Skip to content

Commit 52c907f

Browse files
committed
Add panic-strategy to bootstrap config
1 parent efb3f11 commit 52c907f

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

config.example.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@
504504
# Defaults to rust.overflow-checks value
505505
#overflow-checks-std = rust.overflow-checks (boolean)
506506

507+
# The panic strategy used for all compiler invocations
508+
#panic-strategy = "unwind"
509+
507510
# Debuginfo level for most of Rust code, corresponds to the `-C debuginfo=N` option of `rustc`.
508511
# `0` - no debug info
509512
# `1` - line tables only - sufficient to generate backtraces that include line

src/bootstrap/src/core/builder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,6 +2135,10 @@ impl<'a> Builder<'a> {
21352135
cargo.env("RUSTFLAGS", &rustc_args.join(" "));
21362136
}
21372137

2138+
if matches!(self.config.rust_panic_strategy, crate::PanicStrategy::Abort) {
2139+
rustflags.arg("-Cpanic=abort");
2140+
}
2141+
21382142
Cargo { command: cargo, rustflags, rustdocflags, hostflags, allow_features }
21392143
}
21402144

src/bootstrap/src/core/config/config.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ impl Display for DebuginfoLevel {
105105
}
106106
}
107107

108+
#[derive(Clone, Copy, Debug, Default, PartialEq, Deserialize)]
109+
#[serde(rename_all = "lowercase")]
110+
pub enum PanicStrategy {
111+
#[default]
112+
Unwind,
113+
Abort,
114+
}
115+
108116
/// LLD in bootstrap works like this:
109117
/// - Self-contained lld: use `rust-lld` from the compiler's sysroot
110118
/// - External: use an external `lld` binary
@@ -272,6 +280,7 @@ pub struct Config {
272280
pub rust_profile_generate: Option<String>,
273281
pub rust_lto: RustcLto,
274282
pub rust_validate_mir_opts: Option<u32>,
283+
pub rust_panic_strategy: PanicStrategy,
275284
pub llvm_profile_use: Option<String>,
276285
pub llvm_profile_generate: bool,
277286
pub llvm_libunwind_default: Option<LlvmLibunwind>,
@@ -1111,6 +1120,7 @@ define_config! {
11111120
download_rustc: Option<StringOrBool> = "download-rustc",
11121121
lto: Option<String> = "lto",
11131122
validate_mir_opts: Option<u32> = "validate-mir-opts",
1123+
panic_strategy: Option<PanicStrategy> = "panic-strategy",
11141124
}
11151125
}
11161126

@@ -1562,6 +1572,7 @@ impl Config {
15621572
stack_protector,
15631573
strip,
15641574
lld_mode,
1575+
panic_strategy,
15651576
} = rust;
15661577

15671578
set(&mut config.channel, channel);
@@ -1594,6 +1605,7 @@ impl Config {
15941605
debuginfo_level_std = debuginfo_level_std_toml;
15951606
debuginfo_level_tools = debuginfo_level_tools_toml;
15961607
debuginfo_level_tests = debuginfo_level_tests_toml;
1608+
set(&mut config.rust_panic_strategy, panic_strategy);
15971609

15981610
config.rust_split_debuginfo = split_debuginfo
15991611
.as_deref()

src/bootstrap/src/lib.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
//! More documentation can be found in each respective module below, and you can
1717
//! also check out the `src/bootstrap/README.md` file for more information.
1818
19+
use core::config::PanicStrategy;
1920
use std::cell::{Cell, RefCell};
2021
use std::collections::{HashMap, HashSet};
2122
use std::env;
@@ -708,13 +709,19 @@ impl Build {
708709
/// Gets the space-separated set of activated features for the standard
709710
/// library.
710711
fn std_features(&self, target: TargetSelection) -> String {
711-
let mut features = " panic-unwind".to_string();
712+
let mut features = match self.config.rust_panic_strategy {
713+
PanicStrategy::Abort => String::new(),
714+
_ => {
715+
let mut features = " panic-unwind".to_string();
716+
match self.config.llvm_libunwind(target) {
717+
LlvmLibunwind::InTree => features.push_str(" llvm-libunwind"),
718+
LlvmLibunwind::System => features.push_str(" system-llvm-libunwind"),
719+
LlvmLibunwind::No => {}
720+
}
721+
features
722+
}
723+
};
712724

713-
match self.config.llvm_libunwind(target) {
714-
LlvmLibunwind::InTree => features.push_str(" llvm-libunwind"),
715-
LlvmLibunwind::System => features.push_str(" system-llvm-libunwind"),
716-
LlvmLibunwind::No => {}
717-
}
718725
if self.config.backtrace {
719726
features.push_str(" backtrace");
720727
}

0 commit comments

Comments
 (0)