diff --git a/src/cargo.rs b/src/cargo.rs index 956808b9..96742517 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -38,19 +38,6 @@ impl Cargo { } } -pub(crate) fn config(cargo: &Cargo, workspace_root: &Utf8Path) -> Result { - let s = cargo - .process() - .args(&["-Z", "unstable-options", "config", "get", "--format", "json"]) - .env("RUSTC_BOOTSTRAP", "1") - .dir(workspace_root) - .stderr_capture() - .read()?; - let mut config: Config = serde_json::from_str(&s)?; - config.apply_env()?; - Ok(config) -} - pub(crate) fn locate_project() -> Result { cmd!("cargo", "locate-project", "--message-format", "plain").read() } @@ -190,8 +177,29 @@ pub(crate) fn append_args(cx: &Context, cmd: &mut ProcessBuilder) { // // Refs: // - https://doc.rust-lang.org/nightly/cargo/reference/config.html +// - https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#cargo-config // - https://github.com/rust-lang/cargo/issues/9301 +pub(crate) fn config(cargo: &Cargo, workspace_root: &Utf8Path) -> Result { + let mut config = match cargo + .process() + .args(&["-Z", "unstable-options", "config", "get", "--format", "json"]) + .env("RUSTC_BOOTSTRAP", "1") + .dir(workspace_root) + .stderr_capture() + .read() + { + Ok(s) => serde_json::from_str(&s)?, + Err(e) => { + // Allow error from cargo-config as it is an unstable feature. + warn!("{:#}", e); + Config::default() + } + }; + config.apply_env()?; + Ok(config) +} + #[derive(Debug, Default, Deserialize)] pub(crate) struct Config { #[serde(default)]