Skip to content

Commit

Permalink
Enable libc_const_extern_fn implicitly from Rust 1.62
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Jun 8, 2022
1 parent e534fd8 commit 576f778
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 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

4 comments on commit 576f778

@glandium
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change broke building with early 1.62.0 nightlies, e.g. nightly-2022-04-05.

@eddyb
Copy link
Member

@eddyb eddyb commented on 576f778 Aug 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glandium Have you reported an issue? I believe this is now starting to break Rust-GPU CI.

@glandium
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't.

@eddyb
Copy link
Member

@eddyb eddyb commented on 576f778 Aug 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the time I remembered about this again it's been reported and fixed on our end (we just needed to bump our nightly one week for that):

I doubt that libc can/may want to do something about this, especially with so many versions since then, so at this point... sorry for the noise.

Please sign in to comment.