Skip to content

Commit 86a692e

Browse files
committed
Add cargo_mode option to Xargo.toml
This allows configuring Xargo to run `cargo check` instead of `cargo build` Needed to support rust-lang/miri#1048
1 parent d1d7606 commit 86a692e

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,21 @@ git = "https://github.com/japaric/steed"
309309
stage = 2
310310
```
311311

312+
## Cargo mode
313+
314+
Xaro supports configuring the mode in which `cargo` is invoked.
315+
The current options are `build` (the default), and `check`. This
316+
is used to determine which `cargo` subcommand will be invoked - either
317+
`build` or `check`.
318+
319+
This is set via the `cargo_mode` entry in `Xargo.toml`:
320+
321+
``` toml
322+
cargo_mode = "check"
323+
```
324+
325+
`build` is almost always what you want.
326+
312327
## Caveats / gotchas
313328

314329
- Xargo won't build a sysroot when used with stable or beta Rust. This is

src/sysroot.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ version = "0.0.0"
7676
}
7777
}
7878

79+
// Copy `cargo_mode` so that we can access it after
80+
// moving out of `blueprint`
81+
let cargo_mode = blueprint.cargo_mode;
7982
for (_, stage) in blueprint.stages {
8083
let td = TempDir::new("xargo").chain_err(|| "couldn't create a temporary directory")?;
8184
let tdp;
@@ -165,7 +168,10 @@ version = "0.0.0"
165168
}
166169
}
167170

168-
cmd.arg("build");
171+
match cargo_mode {
172+
CargoMode::Build => cmd.arg("build"),
173+
CargoMode::Check => cmd.arg("check")
174+
};
169175

170176
match () {
171177
#[cfg(feature = "dev")]
@@ -344,10 +350,19 @@ pub struct Stage {
344350
patch: Table,
345351
}
346352

353+
/// Which mode to invoke `cargo` in when building the sysroot
354+
/// Can be either `cargo build` or `cargo check`
355+
#[derive(Copy, Clone, Debug)]
356+
enum CargoMode {
357+
Build,
358+
Check
359+
}
360+
347361
/// A sysroot that will be built in "stages"
348362
#[derive(Debug)]
349363
pub struct Blueprint {
350364
stages: BTreeMap<i64, Stage>,
365+
cargo_mode: CargoMode
351366
}
352367

353368
trait AsTableMut {
@@ -378,6 +393,7 @@ impl Blueprint {
378393
fn new() -> Self {
379394
Blueprint {
380395
stages: BTreeMap::new(),
396+
cargo_mode: CargoMode::Build
381397
}
382398
}
383399

@@ -432,6 +448,21 @@ impl Blueprint {
432448
Ok(())
433449
}
434450

451+
let mut blueprint = Blueprint::new();
452+
453+
// Get `cargo_mode` from `Xargo.toml`
454+
if let Some(value) = toml.and_then(xargo::Toml::cargo_mode) {
455+
let val = value.as_str()
456+
.ok_or_else(|| format!("`cargo_mode` must be a string"))?;
457+
458+
let mode = match val {
459+
"check" => CargoMode::Check,
460+
"build" => CargoMode::Build,
461+
_ => Err(format!("`cargo_mode` must be either `check` or `build`"))?
462+
};
463+
blueprint.cargo_mode = mode;
464+
}
465+
435466
// Compose patch section
436467
let mut patch = match toml.and_then(xargo::Toml::patch) {
437468
Some(value) => value
@@ -514,7 +545,6 @@ impl Blueprint {
514545
}
515546
};
516547

517-
let mut blueprint = Blueprint::new();
518548
for (k, v) in deps {
519549
if let Value::Table(mut map) = v {
520550
let stage = if let Some(value) = map.remove("stage") {

src/xargo.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ impl Toml {
118118
pub fn patch(&self) -> Option<&Value> {
119119
self.table.lookup("patch")
120120
}
121+
122+
/// Returns the `cargo_mode` part of `Xargo.toml`
123+
pub fn cargo_mode(&self) -> Option<&Value> {
124+
self.table.lookup("cargo_mode")
125+
}
121126
}
122127

123128
/// Returns the closest directory containing a 'Xargo.toml' and the parsed

0 commit comments

Comments
 (0)