Skip to content

Commit 1bc689f

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 fd55d41 commit 1bc689f

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;
@@ -133,7 +136,10 @@ version = "0.0.0"
133136
}
134137
}
135138

136-
cmd.arg("build");
139+
match cargo_mode {
140+
CargoMode::Build => cmd.arg("build"),
141+
CargoMode::Check => cmd.arg("check")
142+
};
137143

138144
match () {
139145
#[cfg(feature = "dev")]
@@ -312,10 +318,19 @@ pub struct Stage {
312318
patch: Table,
313319
}
314320

321+
/// Which mode to invoke `cargo` in when building the sysroot
322+
/// Can be either `cargo build` or `cargo check`
323+
#[derive(Copy, Clone, Debug)]
324+
enum CargoMode {
325+
Build,
326+
Check
327+
}
328+
315329
/// A sysroot that will be built in "stages"
316330
#[derive(Debug)]
317331
pub struct Blueprint {
318332
stages: BTreeMap<i64, Stage>,
333+
cargo_mode: CargoMode
319334
}
320335

321336
trait AsTableMut {
@@ -346,6 +361,7 @@ impl Blueprint {
346361
fn new() -> Self {
347362
Blueprint {
348363
stages: BTreeMap::new(),
364+
cargo_mode: CargoMode::Build
349365
}
350366
}
351367

@@ -400,6 +416,21 @@ impl Blueprint {
400416
Ok(())
401417
}
402418

419+
let mut blueprint = Blueprint::new();
420+
421+
// Get `cargo_mode` from `Xargo.toml`
422+
if let Some(value) = toml.and_then(xargo::Toml::cargo_mode) {
423+
let val = value.as_str()
424+
.ok_or_else(|| format!("`cargo_mode` must be a string"))?;
425+
426+
let mode = match val {
427+
"check" => CargoMode::Check,
428+
"build" => CargoMode::Build,
429+
_ => Err(format!("`cargo_mode` must be either `check` or `build`"))?
430+
};
431+
blueprint.cargo_mode = mode;
432+
}
433+
403434
// Compose patch section
404435
let mut patch = match toml.and_then(xargo::Toml::patch) {
405436
Some(value) => value
@@ -482,7 +513,6 @@ impl Blueprint {
482513
}
483514
};
484515

485-
let mut blueprint = Blueprint::new();
486516
for (k, v) in deps {
487517
if let Value::Table(mut map) = v {
488518
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)