Skip to content

Commit

Permalink
Add cargo_mode option to Xargo.toml
Browse files Browse the repository at this point in the history
This allows configuring Xargo to run `cargo check`
instead of `cargo build`

Needed to support rust-lang/miri#1048
  • Loading branch information
Aaron1011 committed Nov 14, 2019
1 parent fd55d41 commit 1bc689f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,21 @@ git = "https://github.com/japaric/steed"
stage = 2
```

## Cargo mode

Xaro supports configuring the mode in which `cargo` is invoked.
The current options are `build` (the default), and `check`. This
is used to determine which `cargo` subcommand will be invoked - either
`build` or `check`.

This is set via the `cargo_mode` entry in `Xargo.toml`:

``` toml
cargo_mode = "check"
```

`build` is almost always what you want.

## Caveats / gotchas

- Xargo won't build a sysroot when used with stable or beta Rust. This is
Expand Down
34 changes: 32 additions & 2 deletions src/sysroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ version = "0.0.0"
}
}

// Copy `cargo_mode` so that we can access it after
// moving out of `blueprint`
let cargo_mode = blueprint.cargo_mode;
for (_, stage) in blueprint.stages {
let td = TempDir::new("xargo").chain_err(|| "couldn't create a temporary directory")?;
let tdp;
Expand Down Expand Up @@ -133,7 +136,10 @@ version = "0.0.0"
}
}

cmd.arg("build");
match cargo_mode {
CargoMode::Build => cmd.arg("build"),
CargoMode::Check => cmd.arg("check")
};

match () {
#[cfg(feature = "dev")]
Expand Down Expand Up @@ -312,10 +318,19 @@ pub struct Stage {
patch: Table,
}

/// Which mode to invoke `cargo` in when building the sysroot
/// Can be either `cargo build` or `cargo check`
#[derive(Copy, Clone, Debug)]
enum CargoMode {
Build,
Check
}

/// A sysroot that will be built in "stages"
#[derive(Debug)]
pub struct Blueprint {
stages: BTreeMap<i64, Stage>,
cargo_mode: CargoMode
}

trait AsTableMut {
Expand Down Expand Up @@ -346,6 +361,7 @@ impl Blueprint {
fn new() -> Self {
Blueprint {
stages: BTreeMap::new(),
cargo_mode: CargoMode::Build
}
}

Expand Down Expand Up @@ -400,6 +416,21 @@ impl Blueprint {
Ok(())
}

let mut blueprint = Blueprint::new();

// Get `cargo_mode` from `Xargo.toml`
if let Some(value) = toml.and_then(xargo::Toml::cargo_mode) {
let val = value.as_str()
.ok_or_else(|| format!("`cargo_mode` must be a string"))?;

let mode = match val {
"check" => CargoMode::Check,
"build" => CargoMode::Build,
_ => Err(format!("`cargo_mode` must be either `check` or `build`"))?
};
blueprint.cargo_mode = mode;
}

// Compose patch section
let mut patch = match toml.and_then(xargo::Toml::patch) {
Some(value) => value
Expand Down Expand Up @@ -482,7 +513,6 @@ impl Blueprint {
}
};

let mut blueprint = Blueprint::new();
for (k, v) in deps {
if let Value::Table(mut map) = v {
let stage = if let Some(value) = map.remove("stage") {
Expand Down
5 changes: 5 additions & 0 deletions src/xargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ impl Toml {
pub fn patch(&self) -> Option<&Value> {
self.table.lookup("patch")
}

/// Returns the `cargo_mode` part of `Xargo.toml`
pub fn cargo_mode(&self) -> Option<&Value> {
self.table.lookup("cargo_mode")
}
}

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

0 comments on commit 1bc689f

Please sign in to comment.