Skip to content

The which_freebsd detection is cross-compilation unfriendly #2061

Description

@nagisa

The detection of freebsd version invokes a freebsd-version executable:

libc/build.rs

Lines 122 to 123 in 5f7c6c1

fn which_freebsd() -> Option<i32> {
let output = std::process::Command::new("freebsd-version").output().ok();

however that only meaningfully works when building on a freebsd host. When building on any other host and targeting a freebsd, libc will always default to targeting a freebsd11.0:

libc/build.rs

Lines 26 to 34 in 5f7c6c1

match which_freebsd() {
Some(10) if libc_ci || rustc_dep_of_std => {
println!("cargo:rustc-cfg=freebsd10")
}
Some(11) if libc_ci => println!("cargo:rustc-cfg=freebsd11"),
Some(12) if libc_ci => println!("cargo:rustc-cfg=freebsd12"),
Some(13) if libc_ci => println!("cargo:rustc-cfg=freebsd13"),
Some(_) | None => println!("cargo:rustc-cfg=freebsd11"),
}

Thus making it difficult to e.g.

  • Cross-compile a library or binary that relies on freebsd12.0 or freebsd13.0 APIs;
  • CI test other libraries that rely on freebsd12.0 or freebsd13.0 APIs.

Note that adding a freebsd-version executable to the path is not a very viable solution – some builds running in parallel may target other versions of freebsd too.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugO-bsdS-waiting-on-decisionversion-supportThis is a discussion related to supported versions that may require a decision.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions