Skip to content

Commit 207b0a5

Browse files
authored
Merge pull request #278 from dtolnay/rustflags
Combine all rustflags into cargo `--config` arg
2 parents ef6893b + 1b8d4bd commit 207b0a5

File tree

4 files changed

+7
-46
lines changed

4 files changed

+7
-46
lines changed

src/cargo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ fn cargo(project: &Project) -> Command {
3838
let mut cmd = raw_cargo();
3939
cmd.current_dir(&project.dir);
4040
cmd.envs(cargo_target_dir(project));
41-
cmd.envs(rustflags::envs());
41+
cmd.env_remove("RUSTFLAGS");
4242
cmd.env("CARGO_INCREMENTAL", "0");
4343
cmd.arg("--offline");
44-
cmd.arg("--config=build.rustflags=[\"--verbose\"]");
44+
cmd.arg(format!("--config=build.rustflags={}", rustflags::toml()));
4545
cmd
4646
}
4747

src/manifest.rs

-10
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,6 @@ pub(crate) struct Bin {
6060
#[derive(Serialize, Clone, Debug)]
6161
pub(crate) struct Name(pub String);
6262

63-
#[derive(Serialize, Debug)]
64-
pub(crate) struct Config {
65-
pub build: Build,
66-
}
67-
68-
#[derive(Serialize, Debug)]
69-
pub(crate) struct Build {
70-
pub rustflags: Vec<&'static str>,
71-
}
72-
7363
#[derive(Serialize, Debug)]
7464
pub(crate) struct Workspace {
7565
#[serde(skip_serializing_if = "Map::is_empty")]

src/run.rs

+2-16
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use crate::env::Update;
55
use crate::error::{Error, Result};
66
use crate::expand::{expand_globs, ExpandedTest};
77
use crate::flock::Lock;
8-
use crate::manifest::{Bin, Build, Config, Manifest, Name, Package, Workspace};
8+
use crate::manifest::{Bin, Manifest, Name, Package, Workspace};
99
use crate::message::{self, Fail, Warn};
1010
use crate::normalize::{self, Context, Variations};
11-
use crate::{features, rustflags, Expected, Runner, Test};
11+
use crate::{features, Expected, Runner, Test};
1212
use serde_derive::Deserialize;
1313
use std::collections::{BTreeMap as Map, BTreeSet as Set};
1414
use std::env;
@@ -182,12 +182,6 @@ impl Runner {
182182

183183
fn write(&self, project: &mut Project) -> Result<()> {
184184
let manifest_toml = toml::to_string(&project.manifest)?;
185-
186-
let config = self.make_config();
187-
let config_toml = toml::to_string(&config)?;
188-
189-
fs::create_dir_all(path!(project.dir / ".cargo"))?;
190-
fs::write(path!(project.dir / ".cargo" / "config.toml"), config_toml)?;
191185
fs::write(path!(project.dir / "Cargo.toml"), manifest_toml)?;
192186

193187
let main_rs = b"\
@@ -323,14 +317,6 @@ impl Runner {
323317
Ok(manifest)
324318
}
325319

326-
fn make_config(&self) -> Config {
327-
Config {
328-
build: Build {
329-
rustflags: rustflags::make_vec(),
330-
},
331-
}
332-
}
333-
334320
fn run_all(&self, project: &Project, tests: Vec<ExpandedTest>) -> Result<Report> {
335321
let mut report = Report {
336322
failures: 0,

src/rustflags.rs

+3-18
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
1-
use std::env;
2-
use std::ffi::OsString;
3-
4-
const RUSTFLAGS: &str = "RUSTFLAGS";
51
const IGNORED_LINTS: &[&str] = &["dead_code"];
62

7-
pub(crate) fn make_vec() -> Vec<&'static str> {
8-
let mut rustflags = vec!["--cfg", "trybuild"];
3+
pub(crate) fn toml() -> toml::Value {
4+
let mut rustflags = vec!["--cfg", "trybuild", "--verbose"];
95

106
for &lint in IGNORED_LINTS {
117
rustflags.push("-A");
128
rustflags.push(lint);
139
}
1410

15-
rustflags
16-
}
17-
18-
pub(crate) fn envs() -> impl IntoIterator<Item = (&'static str, OsString)> {
19-
let mut rustflags = env::var_os(RUSTFLAGS)?;
20-
21-
for flag in make_vec() {
22-
rustflags.push(" ");
23-
rustflags.push(flag);
24-
}
25-
26-
Some((RUSTFLAGS, rustflags))
11+
toml::Value::try_from(rustflags).unwrap()
2712
}

0 commit comments

Comments
 (0)