Skip to content

Commit

Permalink
bootstrap: add std_features config to rust section
Browse files Browse the repository at this point in the history
  • Loading branch information
shrirambalaji committed Sep 11, 2024
1 parent 7b18b3e commit fa07dcf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ pub struct Config {
pub rust_profile_generate: Option<String>,
pub rust_lto: RustcLto,
pub rust_validate_mir_opts: Option<u32>,
pub rust_std_features: Option<Vec<String>>,
pub llvm_profile_use: Option<String>,
pub llvm_profile_generate: bool,
pub llvm_libunwind_default: Option<LlvmLibunwind>,
Expand Down Expand Up @@ -1141,6 +1142,7 @@ define_config! {
download_rustc: Option<StringOrBool> = "download-rustc",
lto: Option<String> = "lto",
validate_mir_opts: Option<u32> = "validate-mir-opts",
std_features: Option<Vec<String>> = "std_features",
}
}

Expand Down Expand Up @@ -1621,6 +1623,7 @@ impl Config {
let mut optimize = None;
let mut omit_git_hash = None;
let mut lld_enabled = None;
let mut std_features = None;

let mut is_user_configured_rust_channel = false;

Expand Down Expand Up @@ -1679,6 +1682,7 @@ impl Config {
stack_protector,
strip,
lld_mode,
std_features: std_features_toml,
} = rust;

is_user_configured_rust_channel = channel.is_some();
Expand All @@ -1698,6 +1702,7 @@ impl Config {
debuginfo_level_tools = debuginfo_level_tools_toml;
debuginfo_level_tests = debuginfo_level_tests_toml;
lld_enabled = lld_enabled_toml;
std_features = std_features_toml;

optimize = optimize_toml;
omit_git_hash = omit_git_hash_toml;
Expand Down Expand Up @@ -2103,6 +2108,9 @@ impl Config {
);
}

// std_features chosen during bootstrap
config.rust_std_features = std_features;

let default = debug == Some(true);
config.rust_debug_assertions = debug_assertions.unwrap_or(default);
config.rust_debug_assertions_std =
Expand Down Expand Up @@ -2949,6 +2957,7 @@ fn check_incompatible_options_for_ci_rustc(
download_rustc: _,
validate_mir_opts: _,
frame_pointers: _,
std_features: _,
} = ci_rust_config;

// There are two kinds of checks for CI rustc incompatible options:
Expand Down
26 changes: 18 additions & 8 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,27 +655,37 @@ impl Build {
}

/// Gets the space-separated set of activated features for the standard
/// library.
/// library. This can be configured with the `std_features` key in config.toml.
fn std_features(&self, target: TargetSelection) -> String {
let mut features = " panic-unwind".to_string();
let mut features = if let Some(features) = &self.config.rust_std_features {
features.iter().map(|s| s.as_ref()).collect::<Vec<&str>>()
} else {
vec![]
};

if !features.contains(&"panic-unwind") {
features.push("panic-unwind");
}

match self.config.llvm_libunwind(target) {
LlvmLibunwind::InTree => features.push_str(" llvm-libunwind"),
LlvmLibunwind::System => features.push_str(" system-llvm-libunwind"),
LlvmLibunwind::InTree => features.push("llvm-libunwind"),
LlvmLibunwind::System => features.push("system-llvm-libunwind"),
LlvmLibunwind::No => {}
}
if self.config.backtrace {
features.push_str(" backtrace");
features.push("backtrace");
}
if self.config.profiler_enabled(target) {
features.push_str(" profiler");
features.push("profiler");
}
// Generate memcpy, etc. FIXME: Remove this once compiler-builtins
// automatically detects this target.
if target.contains("zkvm") {
features.push_str(" compiler-builtins-mem");
features.push("compiler-builtins-mem");
}
features

// remove duplicates
features.into_iter().collect::<HashSet<_>>().into_iter().collect::<Vec<_>>().join(" ")
}

/// Gets the space-separated set of activated features for the compiler.
Expand Down

0 comments on commit fa07dcf

Please sign in to comment.