Skip to content

Commit

Permalink
Delegate TARGET identification to target-triple crate
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 18, 2024
1 parent 7c399e0 commit 669bdb0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 28 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ categories = ["development-tools::testing"]
description = "Test harness for ui tests of compiler diagnostics"
documentation = "https://docs.rs/trybuild"
edition = "2021"
exclude = ["screenshots/*"]
exclude = ["build.rs", "screenshots/*"]
keywords = ["macros", "testing", "dev-dependencies"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/dtolnay/trybuild"
Expand All @@ -24,6 +24,7 @@ glob = "0.3"
serde = "1.0.194"
serde_derive = "1.0.194"
serde_json = "1.0.110"
target-triple = "0.1"
termcolor = "1.0.4"
toml = "0.8"

Expand Down
22 changes: 2 additions & 20 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
use std::env;
use std::fs;
use std::io;
use std::path::Path;
fn main() {
// Warning: build.rs is not published to crates.io.

fn main() -> io::Result<()> {
println!("cargo:rerun-if-changed=src/tests");

println!("cargo:rustc-check-cfg=cfg(trybuild_no_target)");
println!("cargo:rustc-check-cfg=cfg(host_os, values(\"windows\"))");

let out_dir = env::var_os("OUT_DIR").unwrap();
let target = env::var("TARGET").unwrap();
let path = Path::new(&out_dir).join("target");
let value = format!(r#""{}""#, target.escape_debug());
fs::write(path, value)?;

let host = env::var_os("HOST").unwrap();
if let Some("windows") = host.to_str().unwrap().split('-').nth(2) {
println!("cargo:rustc-cfg=host_os=\"windows\"");
}

Ok(())
}
8 changes: 1 addition & 7 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,6 @@ fn features(project: &Project) -> Vec<String> {
}

fn target() -> Vec<&'static str> {
#[cfg(not(host_os = "windows"))]
const TARGET: &str = include!(concat!(env!("OUT_DIR"), "/target"));

#[cfg(host_os = "windows")]
const TARGET: &str = include!(concat!(env!("OUT_DIR"), "\\target"));

// When --target flag is passed, cargo does not pass RUSTFLAGS to rustc when
// building proc-macro and build script even if the host and target triples
// are the same. Therefore, if we always pass --target to cargo, tools such
Expand All @@ -205,6 +199,6 @@ fn target() -> Vec<&'static str> {
if cfg!(trybuild_no_target) {
vec![]
} else {
vec!["--target", TARGET]
vec!["--target", target_triple::TARGET]
}
}

0 comments on commit 669bdb0

Please sign in to comment.