Skip to content

Commit 4fd844c

Browse files
committed
xtask: add switch for stable and unstable functionality
1 parent f7f3fd8 commit 4fd844c

File tree

3 files changed

+45
-11
lines changed

3 files changed

+45
-11
lines changed

xtask/src/cargo.rs

+26-4
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,18 @@ impl Feature {
9595
}
9696

9797
/// Set of features that enables more code in the root uefi crate.
98-
pub fn more_code() -> Vec<Self> {
99-
vec![Self::GlobalAllocator, Self::Alloc, Self::Logger]
98+
/// # Parameters
99+
/// - `include_unstable` - add all functionality behind the `unstable` feature
100+
/// - `runtime_features` - add all functionality that effect the runtime of Rust
101+
pub fn more_code(include_unstable: bool, runtime_features: bool) -> Vec<Self> {
102+
let mut base_features = vec![Self::Alloc, Self::Logger];
103+
if include_unstable {
104+
base_features.extend([Self::Unstable])
105+
}
106+
if runtime_features {
107+
base_features.extend([Self::GlobalAllocator])
108+
}
109+
base_features
100110
}
101111

102112
fn comma_separated_string(features: &[Feature]) -> String {
@@ -316,8 +326,20 @@ mod tests {
316326
#[test]
317327
fn test_comma_separated_features() {
318328
assert_eq!(
319-
Feature::comma_separated_string(&Feature::more_code()),
320-
"global_allocator,alloc,logger"
329+
Feature::comma_separated_string(&Feature::more_code(false, false)),
330+
"alloc,logger"
331+
);
332+
assert_eq!(
333+
Feature::comma_separated_string(&Feature::more_code(false, true)),
334+
"alloc,logger,global_allocator"
335+
);
336+
assert_eq!(
337+
Feature::comma_separated_string(&Feature::more_code(true, false)),
338+
"alloc,logger,unstable"
339+
);
340+
assert_eq!(
341+
Feature::comma_separated_string(&Feature::more_code(true, true)),
342+
"alloc,logger,unstable,global_allocator"
321343
);
322344
}
323345

xtask/src/main.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod platform;
99
mod qemu;
1010
mod util;
1111

12+
use crate::opt::TestOpt;
1213
use anyhow::Result;
1314
use cargo::{fix_nested_cargo_env, Cargo, CargoAction, Feature, Package, TargetTypes};
1415
use clap::Parser;
@@ -47,7 +48,7 @@ fn build(opt: &BuildOpt) -> Result<()> {
4748

4849
let cargo = Cargo {
4950
action: CargoAction::Build,
50-
features: Feature::more_code(),
51+
features: Feature::more_code(true, true),
5152
packages: Package::all_except_xtask(),
5253
release: opt.build_mode.release,
5354
target: Some(*opt.target),
@@ -61,7 +62,8 @@ fn clippy(opt: &ClippyOpt) -> Result<()> {
6162
// Run clippy on all the UEFI packages.
6263
let cargo = Cargo {
6364
action: CargoAction::Clippy,
64-
features: Feature::more_code(),
65+
// for all possible features
66+
features: Feature::more_code(true, true),
6567
packages: Package::all_except_xtask(),
6668
release: false,
6769
target: Some(*opt.target),
@@ -90,7 +92,8 @@ fn doc(opt: &DocOpt) -> Result<()> {
9092
open: opt.open,
9193
document_private_items: opt.document_private_items,
9294
},
93-
features: Feature::more_code(),
95+
// for all possible features
96+
features: Feature::more_code(true, true),
9497
packages: Package::published(),
9598
release: false,
9699
target: None,
@@ -143,7 +146,7 @@ fn run_vm_tests(opt: &QemuOpt) -> Result<()> {
143146
/// Run unit tests and doctests on the host. Most of uefi-rs is tested
144147
/// with VM tests, but a few things like macros and data types can be
145148
/// tested with regular tests.
146-
fn run_host_tests() -> Result<()> {
149+
fn run_host_tests(test_opt: &TestOpt) -> Result<()> {
147150
// Run xtask tests.
148151
let cargo = Cargo {
149152
action: CargoAction::Test,
@@ -159,7 +162,11 @@ fn run_host_tests() -> Result<()> {
159162
// Run uefi-rs and uefi-macros tests.
160163
let cargo = Cargo {
161164
action: CargoAction::Test,
162-
features: vec![Feature::Alloc],
165+
// At least one unit test, for make_boxed() currently, has different behaviour dependent on
166+
// the unstable feature. Because of this, we need to allow to test both variants. Runtime
167+
// features is set to no as it is not possible as as soon a #[global_allocator] is
168+
// registered, the Rust runtime executing the tests uses it as well.
169+
features: Feature::more_code(test_opt.include_unstable, false),
163170
// Don't test uefi-services (or the packages that depend on it)
164171
// as it has lang items that conflict with `std`.
165172
packages: vec![Package::Uefi, Package::UefiMacros],
@@ -222,7 +229,7 @@ fn main() -> Result<()> {
222229
Action::GenCode(gen_opt) => device_path::gen_code(gen_opt),
223230
Action::Miri(_) => run_miri(),
224231
Action::Run(qemu_opt) => run_vm_tests(qemu_opt),
225-
Action::Test(_) => run_host_tests(),
232+
Action::Test(test_opt) => run_host_tests(test_opt),
226233
Action::TestLatestRelease(_) => test_latest_release(),
227234
}
228235
}

xtask/src/opt.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,12 @@ pub struct QemuOpt {
150150

151151
/// Run unit tests and doctests on the host.
152152
#[derive(Debug, Parser)]
153-
pub struct TestOpt;
153+
pub struct TestOpt {
154+
/// Include all features behind the "unstable" gate. uefi-rs must build without unstable
155+
/// functionality on stable (eventually) and with it in our nightly MSRV.
156+
#[clap(long, action)]
157+
pub include_unstable: bool,
158+
}
154159

155160
/// Build the template against the crates.io packages.
156161
#[derive(Debug, Parser)]

0 commit comments

Comments
 (0)