From 1b8d4bdf0718bfe4719039ad2d3d53c9f5ccdab5 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 6 Jul 2024 10:56:04 -0700 Subject: [PATCH] Combine all rustflags into cargo --config arg --- src/cargo.rs | 4 ++-- src/manifest.rs | 10 ---------- src/run.rs | 18 ++---------------- src/rustflags.rs | 21 +++------------------ 4 files changed, 7 insertions(+), 46 deletions(-) diff --git a/src/cargo.rs b/src/cargo.rs index 9699638..6609d2f 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -38,10 +38,10 @@ fn cargo(project: &Project) -> Command { let mut cmd = raw_cargo(); cmd.current_dir(&project.dir); cmd.envs(cargo_target_dir(project)); - cmd.envs(rustflags::envs()); + cmd.env_remove("RUSTFLAGS"); cmd.env("CARGO_INCREMENTAL", "0"); cmd.arg("--offline"); - cmd.arg("--config=build.rustflags=[\"--verbose\"]"); + cmd.arg(format!("--config=build.rustflags={}", rustflags::toml())); cmd } diff --git a/src/manifest.rs b/src/manifest.rs index c815c59..6b62a8f 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -60,16 +60,6 @@ pub(crate) struct Bin { #[derive(Serialize, Clone, Debug)] pub(crate) struct Name(pub String); -#[derive(Serialize, Debug)] -pub(crate) struct Config { - pub build: Build, -} - -#[derive(Serialize, Debug)] -pub(crate) struct Build { - pub rustflags: Vec<&'static str>, -} - #[derive(Serialize, Debug)] pub(crate) struct Workspace { #[serde(skip_serializing_if = "Map::is_empty")] diff --git a/src/run.rs b/src/run.rs index 34c4128..b00dd33 100644 --- a/src/run.rs +++ b/src/run.rs @@ -5,10 +5,10 @@ use crate::env::Update; use crate::error::{Error, Result}; use crate::expand::{expand_globs, ExpandedTest}; use crate::flock::Lock; -use crate::manifest::{Bin, Build, Config, Manifest, Name, Package, Workspace}; +use crate::manifest::{Bin, Manifest, Name, Package, Workspace}; use crate::message::{self, Fail, Warn}; use crate::normalize::{self, Context, Variations}; -use crate::{features, rustflags, Expected, Runner, Test}; +use crate::{features, Expected, Runner, Test}; use serde_derive::Deserialize; use std::collections::{BTreeMap as Map, BTreeSet as Set}; use std::env; @@ -182,12 +182,6 @@ impl Runner { fn write(&self, project: &mut Project) -> Result<()> { let manifest_toml = toml::to_string(&project.manifest)?; - - let config = self.make_config(); - let config_toml = toml::to_string(&config)?; - - fs::create_dir_all(path!(project.dir / ".cargo"))?; - fs::write(path!(project.dir / ".cargo" / "config.toml"), config_toml)?; fs::write(path!(project.dir / "Cargo.toml"), manifest_toml)?; let main_rs = b"\ @@ -323,14 +317,6 @@ impl Runner { Ok(manifest) } - fn make_config(&self) -> Config { - Config { - build: Build { - rustflags: rustflags::make_vec(), - }, - } - } - fn run_all(&self, project: &Project, tests: Vec) -> Result { let mut report = Report { failures: 0, diff --git a/src/rustflags.rs b/src/rustflags.rs index c652324..de15903 100644 --- a/src/rustflags.rs +++ b/src/rustflags.rs @@ -1,27 +1,12 @@ -use std::env; -use std::ffi::OsString; - -const RUSTFLAGS: &str = "RUSTFLAGS"; const IGNORED_LINTS: &[&str] = &["dead_code"]; -pub(crate) fn make_vec() -> Vec<&'static str> { - let mut rustflags = vec!["--cfg", "trybuild"]; +pub(crate) fn toml() -> toml::Value { + let mut rustflags = vec!["--cfg", "trybuild", "--verbose"]; for &lint in IGNORED_LINTS { rustflags.push("-A"); rustflags.push(lint); } - rustflags -} - -pub(crate) fn envs() -> impl IntoIterator { - let mut rustflags = env::var_os(RUSTFLAGS)?; - - for flag in make_vec() { - rustflags.push(" "); - rustflags.push(flag); - } - - Some((RUSTFLAGS, rustflags)) + toml::Value::try_from(rustflags).unwrap() }