Skip to content

Commit

Permalink
fix: Ensure that const extern fn is always enabled
Browse files Browse the repository at this point in the history
In [1] this conditional was dropped in favor of a Cargo feature, which
was turned on by default in [2].

Fixes: rust-lang#4149

[1]: rust-lang#4105
[2]: rust-lang#4134
  • Loading branch information
tgross35 committed Nov 26, 2024
1 parent f553033 commit 6d00234
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,10 @@ cargo-args = ["-Zbuild-std=core"]
rustc-std-workspace-core = { version = "1.0.0", optional = true }

[features]
default = ["const-extern-fn", "std"]
default = ["std"]
std = []
rustc-dep-of-std = ["rustc-std-workspace-core"]
extra_traits = []

# `const-extern-function` is deprecated and no longer does anything
# FIXME(1.0): remove this completely
const-extern-fn = []

[workspace]
members = ["libc-test"]
4 changes: 4 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
"freebsd13",
"freebsd14",
"freebsd15",
// FIXME(ctest): this config shouldn't be needed but ctest can't parse `const extern fn`
"libc_const_extern_fn",
"libc_deny_warnings",
"libc_ctest",
];
Expand Down Expand Up @@ -74,6 +76,8 @@ fn main() {
set_cfg("libc_deny_warnings");
}

set_cfg("libc_const_extern_fn");

// check-cfg is a nightly cargo/rustc feature to warn when unknown cfgs are used across the
// codebase. libc can configure it if the appropriate environment variable is passed. Since
// rust-lang/rust enforces it, this is useful when using a custom libc fork there.
Expand Down
3 changes: 2 additions & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ macro_rules! e {
// cfg completely.
// FIXME(ctest): ctest can't handle `$(,)?` so we use `$(,)*` which isn't quite correct.
cfg_if! {
if #[cfg(feature = "const-extern-fn")] {
if #[cfg(libc_const_extern_fn)] {
// if #[cfg(feature = "const-extern-fn")] {
/// Define an `unsafe` function that is const as long as `const-extern-fn` is enabled.
macro_rules! f {
($(
Expand Down

0 comments on commit 6d00234

Please sign in to comment.