Skip to content

Commit 5b5edc5

Browse files
nicholasbishopphip1611
authored andcommitted
xtask: Add "cargo xtask build --feature-permutations"
The `--feature-permutations` flag runs a bunch of builds of just the `uefi` and `uefi-services` crates to test that the build works no matter what features are selected.
1 parent 44150e3 commit 5b5edc5

File tree

4 files changed

+66
-2
lines changed

4 files changed

+66
-2
lines changed

xtask/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ clap = { version = "4.0.4", features = ["derive"] }
1111
fatfs = { git = "https://github.com/rafalh/rust-fatfs.git", rev = "87fc1ed5074a32b4e0344fcdde77359ef9e75432" }
1212
fs-err = "2.6.0"
1313
heck = "0.4.0"
14+
itertools = "0.10.5"
1415
# Use git as a temporary workaround for https://github.com/rust-osdev/uefi-rs/issues/573.
1516
mbrman = { git = "https://github.com/cecton/mbrman.git", rev = "78565860e55c272488d94480e72a4e2cd159ad8e" }
1617
nix = "0.25.0"

xtask/src/cargo.rs

+33-2
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,55 @@ impl Package {
4545

4646
#[derive(Clone, Copy, Debug)]
4747
pub enum Feature {
48-
GlobalAllocator,
48+
// `uefi` features.
4949
Alloc,
50+
GlobalAllocator,
5051
Logger,
52+
PanicOnLoggerErrors,
53+
Unstable,
54+
55+
// `uefi-services` features.
56+
PanicHandler,
57+
Qemu,
58+
ServicesLogger,
5159

60+
// `uefi-test-runner` features.
5261
Ci,
5362
}
5463

5564
impl Feature {
5665
fn as_str(&self) -> &'static str {
5766
match self {
58-
Self::GlobalAllocator => "global_allocator",
5967
Self::Alloc => "alloc",
68+
Self::GlobalAllocator => "global_allocator",
6069
Self::Logger => "logger",
70+
Self::PanicOnLoggerErrors => "panic-on-logger-errors",
71+
Self::Unstable => "unstable",
72+
73+
Self::PanicHandler => "uefi-services/panic_handler",
74+
Self::Qemu => "uefi-services/qemu",
75+
Self::ServicesLogger => "uefi-services/logger",
6176

6277
Self::Ci => "uefi-test-runner/ci",
6378
}
6479
}
6580

81+
/// Get the features for the given package.
82+
pub fn package_features(package: Package) -> Vec<Self> {
83+
match package {
84+
Package::Uefi => vec![
85+
Self::Alloc,
86+
Self::GlobalAllocator,
87+
Self::Logger,
88+
Self::PanicOnLoggerErrors,
89+
Self::Unstable,
90+
],
91+
Package::UefiServices => vec![Self::PanicHandler, Self::Qemu, Self::ServicesLogger],
92+
Package::UefiTestRunner => vec![Self::Ci],
93+
_ => vec![],
94+
}
95+
}
96+
6697
/// Set of features that enables more code in the root uefi crate.
6798
pub fn more_code() -> Vec<Self> {
6899
vec![Self::GlobalAllocator, Self::Alloc, Self::Logger]

xtask/src/main.rs

+27
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,39 @@ mod util;
1212
use anyhow::Result;
1313
use cargo::{fix_nested_cargo_env, Cargo, CargoAction, Feature, Package, TargetTypes};
1414
use clap::Parser;
15+
use itertools::Itertools;
1516
use opt::{Action, BuildOpt, ClippyOpt, DocOpt, Opt, QemuOpt};
1617
use std::process::Command;
1718
use tempfile::TempDir;
1819
use util::{command_to_string, run_cmd};
1920

21+
fn build_feature_permutations(opt: &BuildOpt) -> Result<()> {
22+
for package in [Package::Uefi, Package::UefiServices] {
23+
let all_package_features = Feature::package_features(package);
24+
for features in all_package_features.iter().powerset() {
25+
let features = features.iter().map(|f| **f).collect();
26+
27+
let cargo = Cargo {
28+
action: CargoAction::Build,
29+
features,
30+
packages: vec![package],
31+
release: opt.build_mode.release,
32+
target: Some(*opt.target),
33+
warnings_as_errors: true,
34+
target_types: TargetTypes::BinsExamplesLib,
35+
};
36+
run_cmd(cargo.command()?)?;
37+
}
38+
}
39+
40+
Ok(())
41+
}
42+
2043
fn build(opt: &BuildOpt) -> Result<()> {
44+
if opt.feature_permutations {
45+
return build_feature_permutations(opt);
46+
}
47+
2148
let cargo = Cargo {
2249
action: CargoAction::Build,
2350
features: Feature::more_code(),

xtask/src/opt.rs

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ pub struct BuildOpt {
6262

6363
#[clap(flatten)]
6464
pub build_mode: BuildModeOpt,
65+
66+
/// Build multiple times to check that different feature
67+
/// combinations work.
68+
#[clap(long, action)]
69+
pub feature_permutations: bool,
6570
}
6671

6772
/// Run clippy on all the packages.

0 commit comments

Comments
 (0)