bootstrap: add std_features config

bootstrap: add std_features  to config.example

fix: use BTreeSet for std-features; add unit tests

* fix formatting of string in front of std_features
* rename `std_features` to `std-features` in config.toml

fix: remove space before std-features in config.toml

fix: remove explicit .into_iter conversion

bootstrap: add details for rust.std-features in config.example.toml

Co-authored-by: Onur Özkan <onurozkan.dev@outlook.com>

fix: remove `Option<T>` from `rust_std_features`

fix: move default rust_std_features to config

fix: make std_features CI rustc incompatible
This commit is contained in:
Shriram Balaji 2024-09-12 00:56:52 +05:30
parent 85e2f55d82
commit 8b968764f1
4 changed files with 58 additions and 13 deletions

View File

@ -759,6 +759,16 @@
# Build compiler with the optimization enabled and -Zvalidate-mir, currently only for `std` # Build compiler with the optimization enabled and -Zvalidate-mir, currently only for `std`
#validate-mir-opts = 3 #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 # Options for specific targets
# #

View File

@ -4,7 +4,7 @@
//! how the build runs. //! how the build runs.
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::collections::{HashMap, HashSet}; use std::collections::{BTreeSet, HashMap, HashSet};
use std::fmt::{self, Display}; use std::fmt::{self, Display};
use std::io::IsTerminal; use std::io::IsTerminal;
use std::path::{Path, PathBuf, absolute}; use std::path::{Path, PathBuf, absolute};
@ -287,6 +287,7 @@ pub struct Config {
pub rust_profile_generate: Option<String>, pub rust_profile_generate: Option<String>,
pub rust_lto: RustcLto, pub rust_lto: RustcLto,
pub rust_validate_mir_opts: Option<u32>, pub rust_validate_mir_opts: Option<u32>,
pub rust_std_features: BTreeSet<String>,
pub llvm_profile_use: Option<String>, pub llvm_profile_use: Option<String>,
pub llvm_profile_generate: bool, pub llvm_profile_generate: bool,
pub llvm_libunwind_default: Option<LlvmLibunwind>, pub llvm_libunwind_default: Option<LlvmLibunwind>,
@ -1152,6 +1153,7 @@ define_config! {
download_rustc: Option<StringOrBool> = "download-rustc", download_rustc: Option<StringOrBool> = "download-rustc",
lto: Option<String> = "lto", lto: Option<String> = "lto",
validate_mir_opts: Option<u32> = "validate-mir-opts", 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 optimize = None;
let mut omit_git_hash = None; let mut omit_git_hash = None;
let mut lld_enabled = None; let mut lld_enabled = None;
let mut std_features = None;
let mut is_user_configured_rust_channel = false; let mut is_user_configured_rust_channel = false;
@ -1703,6 +1706,7 @@ impl Config {
stack_protector, stack_protector,
strip, strip,
lld_mode, lld_mode,
std_features: std_features_toml,
} = rust; } = rust;
is_user_configured_rust_channel = channel.is_some(); is_user_configured_rust_channel = channel.is_some();
@ -1722,6 +1726,7 @@ impl Config {
debuginfo_level_tools = debuginfo_level_tools_toml; debuginfo_level_tools = debuginfo_level_tools_toml;
debuginfo_level_tests = debuginfo_level_tests_toml; debuginfo_level_tests = debuginfo_level_tests_toml;
lld_enabled = lld_enabled_toml; lld_enabled = lld_enabled_toml;
std_features = std_features_toml;
optimize = optimize_toml; optimize = optimize_toml;
omit_git_hash = omit_git_hash_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); let default = debug == Some(true);
config.rust_debug_assertions = debug_assertions.unwrap_or(default); config.rust_debug_assertions = debug_assertions.unwrap_or(default);
config.rust_debug_assertions_std = config.rust_debug_assertions_std =
@ -3016,6 +3024,7 @@ fn check_incompatible_options_for_ci_rustc(
description, description,
incremental, incremental,
default_linker, default_linker,
std_features,
// Rest of the options can simply be ignored. // Rest of the options can simply be ignored.
debug: _, debug: _,
@ -3077,6 +3086,7 @@ fn check_incompatible_options_for_ci_rustc(
err!(current_rust_config.default_linker, default_linker); err!(current_rust_config.default_linker, default_linker);
err!(current_rust_config.stack_protector, stack_protector); err!(current_rust_config.stack_protector, stack_protector);
err!(current_rust_config.lto, lto); err!(current_rust_config.lto, lto);
err!(current_rust_config.std_features, std_features);
warn!(current_rust_config.channel, channel); warn!(current_rust_config.channel, channel);
warn!(current_rust_config.description, description); warn!(current_rust_config.description, description);

View File

@ -1,3 +1,4 @@
use std::collections::BTreeSet;
use std::env; use std::env;
use std::fs::{File, remove_file}; use std::fs::{File, remove_file};
use std::io::Write; 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()])); let config = Config::parse(Flags::parse(&["build".into(), "compiler".into(), "-v".into()]));
assert_eq!(config.verbose_tests, true); 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\"");
}

View File

@ -17,7 +17,7 @@
//! also check out the `src/bootstrap/README.md` file for more information. //! also check out the `src/bootstrap/README.md` file for more information.
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::collections::{HashMap, HashSet}; use std::collections::{BTreeSet, HashMap, HashSet};
use std::fmt::Display; use std::fmt::Display;
use std::fs::{self, File}; use std::fs::{self, File};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -645,28 +645,31 @@ impl Build {
&self.config.rust_info &self.config.rust_info
} }
/// Gets the space-separated set of activated features for the standard /// 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 { 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) { match self.config.llvm_libunwind(target) {
LlvmLibunwind::InTree => features.push_str(" llvm-libunwind"), LlvmLibunwind::InTree => features.insert("llvm-libunwind"),
LlvmLibunwind::System => features.push_str(" system-llvm-libunwind"), LlvmLibunwind::System => features.insert("system-llvm-libunwind"),
LlvmLibunwind::No => {} LlvmLibunwind::No => false,
} };
if self.config.backtrace { if self.config.backtrace {
features.push_str(" backtrace"); features.insert("backtrace");
} }
if self.config.profiler_enabled(target) { if self.config.profiler_enabled(target) {
features.push_str(" profiler"); features.insert("profiler");
} }
// Generate memcpy, etc. FIXME: Remove this once compiler-builtins // Generate memcpy, etc. FIXME: Remove this once compiler-builtins
// automatically detects this target. // automatically detects this target.
if target.contains("zkvm") { 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. /// Gets the space-separated set of activated features for the compiler.