Skip to content

Commit

Permalink
Expose cfg to always treat target as host
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Aug 10, 2021
1 parent a1f6303 commit 48db84d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ fn main() -> io::Result<()> {
Some(target) => format!(r#"Some("{}")"#, target.escape_debug()),
None => "None".to_owned(),
};
let content = format!("const TARGET: Option<&'static str> = {};", value);
let content = format!("const TARGET: Option<&str> = {};", value);
fs::write(path, content)
}
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,22 @@ mod normalize;
mod run;
mod rustflags;

// 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 as
// coverage that require RUSTFLAGS do not work for tests run by trybuild.
//
// To avoid that problem, do not pass --target to cargo if we know that it has
// not been passed.
//
// Currently, cargo does not have a way to tell the build script whether
// --target has been passed or not, and there is no heuristic that can handle
// this well.
//
// Therefore, expose a cfg to always treat the target as host.
#[cfg(trybuild_no_target)]
const TARGET: Option<&str> = None;
#[cfg(not(trybuild_no_target))]
include!(concat!(env!("OUT_DIR"), "/target.rs"));

use std::cell::RefCell;
Expand Down

0 comments on commit 48db84d

Please sign in to comment.