Skip to content

Commit

Permalink
Move TARGET const out of crate root
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 15, 2021
1 parent 0413c5c commit eea765e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
5 changes: 2 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use std::path::Path;
fn main() -> io::Result<()> {
let out_dir = env::var_os("OUT_DIR").unwrap();
let target = env::var("TARGET").ok();
let path = Path::new(&out_dir).join("target.rs");
let path = Path::new(&out_dir).join("target");
let value = match target {
Some(target) => format!(r#"Some("{}")"#, target.escape_debug()),
None => "None".to_owned(),
};
let content = format!("const TARGET: Option<&str> = {};", value);
fs::write(path, content)
fs::write(path, value)
}
2 changes: 1 addition & 1 deletion src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ fn target() -> Vec<&'static str> {
// Therefore, expose a cfg to always treat the target as host.
if cfg!(trybuild_no_target) {
vec![]
} else if let Some(target) = crate::TARGET {
} else if let Some(target) = include!(concat!(env!("OUT_DIR"), "/target")) {
vec!["--target", target]
} else {
vec![]
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ mod normalize;
mod run;
mod rustflags;

include!(concat!(env!("OUT_DIR"), "/target.rs"));

use std::cell::RefCell;
use std::panic::RefUnwindSafe;
use std::path::{Path, PathBuf};
Expand Down

0 comments on commit eea765e

Please sign in to comment.