Skip to content

Commit 0534459

Browse files
bors[bot]mkroening
andauthored
Merge #199
199: Rework features r=stlankes a=mkroening Co-authored-by: Martin Kröning <mkroening@posteo.net>
2 parents a01dd68 + 5f2342b commit 0534459

File tree

2 files changed

+45
-51
lines changed

2 files changed

+45
-51
lines changed

hermit-sys/Cargo.toml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,28 @@ edition = "2021"
1414
documentation = "https://hermitcore.github.io/rusty-hermit/hermit_sys"
1515

1616
[features]
17-
default = ["pci", "acpi", "smp", "fsgsbase"]
18-
# controls whether RustyHermit is build with -Z instrument-mcount
19-
instrument = ["rftrace"]
20-
trace = []
17+
default = [
18+
"acpi",
19+
"pci",
20+
"smp",
21+
"fsgsbase",
22+
]
23+
24+
aarch64-qemu-stdout = []
25+
acpi = []
26+
dhcpv4 = ["smoltcp/proto-dhcpv4"]
2127
fsgsbase = []
28+
29+
# Build the kernel with function instrument code for mcount-based tracing
30+
instrument = ["rftrace"]
31+
2232
pci = []
23-
acpi = []
33+
smp = []
34+
trace = []
2435
vga = []
25-
dhcpv4 = ["smoltcp/proto-dhcpv4"]
26-
# only for internal usage, please don't use it
36+
37+
# Internal feature for building the kernel from local sources
2738
with_submodule = []
28-
smp = []
29-
aarch64-qemu-stdout = []
3039

3140
[build-dependencies]
3241
walkdir = "2"

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 = "fsgs_base")]
87-
{
88-
cmd.arg("--features");
89-
cmd.arg("fsgs_base");
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)