Skip to content

Commit fba2456

Browse files
committed
fixup! Fix --target cflag on FreeBSD when compiling against clang
* 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.
1 parent cdc3a37 commit fba2456

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/lib.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,19 +1722,22 @@ impl Build {
17221722
} else if target.contains("aarch64") {
17231723
cmd.args.push("--target=aarch64-unknown-windows-gnu".into())
17241724
}
1725-
} else if target.ends_with("-freebsd") {
1726-
// clang 13 on FreeBSD doesn't support a target triple without at least the
1727-
// major os version number appended; e.g. use x86_64-unknown-freebsd13
1725+
} else if target.ends_with("-freebsd") && self.get_host()?.eq(target) {
1726+
// clang <= 13 on FreeBSD doesn't support a target triple without at least
1727+
// the major os version number appended; e.g. use x86_64-unknown-freebsd13
17281728
// instead of x86-64-unknown-freebsd
1729-
let uname_r = String::from_utf8(
1730-
std::process::Command::new("uname")
1731-
.args(&["-r"])
1732-
.output()
1733-
.expect("Failed to execute uname!")
1734-
.stdout,
1735-
)
1736-
.expect("Failure parsing uname output as UTF-8!");
1737-
let os_ver = uname_r.as_str().split('-').next().unwrap();
1729+
let stdout = std::process::Command::new("freebsd-version")
1730+
.output()
1731+
.map_err(|e| {
1732+
Error::new(
1733+
ErrorKind::ToolNotFound,
1734+
&format!("Error executing freebsd-version: {}", e),
1735+
)
1736+
})?
1737+
.stdout;
1738+
let stdout = String::from_utf8_lossy(&stdout);
1739+
let os_ver = stdout.split('-').next().unwrap();
1740+
17381741
cmd.push_cc_arg(format!("--target={}{}", target, os_ver).into());
17391742
} else {
17401743
cmd.push_cc_arg(format!("--target={}", target).into());

0 commit comments

Comments
 (0)