Skip to content

Commit 669bdb0

Browse files
committed
Delegate TARGET identification to target-triple crate
1 parent 7c399e0 commit 669bdb0

3 files changed

Lines changed: 5 additions & 28 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ categories = ["development-tools::testing"]
66
description = "Test harness for ui tests of compiler diagnostics"
77
documentation = "https://docs.rs/trybuild"
88
edition = "2021"
9-
exclude = ["screenshots/*"]
9+
exclude = ["build.rs", "screenshots/*"]
1010
keywords = ["macros", "testing", "dev-dependencies"]
1111
license = "MIT OR Apache-2.0"
1212
repository = "https://github.com/dtolnay/trybuild"
@@ -24,6 +24,7 @@ glob = "0.3"
2424
serde = "1.0.194"
2525
serde_derive = "1.0.194"
2626
serde_json = "1.0.110"
27+
target-triple = "0.1"
2728
termcolor = "1.0.4"
2829
toml = "0.8"
2930

build.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
1-
use std::env;
2-
use std::fs;
3-
use std::io;
4-
use std::path::Path;
1+
fn main() {
2+
// Warning: build.rs is not published to crates.io.
53

6-
fn main() -> io::Result<()> {
74
println!("cargo:rerun-if-changed=src/tests");
8-
95
println!("cargo:rustc-check-cfg=cfg(trybuild_no_target)");
10-
println!("cargo:rustc-check-cfg=cfg(host_os, values(\"windows\"))");
11-
12-
let out_dir = env::var_os("OUT_DIR").unwrap();
13-
let target = env::var("TARGET").unwrap();
14-
let path = Path::new(&out_dir).join("target");
15-
let value = format!(r#""{}""#, target.escape_debug());
16-
fs::write(path, value)?;
17-
18-
let host = env::var_os("HOST").unwrap();
19-
if let Some("windows") = host.to_str().unwrap().split('-').nth(2) {
20-
println!("cargo:rustc-cfg=host_os=\"windows\"");
21-
}
22-
23-
Ok(())
246
}

src/cargo.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,6 @@ fn features(project: &Project) -> Vec<String> {
183183
}
184184

185185
fn target() -> Vec<&'static str> {
186-
#[cfg(not(host_os = "windows"))]
187-
const TARGET: &str = include!(concat!(env!("OUT_DIR"), "/target"));
188-
189-
#[cfg(host_os = "windows")]
190-
const TARGET: &str = include!(concat!(env!("OUT_DIR"), "\\target"));
191-
192186
// When --target flag is passed, cargo does not pass RUSTFLAGS to rustc when
193187
// building proc-macro and build script even if the host and target triples
194188
// are the same. Therefore, if we always pass --target to cargo, tools such
@@ -205,6 +199,6 @@ fn target() -> Vec<&'static str> {
205199
if cfg!(trybuild_no_target) {
206200
vec![]
207201
} else {
208-
vec!["--target", TARGET]
202+
vec!["--target", target_triple::TARGET]
209203
}
210204
}

0 commit comments

Comments
 (0)