Skip to content

Commit

Permalink
Merge pull request meh#88 from kornelski/crossfix
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski authored Aug 3, 2020
2 parents e871793 + 8f8b0b5 commit a379496
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,19 @@ fn build() -> io::Result<()> {
configure.arg(format!("--prefix={}", search().to_string_lossy()));

if env::var("TARGET").unwrap() != env::var("HOST").unwrap() {
configure.arg(format!("--cross-prefix={}-", env::var("TARGET").unwrap()));
// Rust targets are subtly different than naming scheme for compiler prefixes.
// The cc crate has the messy logic of guessing a working prefix,
// and this is a messy way of reusing that logic.
let cc = cc::Build::new();
let compiler = cc.get_compiler();
let compiler = compiler.path()
.file_stem().unwrap().to_str().unwrap();
let suffix_pos = compiler.rfind('-').unwrap(); // cut off "-gcc"
let prefix = compiler[0..suffix_pos].trim_end_matches("-wr"); // "wr-c++" compiler

configure.arg(format!("--cross-prefix={}-", prefix));
configure.arg(format!("--arch={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap()));
configure.arg(format!("--target_os={}", env::var("CARGO_CFG_TARGET_OS").unwrap()));
}

// control debug build
Expand Down Expand Up @@ -388,7 +400,9 @@ fn check_features(
).expect("Write failed");

let executable = out_dir.join(if cfg!(windows) { "check.exe" } else { "check" });
let mut compiler = cc::Build::new().get_compiler().to_command();
let mut compiler = cc::Build::new()
.target(&env::var("HOST").unwrap()) // don't cross-compile this
.get_compiler().to_command();

for dir in include_paths {
compiler.arg("-I");
Expand Down

0 comments on commit a379496

Please sign in to comment.