Skip to content

Commit

Permalink
Add panic-strategy to bootstrap config
Browse files Browse the repository at this point in the history
  • Loading branch information
clubby789 committed Jan 9, 2024
1 parent efb3f11 commit 52c907f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
3 changes: 3 additions & 0 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@
# Defaults to rust.overflow-checks value
#overflow-checks-std = rust.overflow-checks (boolean)

# The panic strategy used for all compiler invocations
#panic-strategy = "unwind"

# Debuginfo level for most of Rust code, corresponds to the `-C debuginfo=N` option of `rustc`.
# `0` - no debug info
# `1` - line tables only - sufficient to generate backtraces that include line
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,10 @@ impl<'a> Builder<'a> {
cargo.env("RUSTFLAGS", &rustc_args.join(" "));
}

if matches!(self.config.rust_panic_strategy, crate::PanicStrategy::Abort) {
rustflags.arg("-Cpanic=abort");
}

Cargo { command: cargo, rustflags, rustdocflags, hostflags, allow_features }
}

Expand Down
12 changes: 12 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ impl Display for DebuginfoLevel {
}
}

#[derive(Clone, Copy, Debug, Default, PartialEq, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum PanicStrategy {
#[default]
Unwind,
Abort,
}

/// LLD in bootstrap works like this:
/// - Self-contained lld: use `rust-lld` from the compiler's sysroot
/// - External: use an external `lld` binary
Expand Down Expand Up @@ -272,6 +280,7 @@ pub struct Config {
pub rust_profile_generate: Option<String>,
pub rust_lto: RustcLto,
pub rust_validate_mir_opts: Option<u32>,
pub rust_panic_strategy: PanicStrategy,
pub llvm_profile_use: Option<String>,
pub llvm_profile_generate: bool,
pub llvm_libunwind_default: Option<LlvmLibunwind>,
Expand Down Expand Up @@ -1111,6 +1120,7 @@ define_config! {
download_rustc: Option<StringOrBool> = "download-rustc",
lto: Option<String> = "lto",
validate_mir_opts: Option<u32> = "validate-mir-opts",
panic_strategy: Option<PanicStrategy> = "panic-strategy",
}
}

Expand Down Expand Up @@ -1562,6 +1572,7 @@ impl Config {
stack_protector,
strip,
lld_mode,
panic_strategy,
} = rust;

set(&mut config.channel, channel);
Expand Down Expand Up @@ -1594,6 +1605,7 @@ impl Config {
debuginfo_level_std = debuginfo_level_std_toml;
debuginfo_level_tools = debuginfo_level_tools_toml;
debuginfo_level_tests = debuginfo_level_tests_toml;
set(&mut config.rust_panic_strategy, panic_strategy);

config.rust_split_debuginfo = split_debuginfo
.as_deref()
Expand Down
19 changes: 13 additions & 6 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//! More documentation can be found in each respective module below, and you can
//! also check out the `src/bootstrap/README.md` file for more information.

use core::config::PanicStrategy;
use std::cell::{Cell, RefCell};
use std::collections::{HashMap, HashSet};
use std::env;
Expand Down Expand Up @@ -708,13 +709,19 @@ impl Build {
/// Gets the space-separated set of activated features for the standard
/// library.
fn std_features(&self, target: TargetSelection) -> String {
let mut features = " panic-unwind".to_string();
let mut features = match self.config.rust_panic_strategy {
PanicStrategy::Abort => String::new(),
_ => {
let mut features = " panic-unwind".to_string();
match self.config.llvm_libunwind(target) {
LlvmLibunwind::InTree => features.push_str(" llvm-libunwind"),
LlvmLibunwind::System => features.push_str(" system-llvm-libunwind"),
LlvmLibunwind::No => {}
}
features
}
};

match self.config.llvm_libunwind(target) {
LlvmLibunwind::InTree => features.push_str(" llvm-libunwind"),
LlvmLibunwind::System => features.push_str(" system-llvm-libunwind"),
LlvmLibunwind::No => {}
}
if self.config.backtrace {
features.push_str(" backtrace");
}
Expand Down

0 comments on commit 52c907f

Please sign in to comment.