Skip to content

Commit 3cce47f

Browse files
authored
Merge pull request #4151 from tgross35/tests-and-const-extern
Ensure all tests in the workspace are run and that `const extern fn` is always enabled
2 parents 42e5708 + e6d7b51 commit 3cce47f

File tree

5 files changed

+29
-39
lines changed

5 files changed

+29
-39
lines changed

Cargo.toml

+1-5
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,10 @@ cargo-args = ["-Zbuild-std=core"]
135135
rustc-std-workspace-core = { version = "1.0.0", optional = true }
136136

137137
[features]
138-
default = ["const-extern-fn", "std"]
138+
default = ["std"]
139139
std = []
140140
rustc-dep-of-std = ["rustc-std-workspace-core"]
141141
extra_traits = []
142142

143-
# `const-extern-function` is deprecated and no longer does anything
144-
# FIXME(1.0): remove this completely
145-
const-extern-fn = []
146-
147143
[workspace]
148144
members = ["libc-test"]

build.rs

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const ALLOWED_CFGS: &'static [&'static str] = &[
1313
"freebsd13",
1414
"freebsd14",
1515
"freebsd15",
16+
// FIXME(ctest): this config shouldn't be needed but ctest can't parse `const extern fn`
17+
"libc_const_extern_fn",
1618
"libc_deny_warnings",
1719
"libc_ctest",
1820
];
@@ -74,6 +76,9 @@ fn main() {
7476
set_cfg("libc_deny_warnings");
7577
}
7678

79+
// Set unconditionally when ctest is not being invoked.
80+
set_cfg("libc_const_extern_fn");
81+
7782
// check-cfg is a nightly cargo/rustc feature to warn when unknown cfgs are used across the
7883
// codebase. libc can configure it if the appropriate environment variable is passed. Since
7984
// rust-lang/rust enforces it, this is useful when using a custom libc fork there.

ci/run.sh

+5-6
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,15 @@ cmd="cargo test --target $target ${LIBC_CI_ZBUILD_STD+"-Zbuild-std"}"
8484

8585
# Run tests in the `libc` crate
8686
case "$target" in
87+
# Only run `libc-test`
8788
# FIXME(android): unit tests fail to start on Android
8889
# FIXME(s390x): unit tests fail to locate glibc
89-
*android*) ;;
90-
*s390x*) ;;
91-
*) $cmd
90+
*android*) cmd="$cmd --manifest-path libc-test/Cargo.toml" ;;
91+
*s390x*) cmd="$cmd --manifest-path libc-test/Cargo.toml" ;;
92+
# For all other platforms, test everything in the workspace
93+
*) cmd="$cmd --workspace"
9294
esac
9395

94-
# Everything else is in `libc-test`
95-
cmd="$cmd --manifest-path libc-test/Cargo.toml"
96-
9796
if [ "$target" = "s390x-unknown-linux-gnu" ]; then
9897
# FIXME: s390x-unknown-linux-gnu often fails to test due to timeout,
9998
# so we retry this N times.

ci/verify-build.sh

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ test_target() {
6262

6363
# Test with expected combinations of features
6464
$cmd
65-
$cmd --features const-extern-fn
6665
$cmd --features extra_traits
6766

6867
# Test again without default features, i.e. without "std"

src/macros.rs

+18-27
Original file line numberDiff line numberDiff line change
@@ -167,40 +167,31 @@ macro_rules! e {
167167
)*);
168168
}
169169

170-
// This is a pretty horrible hack to allow us to conditionally mark
171-
// some functions as 'const', without requiring users of this macro
172-
// to care about the "const-extern-fn" feature.
170+
// This is a pretty horrible hack to allow us to conditionally mark some functions as 'const',
171+
// without requiring users of this macro to care "libc_const_extern_fn".
173172
//
174-
// When 'const-extern-fn' is enabled, we emit the captured 'const' keyword
175-
// in the expanded function.
173+
// When 'libc_const_extern_fn' is enabled, we emit the captured 'const' keyword in the expanded
174+
// function.
176175
//
177-
// When 'const-extern-fn' is disabled, we always emit a plain 'pub unsafe extern fn'.
176+
// When 'libc_const_extern_fn' is disabled, we always emit a plain 'pub unsafe extern fn'.
178177
// Note that the expression matched by the macro is exactly the same - this allows
179-
// users of this macro to work whether or not 'const-extern-fn' is enabled
178+
// users of this macro to work whether or not 'libc_const_extern_fn' is enabled
180179
//
181180
// Unfortunately, we need to duplicate most of this macro between the 'cfg_if' blocks.
182181
// This is because 'const unsafe extern fn' won't even parse on older compilers,
183-
// so we need to avoid emitting it at all of 'const-extern-fn'.
182+
// so we need to avoid emitting it at all of 'libc_const_extern_fn'.
184183
//
185-
// Specifically, moving the 'cfg_if' into the macro body will *not* work.
186-
// Doing so would cause the '#[cfg(feature = "const-extern-fn")]' to be emitted
187-
// into user code. The 'cfg' gate will not stop Rust from trying to parse the
188-
// 'pub const unsafe extern fn', so users would get a compiler error even when
189-
// the 'const-extern-fn' feature is disabled
190-
//
191-
// Note that users of this macro need to place 'const' in a weird position
192-
// (after the closing ')' for the arguments, but before the return type).
193-
// This was the only way I could satisfy the following two requirements:
194-
// 1. Avoid ambiguity errors from 'macro_rules!' (which happen when writing '$foo:ident fn'
195-
// 2. Allow users of this macro to mix 'pub fn foo' and 'pub const fn bar' within the same
196-
// 'f!' block
184+
// Specifically, moving the 'cfg_if' into the macro body will *not* work. Doing so would cause the
185+
// '#[cfg(libc_const_extern_fn)]' to be emitted into user code. The 'cfg' gate will not stop Rust
186+
// from trying to parse the 'pub const unsafe extern fn', so users would get a compiler error even
187+
// when the 'libc_const_extern_fn' feature is disabled.
197188

198189
// FIXME(ctest): ctest can't handle `const extern` functions, we should be able to remove this
199190
// cfg completely.
200191
// FIXME(ctest): ctest can't handle `$(,)?` so we use `$(,)*` which isn't quite correct.
201192
cfg_if! {
202-
if #[cfg(feature = "const-extern-fn")] {
203-
/// Define an `unsafe` function that is const as long as `const-extern-fn` is enabled.
193+
if #[cfg(libc_const_extern_fn)] {
194+
/// Define an `unsafe` function that is const as long as `libc_const_extern_fn` is enabled.
204195
macro_rules! f {
205196
($(
206197
$(#[$attr:meta])*
@@ -214,7 +205,7 @@ cfg_if! {
214205
)*)
215206
}
216207

217-
/// Define a safe function that is const as long as `const-extern-fn` is enabled.
208+
/// Define a safe function that is const as long as `libc_const_extern_fn` is enabled.
218209
macro_rules! safe_f {
219210
($(
220211
$(#[$attr:meta])*
@@ -228,7 +219,7 @@ cfg_if! {
228219
)*)
229220
}
230221

231-
/// A nonpublic function that is const as long as `const-extern-fn` is enabled.
222+
/// A nonpublic function that is const as long as `libc_const_extern_fn` is enabled.
232223
macro_rules! const_fn {
233224
($(
234225
$(#[$attr:meta])*
@@ -242,7 +233,7 @@ cfg_if! {
242233
)*)
243234
}
244235
} else {
245-
/// Define an `unsafe` function that is const as long as `const-extern-fn` is enabled.
236+
/// Define an `unsafe` function that is const as long as `libc_const_extern_fn` is enabled.
246237
macro_rules! f {
247238
($(
248239
$(#[$attr:meta])*
@@ -256,7 +247,7 @@ cfg_if! {
256247
)*)
257248
}
258249

259-
/// Define a safe function that is const as long as `const-extern-fn` is enabled.
250+
/// Define a safe function that is const as long as `libc_const_extern_fn` is enabled.
260251
macro_rules! safe_f {
261252
($(
262253
$(#[$attr:meta])*
@@ -270,7 +261,7 @@ cfg_if! {
270261
)*)
271262
}
272263

273-
/// A nonpublic function that is const as long as `const-extern-fn` is enabled.
264+
/// A nonpublic function that is const as long as `libc_const_extern_fn` is enabled.
274265
macro_rules! const_fn {
275266
($(
276267
$(#[$attr:meta])*

0 commit comments

Comments
 (0)