mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Rollup merge of #131315 - shrirambalaji:issue-129599-fix-shrirambalaji, r=onur-ozkan
bootstrap: add `std_features` config Adding support for a std-features config under the rust section in config.toml during bootstrap. This allows rustc devs to build with specific feature flags for local development.
This commit is contained in:
commit
3c4bc7d763
@ -759,6 +759,16 @@
|
||||
# Build compiler with the optimization enabled and -Zvalidate-mir, currently only for `std`
|
||||
#validate-mir-opts = 3
|
||||
|
||||
# Configure `std` features used during bootstrap.
|
||||
# Default features will be expanded in the following cases:
|
||||
# - If `rust.llvm-libunwind` or `target.llvm-libunwind` is enabled:
|
||||
# - "llvm-libunwind" will be added for in-tree LLVM builds.
|
||||
# - "system-llvm-libunwind" will be added for system LLVM builds.
|
||||
# - If `rust.backtrace` is enabled, "backtrace" will be added.
|
||||
# - If `rust.profiler` or `target.profiler` is enabled, "profiler" will be added.
|
||||
# - If building for a zkvm target, "compiler-builtins-mem" will be added.
|
||||
#std-features = ["panic_unwind"]
|
||||
|
||||
# =============================================================================
|
||||
# Options for specific targets
|
||||
#
|
||||
|
@ -4,7 +4,7 @@
|
||||
//! how the build runs.
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::collections::{BTreeSet, HashMap, HashSet};
|
||||
use std::fmt::{self, Display};
|
||||
use std::io::IsTerminal;
|
||||
use std::path::{Path, PathBuf, absolute};
|
||||
@ -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: BTreeSet<String>,
|
||||
pub llvm_profile_use: Option<String>,
|
||||
pub llvm_profile_generate: bool,
|
||||
pub llvm_libunwind_default: Option<LlvmLibunwind>,
|
||||
@ -1152,6 +1153,7 @@ define_config! {
|
||||
download_rustc: Option<StringOrBool> = "download-rustc",
|
||||
lto: Option<String> = "lto",
|
||||
validate_mir_opts: Option<u32> = "validate-mir-opts",
|
||||
std_features: Option<BTreeSet<String>> = "std-features",
|
||||
}
|
||||
}
|
||||
|
||||
@ -1645,6 +1647,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;
|
||||
|
||||
@ -1703,6 +1706,7 @@ impl Config {
|
||||
stack_protector,
|
||||
strip,
|
||||
lld_mode,
|
||||
std_features: std_features_toml,
|
||||
} = rust;
|
||||
|
||||
is_user_configured_rust_channel = channel.is_some();
|
||||
@ -1722,6 +1726,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;
|
||||
@ -2118,6 +2123,9 @@ impl Config {
|
||||
);
|
||||
}
|
||||
|
||||
let default_std_features = BTreeSet::from([String::from("panic-unwind")]);
|
||||
config.rust_std_features = std_features.unwrap_or(default_std_features);
|
||||
|
||||
let default = debug == Some(true);
|
||||
config.rust_debug_assertions = debug_assertions.unwrap_or(default);
|
||||
config.rust_debug_assertions_std =
|
||||
@ -3016,6 +3024,7 @@ fn check_incompatible_options_for_ci_rustc(
|
||||
description,
|
||||
incremental,
|
||||
default_linker,
|
||||
std_features,
|
||||
|
||||
// Rest of the options can simply be ignored.
|
||||
debug: _,
|
||||
@ -3077,6 +3086,7 @@ fn check_incompatible_options_for_ci_rustc(
|
||||
err!(current_rust_config.default_linker, default_linker);
|
||||
err!(current_rust_config.stack_protector, stack_protector);
|
||||
err!(current_rust_config.lto, lto);
|
||||
err!(current_rust_config.std_features, std_features);
|
||||
|
||||
warn!(current_rust_config.channel, channel);
|
||||
warn!(current_rust_config.description, description);
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::collections::BTreeSet;
|
||||
use std::env;
|
||||
use std::fs::{File, remove_file};
|
||||
use std::io::Write;
|
||||
@ -326,3 +327,24 @@ fn verbose_tests_default_value() {
|
||||
let config = Config::parse(Flags::parse(&["build".into(), "compiler".into(), "-v".into()]));
|
||||
assert_eq!(config.verbose_tests, true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_rust_std_features() {
|
||||
let config = parse("rust.std-features = [\"panic-unwind\", \"backtrace\"]");
|
||||
let expected_features: BTreeSet<String> =
|
||||
["panic-unwind", "backtrace"].into_iter().map(|s| s.to_string()).collect();
|
||||
assert_eq!(config.rust_std_features, expected_features);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_rust_std_features_empty() {
|
||||
let config = parse("rust.std-features = []");
|
||||
let expected_features: BTreeSet<String> = BTreeSet::new();
|
||||
assert_eq!(config.rust_std_features, expected_features);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn parse_rust_std_features_invalid() {
|
||||
parse("rust.std-features = \"backtrace\"");
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
//! also check out the `src/bootstrap/README.md` file for more information.
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::collections::{BTreeSet, HashMap, HashSet};
|
||||
use std::fmt::Display;
|
||||
use std::fs::{self, File};
|
||||
use std::path::{Path, PathBuf};
|
||||
@ -645,28 +645,31 @@ impl Build {
|
||||
&self.config.rust_info
|
||||
}
|
||||
|
||||
/// Gets the space-separated set of activated features for the standard
|
||||
/// library.
|
||||
/// Gets the space-separated set of activated features for the standard 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: BTreeSet<&str> =
|
||||
self.config.rust_std_features.iter().map(|s| s.as_str()).collect();
|
||||
|
||||
match self.config.llvm_libunwind(target) {
|
||||
LlvmLibunwind::InTree => features.push_str(" llvm-libunwind"),
|
||||
LlvmLibunwind::System => features.push_str(" system-llvm-libunwind"),
|
||||
LlvmLibunwind::No => {}
|
||||
}
|
||||
LlvmLibunwind::InTree => features.insert("llvm-libunwind"),
|
||||
LlvmLibunwind::System => features.insert("system-llvm-libunwind"),
|
||||
LlvmLibunwind::No => false,
|
||||
};
|
||||
|
||||
if self.config.backtrace {
|
||||
features.push_str(" backtrace");
|
||||
features.insert("backtrace");
|
||||
}
|
||||
if self.config.profiler_enabled(target) {
|
||||
features.push_str(" profiler");
|
||||
features.insert("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.insert("compiler-builtins-mem");
|
||||
}
|
||||
features
|
||||
|
||||
features.into_iter().collect::<Vec<_>>().join(" ")
|
||||
}
|
||||
|
||||
/// Gets the space-separated set of activated features for the compiler.
|
||||
|
Loading…
Reference in New Issue
Block a user