diff --git a/Cargo.lock b/Cargo.lock index 879a09fa7..539d1ca0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -350,6 +350,18 @@ dependencies = [ "serde_core", ] +[[package]] +name = "cargo-config2" +version = "0.1.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3795d3a48839a46854805f56c8fe9c558f10804bcf57df53925ca843d87c788f" +dependencies = [ + "serde", + "serde_derive", + "toml", + "windows-sys 0.61.0", +] + [[package]] name = "cargo-dist" version = "0.30.2" @@ -364,6 +376,7 @@ dependencies = [ "base64", "blake2", "camino", + "cargo-config2", "cargo-dist-schema", "cargo-wix", "cargo_metadata 0.23.0", diff --git a/cargo-dist/Cargo.toml b/cargo-dist/Cargo.toml index 933d6c47c..3e99072a6 100644 --- a/cargo-dist/Cargo.toml +++ b/cargo-dist/Cargo.toml @@ -72,6 +72,7 @@ current_platform.workspace = true color-backtrace.workspace = true backtrace.workspace = true schemars.workspace = true +cargo-config2 = "0.1.36" [dev-dependencies] insta.workspace = true diff --git a/cargo-dist/src/build/cargo.rs b/cargo-dist/src/build/cargo.rs index c3d0be405..fbfd6c579 100644 --- a/cargo-dist/src/build/cargo.rs +++ b/cargo-dist/src/build/cargo.rs @@ -70,7 +70,22 @@ impl<'a> DistGraphBuilder<'a> { let mut builds = vec![]; for (target_triple, binaries) in targets { let target = target_triple.parse()?; - let mut rustflags = std::env::var("RUSTFLAGS").unwrap_or_default(); + + // If RUSTFLAGS is set, use that. + // Otherwise, read .cargo/config.toml. + let mut rustflags = match std::env::var("RUSTFLAGS") { + Ok(rustflags) => rustflags, + Err(_) => { + let config = cargo_config2::Config::load()?; + let flags = config + .rustflags(target_triple.as_str())? + .unwrap_or_default(); + // Convert from Vec to a single space-separated String. + flags.flags.join(" ") + } + }; + + // let mut rustflags = std::env::var("RUSTFLAGS").unwrap_or_default(); // FIXME: is there a more principled way for us to add things to RUSTFLAGS // without breaking everything. Cargo has some builtin ways like keys diff --git a/cargo-dist/src/errors.rs b/cargo-dist/src/errors.rs index 33f496277..50d6b2ef0 100644 --- a/cargo-dist/src/errors.rs +++ b/cargo-dist/src/errors.rs @@ -69,6 +69,10 @@ pub enum DistError { #[error(transparent)] TripleError(#[from] cargo_dist_schema::target_lexicon::ParseError), + /// random cargo_config2 error + #[error(transparent)] + ConfigError(#[from] cargo_config2::Error), + /// A problem with a jinja template, which is always a dist bug #[error("Failed to render template")] #[diagnostic(