From 1bc689f599d525ef67492dabb812df8c6008390a Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Wed, 13 Nov 2019 19:02:26 -0500 Subject: [PATCH] Add `cargo_mode` option to `Xargo.toml` This allows configuring Xargo to run `cargo check` instead of `cargo build` Needed to support https://github.com/rust-lang/miri/pull/1048 --- README.md | 15 +++++++++++++++ src/sysroot.rs | 34 ++++++++++++++++++++++++++++++++-- src/xargo.rs | 5 +++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 65facb0..b3b8f0f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/sysroot.rs b/src/sysroot.rs index 4e78e94..fa51d11 100644 --- a/src/sysroot.rs +++ b/src/sysroot.rs @@ -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; @@ -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")] @@ -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, + cargo_mode: CargoMode } trait AsTableMut { @@ -346,6 +361,7 @@ impl Blueprint { fn new() -> Self { Blueprint { stages: BTreeMap::new(), + cargo_mode: CargoMode::Build } } @@ -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 @@ -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") { diff --git a/src/xargo.rs b/src/xargo.rs index c56d203..5dd65d3 100644 --- a/src/xargo.rs +++ b/src/xargo.rs @@ -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