Skip to content

Commit db5d2bf

Browse files
committed
Enable setting target-api-features from config.toml
Move api-feature logic into its own function and make it active in both the rustc and std bootstrap config
1 parent b5211a1 commit db5d2bf

File tree

4 files changed

+56
-22
lines changed

4 files changed

+56
-22
lines changed

config.toml.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,11 @@
546546
# probably don't want to use this.
547547
#qemu-rootfs = "..."
548548

549+
# Comma separated list of target api features for the target. Currently, *all*
550+
# features have to be passed if this is specified. Inherited features are not
551+
# supported here yet.
552+
#target-api-feature = "...,..."
553+
549554
# =============================================================================
550555
# Distribution options
551556
#

src/bootstrap/compile.rs

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,43 @@ fn copy_self_contained_objects(
205205
target_deps
206206
}
207207

208+
fn add_target_api_features_cargo(
209+
builder: &Builder<'_>,
210+
target: TargetSelection,
211+
cargo: &mut Cargo,
212+
) {
213+
if let Some(api_features) = builder.target_api_feature(target) {
214+
for api_feature in api_features {
215+
cargo.rustflag("--cfg");
216+
cargo.rustflag(&format!("target_api_feature=\"{}\"", api_feature));
217+
}
218+
} else {
219+
if target.contains("windows") {
220+
// all `target_api_feature`s for the currently officially supported
221+
// windows version for rust
222+
const WINDOWS_VERSIONS: [&str; 12] = [
223+
"3.10.511", // NT 3.1
224+
"3.10.528", // NT 3.1 SP3
225+
"3.50.807", // NT 3.5
226+
"3.51.1057", // NT 3.51
227+
"4.0.1381", // NT 4
228+
"5.0.2195", // 2000
229+
"5.1.2600", // XP
230+
"5.2.3790", // XP 64bit, Server 2003
231+
"6.0.6000", // Vista, Server 2008
232+
"6.0.6001", // Vista SP1, Server 2008 SP1
233+
"6.0.6002", // Vista SP2, Server 2008 SP2
234+
"6.1.7600", // 7, Server 2008 R2
235+
];
236+
237+
for v in &WINDOWS_VERSIONS {
238+
cargo.rustflag("--cfg");
239+
cargo.rustflag(&format!("target_api_feature=\"{}\"", v));
240+
}
241+
}
242+
}
243+
}
244+
208245
/// Configure cargo to compile the standard library, adding appropriate env vars
209246
/// and such.
210247
pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, cargo: &mut Cargo) {
@@ -296,6 +333,8 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
296333
if target.contains("riscv") {
297334
cargo.rustflag("-Cforce-unwind-tables=yes");
298335
}
336+
337+
add_target_api_features_cargo(builder, target, cargo);
299338
}
300339

301340
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@@ -604,28 +643,7 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS
604643
}
605644
}
606645

607-
if target.contains("windows") {
608-
// all `target_api_feature`s for the currently officially supported
609-
// windows version for rust
610-
const WINDOWS_VERSIONS: [&str; 12] = [
611-
"3.10.511", // NT 3.1
612-
"3.10.528", // NT 3.1 SP3
613-
"3.50.807", // NT 3.5
614-
"3.51.1057", // NT 3.51
615-
"4.0.1381", // NT 4
616-
"5.0.2195", // 2000
617-
"5.1.2600", // XP
618-
"5.2.3790", // XP 64bit, Server 2003
619-
"6.0.6000", // Vista, Server 2008
620-
"6.0.6001", // Vista SP1, Server 2008 SP1
621-
"6.0.6002", // Vista SP2, Server 2008 SP2
622-
"6.1.7600", // 7, Server 2008 R2
623-
];
624-
625-
for v in &WINDOWS_VERSIONS {
626-
cargo.rustflag(&format!("--cfg=target_api_feature=\"{}\"", v));
627-
}
628-
}
646+
add_target_api_features_cargo(builder, target, cargo);
629647
}
630648

631649
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]

src/bootstrap/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ pub struct Target {
240240
pub wasi_root: Option<PathBuf>,
241241
pub qemu_rootfs: Option<PathBuf>,
242242
pub no_std: bool,
243+
pub target_api_feature: Option<Vec<String>>,
243244
}
244245

245246
impl Target {
@@ -432,6 +433,7 @@ struct TomlTarget {
432433
wasi_root: Option<String>,
433434
qemu_rootfs: Option<String>,
434435
no_std: Option<bool>,
436+
target_api_feature: Option<String>,
435437
}
436438

437439
impl Config {
@@ -703,6 +705,10 @@ impl Config {
703705
target.musl_libdir = cfg.musl_libdir.clone().map(PathBuf::from);
704706
target.wasi_root = cfg.wasi_root.clone().map(PathBuf::from);
705707
target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from);
708+
target.target_api_feature = cfg
709+
.target_api_feature
710+
.as_ref()
711+
.map(|s| s.split(',').map(String::from).collect());
706712

707713
config.target_config.insert(TargetSelection::from_user(triple), target);
708714
}

src/bootstrap/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,11 @@ impl Build {
921921
self.config.target_config.get(&target).and_then(|t| t.qemu_rootfs.as_ref()).map(|p| &**p)
922922
}
923923

924+
/// Returns the target api feature list if they are present
925+
fn target_api_feature(&self, target: TargetSelection) -> Option<&Vec<String>> {
926+
self.config.target_config.get(&target).and_then(|t| t.target_api_feature.as_ref())
927+
}
928+
924929
/// Path to the python interpreter to use
925930
fn python(&self) -> &Path {
926931
self.config.python.as_ref().unwrap()

0 commit comments

Comments
 (0)