Skip to content

Commit 36fe025

Browse files
authored
Unrolled build for rust-lang#131315
Rollup merge of rust-lang#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.
2 parents 68301a6 + 8b96876 commit 36fe025

File tree

4 files changed

+58
-13
lines changed

4 files changed

+58
-13
lines changed

config.example.toml

+10
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,16 @@
759759
# Build compiler with the optimization enabled and -Zvalidate-mir, currently only for `std`
760760
#validate-mir-opts = 3
761761

762+
# Configure `std` features used during bootstrap.
763+
# Default features will be expanded in the following cases:
764+
# - If `rust.llvm-libunwind` or `target.llvm-libunwind` is enabled:
765+
# - "llvm-libunwind" will be added for in-tree LLVM builds.
766+
# - "system-llvm-libunwind" will be added for system LLVM builds.
767+
# - If `rust.backtrace` is enabled, "backtrace" will be added.
768+
# - If `rust.profiler` or `target.profiler` is enabled, "profiler" will be added.
769+
# - If building for a zkvm target, "compiler-builtins-mem" will be added.
770+
#std-features = ["panic_unwind"]
771+
762772
# =============================================================================
763773
# Options for specific targets
764774
#

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! how the build runs.
55
66
use std::cell::{Cell, RefCell};
7-
use std::collections::{HashMap, HashSet};
7+
use std::collections::{BTreeSet, HashMap, HashSet};
88
use std::fmt::{self, Display};
99
use std::io::IsTerminal;
1010
use std::path::{Path, PathBuf, absolute};
@@ -287,6 +287,7 @@ pub struct Config {
287287
pub rust_profile_generate: Option<String>,
288288
pub rust_lto: RustcLto,
289289
pub rust_validate_mir_opts: Option<u32>,
290+
pub rust_std_features: BTreeSet<String>,
290291
pub llvm_profile_use: Option<String>,
291292
pub llvm_profile_generate: bool,
292293
pub llvm_libunwind_default: Option<LlvmLibunwind>,
@@ -1152,6 +1153,7 @@ define_config! {
11521153
download_rustc: Option<StringOrBool> = "download-rustc",
11531154
lto: Option<String> = "lto",
11541155
validate_mir_opts: Option<u32> = "validate-mir-opts",
1156+
std_features: Option<BTreeSet<String>> = "std-features",
11551157
}
11561158
}
11571159

@@ -1645,6 +1647,7 @@ impl Config {
16451647
let mut optimize = None;
16461648
let mut omit_git_hash = None;
16471649
let mut lld_enabled = None;
1650+
let mut std_features = None;
16481651

16491652
let mut is_user_configured_rust_channel = false;
16501653

@@ -1703,6 +1706,7 @@ impl Config {
17031706
stack_protector,
17041707
strip,
17051708
lld_mode,
1709+
std_features: std_features_toml,
17061710
} = rust;
17071711

17081712
is_user_configured_rust_channel = channel.is_some();
@@ -1722,6 +1726,7 @@ impl Config {
17221726
debuginfo_level_tools = debuginfo_level_tools_toml;
17231727
debuginfo_level_tests = debuginfo_level_tests_toml;
17241728
lld_enabled = lld_enabled_toml;
1729+
std_features = std_features_toml;
17251730

17261731
optimize = optimize_toml;
17271732
omit_git_hash = omit_git_hash_toml;
@@ -2118,6 +2123,9 @@ impl Config {
21182123
);
21192124
}
21202125

2126+
let default_std_features = BTreeSet::from([String::from("panic-unwind")]);
2127+
config.rust_std_features = std_features.unwrap_or(default_std_features);
2128+
21212129
let default = debug == Some(true);
21222130
config.rust_debug_assertions = debug_assertions.unwrap_or(default);
21232131
config.rust_debug_assertions_std =
@@ -3016,6 +3024,7 @@ fn check_incompatible_options_for_ci_rustc(
30163024
description,
30173025
incremental,
30183026
default_linker,
3027+
std_features,
30193028

30203029
// Rest of the options can simply be ignored.
30213030
debug: _,
@@ -3077,6 +3086,7 @@ fn check_incompatible_options_for_ci_rustc(
30773086
err!(current_rust_config.default_linker, default_linker);
30783087
err!(current_rust_config.stack_protector, stack_protector);
30793088
err!(current_rust_config.lto, lto);
3089+
err!(current_rust_config.std_features, std_features);
30803090

30813091
warn!(current_rust_config.channel, channel);
30823092
warn!(current_rust_config.description, description);

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

+22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::BTreeSet;
12
use std::env;
23
use std::fs::{File, remove_file};
34
use std::io::Write;
@@ -326,3 +327,24 @@ fn verbose_tests_default_value() {
326327
let config = Config::parse(Flags::parse(&["build".into(), "compiler".into(), "-v".into()]));
327328
assert_eq!(config.verbose_tests, true);
328329
}
330+
331+
#[test]
332+
fn parse_rust_std_features() {
333+
let config = parse("rust.std-features = [\"panic-unwind\", \"backtrace\"]");
334+
let expected_features: BTreeSet<String> =
335+
["panic-unwind", "backtrace"].into_iter().map(|s| s.to_string()).collect();
336+
assert_eq!(config.rust_std_features, expected_features);
337+
}
338+
339+
#[test]
340+
fn parse_rust_std_features_empty() {
341+
let config = parse("rust.std-features = []");
342+
let expected_features: BTreeSet<String> = BTreeSet::new();
343+
assert_eq!(config.rust_std_features, expected_features);
344+
}
345+
346+
#[test]
347+
#[should_panic]
348+
fn parse_rust_std_features_invalid() {
349+
parse("rust.std-features = \"backtrace\"");
350+
}

src/bootstrap/src/lib.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
//! also check out the `src/bootstrap/README.md` file for more information.
1818
1919
use std::cell::{Cell, RefCell};
20-
use std::collections::{HashMap, HashSet};
20+
use std::collections::{BTreeSet, HashMap, HashSet};
2121
use std::fmt::Display;
2222
use std::fs::{self, File};
2323
use std::path::{Path, PathBuf};
@@ -645,28 +645,31 @@ impl Build {
645645
&self.config.rust_info
646646
}
647647

648-
/// Gets the space-separated set of activated features for the standard
649-
/// library.
648+
/// Gets the space-separated set of activated features for the standard library.
649+
/// This can be configured with the `std-features` key in config.toml.
650650
fn std_features(&self, target: TargetSelection) -> String {
651-
let mut features = " panic-unwind".to_string();
651+
let mut features: BTreeSet<&str> =
652+
self.config.rust_std_features.iter().map(|s| s.as_str()).collect();
652653

653654
match self.config.llvm_libunwind(target) {
654-
LlvmLibunwind::InTree => features.push_str(" llvm-libunwind"),
655-
LlvmLibunwind::System => features.push_str(" system-llvm-libunwind"),
656-
LlvmLibunwind::No => {}
657-
}
655+
LlvmLibunwind::InTree => features.insert("llvm-libunwind"),
656+
LlvmLibunwind::System => features.insert("system-llvm-libunwind"),
657+
LlvmLibunwind::No => false,
658+
};
659+
658660
if self.config.backtrace {
659-
features.push_str(" backtrace");
661+
features.insert("backtrace");
660662
}
661663
if self.config.profiler_enabled(target) {
662-
features.push_str(" profiler");
664+
features.insert("profiler");
663665
}
664666
// Generate memcpy, etc. FIXME: Remove this once compiler-builtins
665667
// automatically detects this target.
666668
if target.contains("zkvm") {
667-
features.push_str(" compiler-builtins-mem");
669+
features.insert("compiler-builtins-mem");
668670
}
669-
features
671+
672+
features.into_iter().collect::<Vec<_>>().join(" ")
670673
}
671674

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

0 commit comments

Comments
 (0)