Skip to content

Commit

Permalink
Fix --target cflag on FreeBSD when compiling against clang (rust-lang…
Browse files Browse the repository at this point in the history
  • Loading branch information
mqudsi authored Feb 2, 2023
1 parent d247957 commit 1997951
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,23 @@ impl Build {
} else if target.contains("aarch64") {
cmd.args.push("--target=aarch64-unknown-windows-gnu".into())
}
} else if target.ends_with("-freebsd") && self.get_host()?.eq(target) {
// clang <= 13 on FreeBSD doesn't support a target triple without at least
// the major os version number appended; e.g. use x86_64-unknown-freebsd13
// or x86_64-unknown-freebsd13.0 instead of x86_64-unknown-freebsd.
let stdout = std::process::Command::new("freebsd-version")
.output()
.map_err(|e| {
Error::new(
ErrorKind::ToolNotFound,
&format!("Error executing freebsd-version: {}", e),
)
})?
.stdout;
let stdout = String::from_utf8_lossy(&stdout);
let os_ver = stdout.split('-').next().unwrap();

cmd.push_cc_arg(format!("--target={}{}", target, os_ver).into());
} else {
cmd.push_cc_arg(format!("--target={}", target).into());
}
Expand Down

0 comments on commit 1997951

Please sign in to comment.