Skip to content

Commit 1997951

Browse files
authored
Fix --target cflag on FreeBSD when compiling against clang (#785)
Closes #463
1 parent d247957 commit 1997951

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,23 @@ impl Build {
17201720
} else if target.contains("aarch64") {
17211721
cmd.args.push("--target=aarch64-unknown-windows-gnu".into())
17221722
}
1723+
} else if target.ends_with("-freebsd") && self.get_host()?.eq(target) {
1724+
// clang <= 13 on FreeBSD doesn't support a target triple without at least
1725+
// the major os version number appended; e.g. use x86_64-unknown-freebsd13
1726+
// or x86_64-unknown-freebsd13.0 instead of x86_64-unknown-freebsd.
1727+
let stdout = std::process::Command::new("freebsd-version")
1728+
.output()
1729+
.map_err(|e| {
1730+
Error::new(
1731+
ErrorKind::ToolNotFound,
1732+
&format!("Error executing freebsd-version: {}", e),
1733+
)
1734+
})?
1735+
.stdout;
1736+
let stdout = String::from_utf8_lossy(&stdout);
1737+
let os_ver = stdout.split('-').next().unwrap();
1738+
1739+
cmd.push_cc_arg(format!("--target={}{}", target, os_ver).into());
17231740
} else {
17241741
cmd.push_cc_arg(format!("--target={}", target).into());
17251742
}

0 commit comments

Comments
 (0)