Skip to content

Commit 4f1966f

Browse files
committed
Fix FreeBSD build
1 parent d7907c0 commit 4f1966f

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

build.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ fn main() {
77
rustc_minor_version().expect("Failed to get rustc version");
88
let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
99
let align_cargo_feature = env::var("CARGO_FEATURE_ALIGN").is_ok();
10+
#[allow(unused)]
11+
let libc_ci = env::var("LIBC_CI").is_ok();
1012

1113
if env::var("CARGO_FEATURE_USE_STD").is_ok() {
1214
println!(
@@ -15,15 +17,20 @@ fn main() {
1517
);
1618
}
1719

18-
if env::var("LIBC_CI").is_ok() {
19-
if let Some(11) = which_freebsd() {
20-
println!("cargo:rustc-cfg=freebsd11");
21-
}
22-
if let Some(12) = which_freebsd() {
23-
println!("cargo:rustc-cfg=freebsd12");
24-
}
25-
if let Some(13) = which_freebsd() {
26-
println!("cargo:rustc-cfg=freebsd13");
20+
// The ABI of libc is backward compatible with FreeBSD 11.
21+
//
22+
// On CI, we detect the actual FreeBSD version and match its ABI exactly,
23+
// running tests to ensure that the ABI is correct.
24+
#[cfg(target_os = "freebsd")]
25+
match which_freebsd() {
26+
Some(11) if libc_ci => println!("cargo:rustc-cfg=freebsd11"),
27+
Some(12) if libc_ci => println!("cargo:rustc-cfg=freebsd12"),
28+
Some(13) if libc_ci => println!("cargo:rustc-cfg=freebsd13"),
29+
Some(_) => println!("cargo:rustc-cfg=freebsd11"),
30+
None =>
31+
/* not FreeBSD - nothing to do here */
32+
{
33+
()
2734
}
2835
}
2936

@@ -87,6 +94,7 @@ fn rustc_minor_version() -> Option<u32> {
8794
otry!(pieces.next()).parse().ok()
8895
}
8996

97+
#[cfg(target_os = "freebsd")]
9098
fn which_freebsd() -> Option<i32> {
9199
let output = std::process::Command::new("freebsd-version").output().ok();
92100
if output.is_none() {

0 commit comments

Comments
 (0)