Skip to content

Commit 4ebbb84

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 699e017 commit 4ebbb84

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;
@@ -141,7 +144,10 @@ version = "0.0.0"
141144
}
142145
}
143146

144-
cmd.arg("build");
147+
match cargo_mode {
148+
CargoMode::Build => cmd.arg("build"),
149+
CargoMode::Check => cmd.arg("check")
150+
};
145151

146152
match () {
147153
#[cfg(feature = "dev")]
@@ -320,10 +326,19 @@ pub struct Stage {
320326
patch: Table,
321327
}
322328

329+
/// Which mode to invoke `cargo` in when building the sysroot
330+
/// Can be either `cargo build` or `cargo check`
331+
#[derive(Copy, Clone, Debug)]
332+
enum CargoMode {
333+
Build,
334+
Check
335+
}
336+
323337
/// A sysroot that will be built in "stages"
324338
#[derive(Debug)]
325339
pub struct Blueprint {
326340
stages: BTreeMap<i64, Stage>,
341+
cargo_mode: CargoMode
327342
}
328343

329344
trait AsTableMut {
@@ -354,6 +369,7 @@ impl Blueprint {
354369
fn new() -> Self {
355370
Blueprint {
356371
stages: BTreeMap::new(),
372+
cargo_mode: CargoMode::Build
357373
}
358374
}
359375

@@ -408,6 +424,21 @@ impl Blueprint {
408424
Ok(())
409425
}
410426

427+
let mut blueprint = Blueprint::new();
428+
429+
// Get `cargo_mode` from `Xargo.toml`
430+
if let Some(value) = toml.and_then(xargo::Toml::cargo_mode) {
431+
let val = value.as_str()
432+
.ok_or_else(|| format!("`cargo_mode` must be a string"))?;
433+
434+
let mode = match val {
435+
"check" => CargoMode::Check,
436+
"build" => CargoMode::Build,
437+
_ => Err(format!("`cargo_mode` must be either `check` or `build`"))?
438+
};
439+
blueprint.cargo_mode = mode;
440+
}
441+
411442
// Compose patch section
412443
let mut patch = match toml.and_then(xargo::Toml::patch) {
413444
Some(value) => value
@@ -490,7 +521,6 @@ impl Blueprint {
490521
}
491522
};
492523

493-
let mut blueprint = Blueprint::new();
494524
for (k, v) in deps {
495525
if let Value::Table(mut map) = v {
496526
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)