Skip to content

Commit

Permalink
fixup! Fix --target cflag on FreeBSD when compiling against clang
Browse files Browse the repository at this point in the history
* Use `freebsd-version` instead of `uname`. This returns the currently installed
  userland version, which is a closer match to the desired target triple than
  the running kernel version.
* Only match `freebsd-vesion` or `uname` version output if we are compiling to
  the same target as the running host.
* Properly return errors.
  • Loading branch information
mqudsi committed Feb 2, 2023
1 parent cdc3a37 commit 0e9373f
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1722,19 +1722,22 @@ impl Build {
} else if target.contains("aarch64") {
cmd.args.push("--target=aarch64-unknown-windows-gnu".into())
}
} else if target.ends_with("-freebsd") {
// 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
// instead of x86-64-unknown-freebsd
let uname_r = String::from_utf8(
std::process::Command::new("uname")
.args(&["-r"])
.output()
.expect("Failed to execute uname!")
.stdout,
)
.expect("Failure parsing uname output as UTF-8!");
let os_ver = uname_r.as_str().split('-').next().unwrap();
} 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 0e9373f

Please sign in to comment.