Skip to content

Commit

Permalink
Enable const extern "C" fn definitions on Rust 1.62.0 and above
Browse files Browse the repository at this point in the history
This was recently stabilized in rust-lang/rust#95346,
and will be included in the 1.62.0 release.

This `const-extern-fn` feature can still be used to enable
these definitions on older compiler versions.
  • Loading branch information
Aaron1011 committed May 10, 2022
1 parent a72d300 commit efd300b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ fn main() {
// Avoid unnecessary re-building.
println!("cargo:rerun-if-changed=build.rs");

let (rustc_minor_ver, is_nightly) = rustc_minor_nightly().expect("Failed to get rustc version");
let (rustc_minor_ver, _is_nightly) =
rustc_minor_nightly().expect("Failed to get rustc version");
let rustc_dep_of_std = env::var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();
let align_cargo_feature = env::var("CARGO_FEATURE_ALIGN").is_ok();
let const_extern_fn_cargo_feature = env::var("CARGO_FEATURE_CONST_EXTERN_FN").is_ok();
Expand Down Expand Up @@ -97,10 +98,8 @@ fn main() {
println!("cargo:rustc-cfg=libc_thread_local");
}

if const_extern_fn_cargo_feature {
if !is_nightly || rustc_minor_ver < 40 {
panic!("const-extern-fn requires a nightly compiler >= 1.40")
}
// Rust >= 1.62.0 allows `const extern "C" fn`
if const_extern_fn_cargo_feature || rustc_minor_ver >= 62 || rustc_dep_of_std {
println!("cargo:rustc-cfg=libc_const_extern_fn");
}
}
Expand Down

0 comments on commit efd300b

Please sign in to comment.