Skip to content

Commit

Permalink
Merge pull request #278 from dtolnay/rustflags
Browse files Browse the repository at this point in the history
Combine all rustflags into cargo `--config` arg
  • Loading branch information
dtolnay committed Jul 6, 2024
2 parents ef6893b + 1b8d4bd commit 207b0a5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 0 additions & 10 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
18 changes: 2 additions & 16 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"\
Expand Down Expand Up @@ -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<ExpandedTest>) -> Result<Report> {
let mut report = Report {
failures: 0,
Expand Down
21 changes: 3 additions & 18 deletions src/rustflags.rs
Original file line number Diff line number Diff line change
@@ -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<Item = (&'static str, OsString)> {
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()
}

0 comments on commit 207b0a5

Please sign in to comment.