Skip to content

Commit f70feb8

Browse files
nicholasbishopGabrielMajeri
authored andcommitted
xtask: add option to override toolchain
1 parent 8e4fb8d commit f70feb8

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

xtask/src/cargo.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub enum CargoAction {
8989
pub struct Cargo {
9090
pub action: CargoAction,
9191
pub features: Vec<Feature>,
92-
pub nightly: bool,
92+
pub toolchain: Option<String>,
9393
pub packages: Vec<Package>,
9494
pub release: bool,
9595
pub target: Option<UefiArch>,
@@ -99,8 +99,9 @@ pub struct Cargo {
9999
impl Cargo {
100100
pub fn command(&self) -> Result<Command> {
101101
let mut cmd = Command::new("cargo");
102-
if self.nightly {
103-
cmd.arg("+nightly");
102+
103+
if let Some(toolchain) = &self.toolchain {
104+
cmd.arg(&format!("+{}", toolchain));
104105
}
105106

106107
let action;
@@ -187,7 +188,7 @@ mod tests {
187188
let cargo = Cargo {
188189
action: CargoAction::Doc { open: true },
189190
features: vec![Feature::Alloc],
190-
nightly: true,
191+
toolchain: Some("nightly".into()),
191192
packages: vec![Package::Uefi, Package::Xtask],
192193
release: false,
193194
target: None,

xtask/src/main.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ use std::process::Command;
1212
use tempfile::TempDir;
1313
use util::{command_to_string, run_cmd};
1414

15+
const NIGHTLY: &str = "nightly";
16+
1517
fn build(opt: &BuildOpt) -> Result<()> {
1618
let cargo = Cargo {
1719
action: CargoAction::Build,
1820
features: Feature::more_code(),
19-
nightly: true,
21+
toolchain: opt.toolchain.or(NIGHTLY),
2022
packages: Package::all_except_xtask(),
2123
release: opt.build_mode.release,
2224
target: Some(*opt.target),
@@ -30,7 +32,7 @@ fn clippy(opt: &ClippyOpt) -> Result<()> {
3032
let cargo = Cargo {
3133
action: CargoAction::Clippy,
3234
features: Feature::more_code(),
33-
nightly: true,
35+
toolchain: opt.toolchain.or(NIGHTLY),
3436
packages: Package::all_except_xtask(),
3537
release: false,
3638
target: Some(*opt.target),
@@ -42,7 +44,7 @@ fn clippy(opt: &ClippyOpt) -> Result<()> {
4244
let cargo = Cargo {
4345
action: CargoAction::Clippy,
4446
features: Vec::new(),
45-
nightly: false,
47+
toolchain: None,
4648
packages: vec![Package::Xtask],
4749
release: false,
4850
target: None,
@@ -56,7 +58,7 @@ fn doc(opt: &DocOpt) -> Result<()> {
5658
let cargo = Cargo {
5759
action: CargoAction::Doc { open: opt.open },
5860
features: Feature::more_code(),
59-
nightly: true,
61+
toolchain: opt.toolchain.or(NIGHTLY),
6062
packages: Package::published(),
6163
release: false,
6264
target: None,
@@ -76,7 +78,7 @@ fn run_vm_tests(opt: &QemuOpt) -> Result<()> {
7678
let cargo = Cargo {
7779
action: CargoAction::Build,
7880
features,
79-
nightly: true,
81+
toolchain: opt.toolchain.or(NIGHTLY),
8082
packages: vec![Package::UefiTestRunner],
8183
release: opt.build_mode.release,
8284
target: Some(*opt.target),
@@ -94,7 +96,7 @@ fn run_host_tests() -> Result<()> {
9496
let cargo = Cargo {
9597
action: CargoAction::Test,
9698
features: vec![Feature::Exts],
97-
nightly: true,
99+
toolchain: Some(NIGHTLY.into()),
98100
// Don't test uefi-services (or the packages that depend on it)
99101
// as it has lang items that conflict with `std`.
100102
packages: vec![Package::Uefi, Package::UefiMacros, Package::Xtask],

xtask/src/opt.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ impl Deref for TargetOpt {
2121
}
2222
}
2323

24+
#[derive(Debug, Parser)]
25+
pub struct ToolchainOpt {
26+
/// Rust toolchain to use, e.g. "nightly-2022-02-24".
27+
#[clap(long)]
28+
toolchain: Option<String>,
29+
}
30+
31+
impl ToolchainOpt {
32+
/// Get the toolchain arg if set, otherwise use `default_toolchain`.
33+
pub fn or(&self, default_toolchain: &str) -> Option<String> {
34+
self.toolchain
35+
.clone()
36+
.or_else(|| Some(default_toolchain.to_string()))
37+
}
38+
}
39+
2440
#[derive(Debug, Parser)]
2541
pub struct BuildModeOpt {
2642
/// Build in release mode.
@@ -58,6 +74,9 @@ pub struct BuildOpt {
5874
#[clap(flatten)]
5975
pub target: TargetOpt,
6076

77+
#[clap(flatten)]
78+
pub toolchain: ToolchainOpt,
79+
6180
#[clap(flatten)]
6281
pub build_mode: BuildModeOpt,
6382
}
@@ -68,13 +87,19 @@ pub struct ClippyOpt {
6887
#[clap(flatten)]
6988
pub target: TargetOpt,
7089

90+
#[clap(flatten)]
91+
pub toolchain: ToolchainOpt,
92+
7193
#[clap(flatten)]
7294
pub warning: WarningOpt,
7395
}
7496

7597
/// Build the docs for the uefi packages.
7698
#[derive(Debug, Parser)]
7799
pub struct DocOpt {
100+
#[clap(flatten)]
101+
pub toolchain: ToolchainOpt,
102+
78103
/// Open the docs in a browser.
79104
#[clap(long)]
80105
pub open: bool,
@@ -89,6 +114,9 @@ pub struct QemuOpt {
89114
#[clap(flatten)]
90115
pub target: TargetOpt,
91116

117+
#[clap(flatten)]
118+
pub toolchain: ToolchainOpt,
119+
92120
#[clap(flatten)]
93121
pub build_mode: BuildModeOpt,
94122

0 commit comments

Comments
 (0)