Skip to content

Commit 0c794da

Browse files
committed
xtask: add switch for stable and unstable functionality
1 parent 2e83331 commit 0c794da

File tree

3 files changed

+49
-11
lines changed

3 files changed

+49
-11
lines changed

xtask/src/cargo.rs

+28-4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub enum Feature {
5151
Logger,
5252
PanicOnLoggerErrors,
5353
Unstable,
54+
UnstableAlloc,
5455

5556
// `uefi-services` features.
5657
PanicHandler,
@@ -69,6 +70,7 @@ impl Feature {
6970
Self::Logger => "logger",
7071
Self::PanicOnLoggerErrors => "panic-on-logger-errors",
7172
Self::Unstable => "unstable",
73+
Self::UnstableAlloc => "unstable_alloc",
7274

7375
Self::PanicHandler => "uefi-services/panic_handler",
7476
Self::Qemu => "uefi-services/qemu",
@@ -95,8 +97,18 @@ impl Feature {
9597
}
9698

9799
/// 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]
100+
/// # Parameters
101+
/// - `include_unstable` - add all functionality behind the `unstable` feature
102+
/// - `runtime_features` - add all functionality that effect the runtime of Rust
103+
pub fn more_code(include_unstable: bool, runtime_features: bool) -> Vec<Self> {
104+
let mut base_features = vec![Self::Alloc, Self::Logger];
105+
if include_unstable {
106+
base_features.extend([Self::Unstable, Self::UnstableAlloc])
107+
}
108+
if runtime_features {
109+
base_features.extend([Self::GlobalAllocator])
110+
}
111+
base_features
100112
}
101113

102114
fn comma_separated_string(features: &[Feature]) -> String {
@@ -307,8 +319,20 @@ mod tests {
307319
#[test]
308320
fn test_comma_separated_features() {
309321
assert_eq!(
310-
Feature::comma_separated_string(&Feature::more_code()),
311-
"global_allocator,alloc,logger"
322+
Feature::comma_separated_string(&Feature::more_code(false, false)),
323+
"alloc,logger"
324+
);
325+
assert_eq!(
326+
Feature::comma_separated_string(&Feature::more_code(false, true)),
327+
"alloc,logger,global_allocator"
328+
);
329+
assert_eq!(
330+
Feature::comma_separated_string(&Feature::more_code(true, false)),
331+
"alloc,logger,unstable,unstable_alloc"
332+
);
333+
assert_eq!(
334+
Feature::comma_separated_string(&Feature::more_code(true, true)),
335+
"alloc,logger,unstable,unstable_alloc,global_allocator"
312336
);
313337
}
314338

xtask/src/main.rs

+10-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(opt.include_unstable, 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),
@@ -87,7 +89,8 @@ fn clippy(opt: &ClippyOpt) -> Result<()> {
8789
fn doc(opt: &DocOpt) -> Result<()> {
8890
let cargo = Cargo {
8991
action: CargoAction::Doc { open: opt.open },
90-
features: Feature::more_code(),
92+
// for all possible features
93+
features: Feature::more_code(true, true),
9194
packages: Package::published(),
9295
release: false,
9396
target: None,
@@ -140,7 +143,7 @@ fn run_vm_tests(opt: &QemuOpt) -> Result<()> {
140143
/// Run unit tests and doctests on the host. Most of uefi-rs is tested
141144
/// with VM tests, but a few things like macros and data types can be
142145
/// tested with regular tests.
143-
fn run_host_tests() -> Result<()> {
146+
fn run_host_tests(test_opt: &TestOpt) -> Result<()> {
144147
// Run xtask tests.
145148
let cargo = Cargo {
146149
action: CargoAction::Test,
@@ -156,7 +159,8 @@ fn run_host_tests() -> Result<()> {
156159
// Run uefi-rs and uefi-macros tests.
157160
let cargo = Cargo {
158161
action: CargoAction::Test,
159-
features: vec![Feature::Alloc],
162+
// No runtime features as it is not possible to test a #[global_allocator] in Rust tests
163+
features: Feature::more_code(test_opt.include_unstable, false),
160164
// Don't test uefi-services (or the packages that depend on it)
161165
// as it has lang items that conflict with `std`.
162166
packages: vec![Package::Uefi, Package::UefiMacros],
@@ -219,7 +223,7 @@ fn main() -> Result<()> {
219223
Action::GenCode(gen_opt) => device_path::gen_code(gen_opt),
220224
Action::Miri(_) => run_miri(),
221225
Action::Run(qemu_opt) => run_vm_tests(qemu_opt),
222-
Action::Test(_) => run_host_tests(),
226+
Action::Test(test_opt) => run_host_tests(test_opt),
223227
Action::TestLatestRelease(_) => test_latest_release(),
224228
}
225229
}

xtask/src/opt.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ pub struct BuildOpt {
6363
#[clap(flatten)]
6464
pub build_mode: BuildModeOpt,
6565

66+
/// Include all features behind the "unstable" gate. uefi-rs must build without unstable
67+
/// functionality on stable (eventually) and with it in our nightly MSRV.
68+
#[clap(long, action)]
69+
pub include_unstable: bool,
70+
6671
/// Build multiple times to check that different feature
6772
/// combinations work.
6873
#[clap(long, action)]
@@ -145,7 +150,12 @@ pub struct QemuOpt {
145150

146151
/// Run unit tests and doctests on the host.
147152
#[derive(Debug, Parser)]
148-
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+
}
149159

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

0 commit comments

Comments
 (0)