Skip to content

Commit

Permalink
Auto merge of #2820 - JohnTitor:1-62-const-extern-fn, r=Amanieu
Browse files Browse the repository at this point in the history
Enable `libc_const_extern_fn` implicitly from Rust 1.62

const_extern_fn for "C" has been stabilized since 1.62: rust-lang/rust#95346
This enables the const-extern-fn feature implicitly from 1.62, but leaves the crate feature as-is for compatibility and old nightlies.
Closes #2785
  • Loading branch information
bors committed Jun 9, 2022
2 parents bbf43e8 + 4a84f34 commit 4042ce2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ libc = "0.2"
This feature derives `Debug`, `Eq`, `Hash`, and `PartialEq`.

* `const-extern-fn`: Changes some `extern fn`s into `const extern fn`s.
This feature requires a nightly rustc.
If you use Rust >= 1.62, this feature is implicitly enabled.
Otherwise it requires a nightly rustc.

* **deprecated**: `use_std` is deprecated, and is equivalent to `std`.

Expand All @@ -53,6 +54,7 @@ newer Rust features are only available on newer Rust toolchains:
| `core::ffi::c_void` | 1.30.0 |
| `repr(packed(N))` | 1.33.0 |
| `cfg(target_vendor)` | 1.33.0 |
| `const-extern-fn` | 1.62.0 |

## Platform support

Expand Down
15 changes: 11 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,18 @@ 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 to use `const_extern_fn` for "Rust" and "C".
if rustc_minor_ver >= 62 {
println!("cargo:rustc-cfg=libc_const_extern_fn");
} else {
// Rust < 1.62.0 requires a crate feature and feature gate.
if const_extern_fn_cargo_feature {
if !is_nightly || rustc_minor_ver < 40 {
panic!("const-extern-fn requires a nightly compiler >= 1.40");
}
println!("cargo:rustc-cfg=libc_const_extern_fn_unstable");
println!("cargo:rustc-cfg=libc_const_extern_fn");
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
feature = "rustc-dep-of-std",
feature(native_link_modifiers, native_link_modifiers_bundle)
)]
#![cfg_attr(libc_const_extern_fn, feature(const_extern_fn))]
#![cfg_attr(libc_const_extern_fn_unstable, feature(const_extern_fn))]

#[macro_use]
mod macros;
Expand Down
14 changes: 10 additions & 4 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4682,6 +4682,16 @@ cfg_if! {
const __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1;
p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32
}
} else {
fn __DARWIN_ALIGN32(p: usize) -> usize {
let __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1;
p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32
}
}
}

cfg_if! {
if #[cfg(libc_const_size_of)] {
pub const THREAD_EXTENDED_POLICY_COUNT: mach_msg_type_number_t =
(::mem::size_of::<thread_extended_policy_data_t>() / ::mem::size_of::<integer_t>())
as mach_msg_type_number_t;
Expand Down Expand Up @@ -4722,10 +4732,6 @@ cfg_if! {
(::mem::size_of::<vm_statistics64_data_t>() / ::mem::size_of::<integer_t>())
as mach_msg_type_number_t;
} else {
fn __DARWIN_ALIGN32(p: usize) -> usize {
let __DARWIN_ALIGNBYTES32: usize = ::mem::size_of::<u32>() - 1;
p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32
}
pub const THREAD_EXTENDED_POLICY_COUNT: mach_msg_type_number_t = 1;
pub const THREAD_TIME_CONSTRAINT_POLICY_COUNT: mach_msg_type_number_t = 4;
pub const THREAD_PRECEDENCE_POLICY_COUNT: mach_msg_type_number_t = 1;
Expand Down

0 comments on commit 4042ce2

Please sign in to comment.