Skip to content

Commit 7ab3246

Browse files
committed
build.rs: Rework feature forwarding
Now features are enabled with a single `--features` flag. Also the logic is easier to use now.
1 parent 9c2fc79 commit 7ab3246

File tree

1 file changed

+27
-42
lines changed

1 file changed

+27
-42
lines changed

hermit-sys/build.rs

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ use std::path::{Path, PathBuf};
1010
use std::process::Command;
1111
use walkdir::{DirEntry, WalkDir};
1212

13+
macro_rules! forward_features {
14+
($cmd:expr, $($feature:literal,)+ ) => {
15+
let mut features = vec![];
16+
17+
$(
18+
if cfg!(feature = $feature) {
19+
features.push($feature);
20+
}
21+
)+
22+
23+
if !features.is_empty() {
24+
$cmd.arg("--features");
25+
$cmd.arg(features.join(" "));
26+
}
27+
};
28+
}
29+
1330
fn build_hermit(src_dir: &Path, target_dir_opt: Option<&Path>) {
1431
let manifest_path = src_dir.join("Cargo.toml");
1532
assert!(
@@ -59,49 +76,17 @@ fn build_hermit(src_dir: &Path, target_dir_opt: Option<&Path>) {
5976
cmd.arg("--release");
6077
}
6178

62-
// disable all default features
79+
// Control enabled features via this crate's features
6380
cmd.arg("--no-default-features");
64-
65-
#[cfg(feature = "aarch64-qemu-stdout")]
66-
{
67-
cmd.arg("--features");
68-
cmd.arg("aarch64-qemu-stdout");
69-
}
70-
71-
// do we have to enable PCI support?
72-
#[cfg(feature = "pci")]
73-
{
74-
cmd.arg("--features");
75-
cmd.arg("pci");
76-
}
77-
78-
// do we have to enable acpi support?
79-
#[cfg(feature = "acpi")]
80-
{
81-
cmd.arg("--features");
82-
cmd.arg("acpi");
83-
}
84-
85-
// do we have to enable FSGSBASE support?
86-
#[cfg(feature = "fsgsbase")]
87-
{
88-
cmd.arg("--features");
89-
cmd.arg("fsgsbase");
90-
}
91-
92-
// do we support multi-processor systems?
93-
#[cfg(feature = "smp")]
94-
{
95-
cmd.arg("--features");
96-
cmd.arg("smp");
97-
}
98-
99-
// do we have to enable VGA support
100-
#[cfg(feature = "vga")]
101-
{
102-
cmd.arg("--features");
103-
cmd.arg("vga");
104-
}
81+
forward_features!(
82+
cmd,
83+
"aarch64-qemu-stdout",
84+
"acpi",
85+
"fsgsbase",
86+
"pci",
87+
"smp",
88+
"vga",
89+
);
10590

10691
let mut rustflags = vec!["-Zmutable-noalias=no".to_string()];
10792
let outer_rustflags = env::var("CARGO_ENCODED_RUSTFLAGS").unwrap();

0 commit comments

Comments
 (0)