Skip to content

Commit d0c7c35

Browse files
committed
fs: emit compilation error without 'tokio_unstable' for 'io-uring'
Signed-off-by: ADD-SP <qiqi.zhang@konghq.com>
1 parent 3b5a15d commit d0c7c35

File tree

4 files changed

+80
-53
lines changed

4 files changed

+80
-53
lines changed

.cirrus.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ env:
66
RUST_STABLE: stable
77
RUST_NIGHTLY: nightly-2025-01-25
88
RUSTFLAGS: -D warnings
9+
# This excludes unstable features like io_uring, which require '--cfg tokio_unstable'.
10+
TOKIO_STABLE_FEATURES: full,test-util
911

1012
# Test FreeBSD in a full VM on cirrus-ci.com. Test the i686 target too, in the
1113
# same VM. The binary will be built in 32-bit mode, but will execute on a
@@ -23,7 +25,13 @@ task:
2325
rustc --version
2426
test_script:
2527
- . $HOME/.cargo/env
26-
- cargo test --all --all-features
28+
- cargo test --all --features $TOKIO_STABLE_FEATURES
29+
# Free the disk space before the next build,
30+
# otherwise cirrus-ci complains about "No space left on device".
31+
- cargo clean
32+
# Enable all unstable features, including io_uring, because it supports
33+
# x86_64 FreeBSD.
34+
- RUSTFLAGS="$RUSTFLAGS --cfg tokio_unstable" RUSTDOCFLAGS="$RUSTDOCFLAGS --cfg tokio_unstable" cargo test --all --all-features
2735

2836
task:
2937
name: FreeBSD docs
@@ -55,4 +63,4 @@ task:
5563
rustc --version
5664
test_script:
5765
- . $HOME/.cargo/env
58-
- cargo test --all --all-features --target i686-unknown-freebsd
66+
- cargo test --all --features $TOKIO_STABLE_FEATURES --target i686-unknown-freebsd

.github/workflows/ci.yml

Lines changed: 64 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ env:
2929
# - tokio-test/Cargo.toml
3030
# - tokio-stream/Cargo.toml
3131
rust_min: '1.70'
32+
# This excludes unstable features like io_uring,
33+
# which require '--cfg tokio_unstable'.
34+
TOKIO_STABLE_FEATURES: "full,test-util"
3235

3336
defaults:
3437
run:
@@ -73,15 +76,13 @@ jobs:
7376

7477
- uses: Swatinem/rust-cache@v2
7578

76-
# Run `tokio` with `full` features. This excludes testing utilities which
79+
# Run `tokio` with stable features. This excludes testing utilities which
7780
# can alter the runtime behavior of Tokio.
7881
- name: test tokio full
7982
run: |
8083
set -euxo pipefail
81-
# We use `--features "full,test-util"` instead of `--all-features` since
82-
# `--all-features` includes `io_uring`, which is not available on all targets.
83-
cargo nextest run --features full,test-util
84-
cargo test --doc --features full,test-util
84+
cargo nextest run --features full
85+
cargo test --doc --features full
8586
working-directory: tokio
8687

8788
test-workspace-all-features:
@@ -107,12 +108,11 @@ jobs:
107108

108109
- uses: Swatinem/rust-cache@v2
109110

110-
# Test **all** crates in the workspace with all features.
111-
- name: test all --all-features
111+
- name: test --features ${{ env.TOKIO_STABLE_FEATURES }}
112112
run: |
113113
set -euxo pipefail
114-
cargo nextest run --workspace --all-features
115-
cargo test --doc --workspace --all-features
114+
cargo nextest run --workspace --features $TOKIO_STABLE_FEATURES
115+
cargo test --doc --workspace --features $TOKIO_STABLE_FEATURES
116116
117117
test-workspace-all-features-panic-abort:
118118
needs: basics
@@ -137,10 +137,15 @@ jobs:
137137

138138
- uses: Swatinem/rust-cache@v2
139139

140-
- name: test all --all-features panic=abort
140+
- name: test --features ${{ env.TOKIO_STABLE_FEATURES }} panic=abort
141141
run: |
142142
set -euxo pipefail
143-
RUSTFLAGS="$RUSTFLAGS -C panic=abort -Zpanic-abort-tests" cargo nextest run --workspace --exclude tokio-macros --exclude tests-build --all-features --tests
143+
RUSTFLAGS="$RUSTFLAGS -C panic=abort -Zpanic-abort-tests" cargo nextest run \
144+
--workspace \
145+
--exclude tokio-macros \
146+
--exclude tests-build \
147+
--features $TOKIO_STABLE_FEATURES \
148+
--tests
144149
145150
test-integration-tests-per-feature:
146151
needs: basics
@@ -204,8 +209,9 @@ jobs:
204209
run: sed -i '/\[features\]/a plsend = ["parking_lot/send_guard"]' tokio/Cargo.toml
205210

206211
- uses: Swatinem/rust-cache@v2
207-
- name: Check tests with all features enabled
208-
run: cargo check --workspace --all-features --tests
212+
213+
- name: Check tests --unstable --features ${{ env.TOKIO_STABLE_FEATURES }}
214+
run: cargo check --workspace --tests --features $TOKIO_STABLE_FEATURES
209215

210216
valgrind:
211217
name: valgrind
@@ -247,12 +253,11 @@ jobs:
247253
strategy:
248254
matrix:
249255
include:
250-
# We use `--features "full,test-util"` instead of `--all-features` since
251-
# `--all-features` includes `io_uring`, which is not available on all targets.
252-
- { os: windows-latest, features: "full,test-util" }
253-
- { os: ubuntu-latest, features: "full,test-util" }
254-
- { os: ubuntu-latest, features: "full,test-util,io-uring" }
255-
- { os: macos-latest, features: "full,test-util" }
256+
- { os: windows-latest, extra_features: "" }
257+
- { os: ubuntu-latest, extra_features: "" }
258+
# only Linux supports io_uring
259+
- { os: ubuntu-latest, extra_features: io-uring }
260+
- { os: macos-latest, extra_features: "" }
256261
steps:
257262
- uses: actions/checkout@v5
258263
- name: Install Rust ${{ env.rust_stable }}
@@ -270,8 +275,8 @@ jobs:
270275
- name: test tokio full --cfg unstable
271276
run: |
272277
set -euxo pipefail
273-
cargo nextest run --features ${{ matrix.features }}
274-
cargo test --doc --features ${{ matrix.features }}
278+
cargo nextest run --features $TOKIO_STABLE_FEATURES,${{ matrix.extra_features }}
279+
cargo test --doc --features $TOKIO_STABLE_FEATURES,${{ matrix.extra_features }}
275280
working-directory: tokio
276281
env:
277282
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
@@ -304,8 +309,11 @@ jobs:
304309
- name: test tokio full --cfg unstable --cfg taskdump
305310
run: |
306311
set -euxo pipefail
307-
cargo nextest run --all-features
308-
cargo test --doc --all-features
312+
# taskdump is an unstable feature, but it can only be enabled
313+
# by --cfg tokio_taskdump, not by a feature flag, so we can
314+
# use $TOKIO_STABLE_FEATURES here.
315+
cargo nextest run --features $TOKIO_STABLE_FEATURES
316+
cargo test --doc --features $TOKIO_STABLE_FEATURES
309317
working-directory: tokio
310318
env:
311319
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings
@@ -336,8 +344,11 @@ jobs:
336344
- name: check tokio full --cfg unstable --cfg internal-mt-counters
337345
run: |
338346
set -euxo pipefail
339-
cargo nextest run --all-features
340-
cargo test --doc --all-features
347+
# taskdump is an unstable feature, but it can only be enabled
348+
# by --cfg tokio_taskdump, not by a feature flag, so we can
349+
# use $TOKIO_STABLE_FEATURES here.
350+
cargo nextest run --features $TOKIO_STABLE_FEATURES
351+
cargo test --doc --features $TOKIO_STABLE_FEATURES
341352
working-directory: tokio
342353
env:
343354
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_internal_mt_counters -Dwarnings
@@ -405,7 +416,7 @@ jobs:
405416
- uses: Swatinem/rust-cache@v2
406417
- name: miri-doc-test
407418
run: |
408-
cargo miri test --doc --all-features --no-fail-fast
419+
cargo miri test --doc --features $TOKIO_STABLE_FEATURES --no-fail-fast
409420
working-directory: tokio
410421
env:
411422
MIRIFLAGS: -Zmiri-disable-isolation -Zmiri-strict-provenance -Zmiri-retag-fields
@@ -426,7 +437,7 @@ jobs:
426437

427438
- uses: Swatinem/rust-cache@v2
428439
- name: asan
429-
run: cargo test --workspace --all-features --target x86_64-unknown-linux-gnu --tests -- --test-threads 1 --nocapture
440+
run: cargo test --workspace --features $TOKIO_STABLE_FEATURES --target x86_64-unknown-linux-gnu --tests -- --test-threads 1 --nocapture
430441
env:
431442
RUSTFLAGS: -Z sanitizer=address --cfg tokio_no_tuning_tests
432443
# Ignore `trybuild` errors as they are irrelevant and flaky on nightly
@@ -444,6 +455,9 @@ jobs:
444455
rust-toolchain: ${{ env.rust_stable }}
445456
package: tokio
446457
release-type: minor
458+
feature-group: only-explicit-features
459+
# We don't care about the semver of unstable tokio features.
460+
features: ${{ env.TOKIO_STABLE_FEATURES }}
447461
- name: Check semver for rest of the workspace
448462
if: ${{ !startsWith(github.event.pull_request.base.ref, 'tokio-1.') }}
449463
uses: obi1kenobi/cargo-semver-checks-action@v2
@@ -669,9 +683,9 @@ jobs:
669683
strategy:
670684
matrix:
671685
include:
672-
- { name: "", rustflags: "" }
673-
- { name: "--unstable", rustflags: "--cfg tokio_unstable -Dwarnings" }
674-
- { name: "--unstable --taskdump", rustflags: "--cfg tokio_unstable -Dwarnings --cfg tokio_taskdump" }
686+
- { name: "", rustflags: "", exclude_features: "io-uring" }
687+
- { name: "--unstable", rustflags: "--cfg tokio_unstable -Dwarnings", exclude_features: "" }
688+
- { name: "--unstable --taskdump", rustflags: "--cfg tokio_unstable -Dwarnings --cfg tokio_taskdump", exclude_features: "" }
675689
steps:
676690
- uses: actions/checkout@v5
677691
- name: Install Rust ${{ env.rust_nightly }}
@@ -684,7 +698,7 @@ jobs:
684698

685699
- uses: Swatinem/rust-cache@v2
686700
- name: check --feature-powerset ${{ matrix.name }}
687-
run: cargo hack check --all --feature-powerset --depth 2 --keep-going
701+
run: cargo hack check --all --feature-powerset --exclude-features "${{ matrix.exclude_features }}" --depth 2 --keep-going
688702
env:
689703
RUSTFLAGS: ${{ matrix.rustflags }}
690704

@@ -698,17 +712,19 @@ jobs:
698712
with:
699713
toolchain: ${{ env.rust_min }}
700714
- uses: Swatinem/rust-cache@v2
701-
- name: "check --workspace --all-features"
715+
- name: "cargo check"
702716
run: |
703717
if [[ "${{ github.event.pull_request.base.ref }}" =~ ^tokio-1\..* ]]; then
704718
# Only check `tokio` crate as the PR is backporting to an earlier tokio release.
705-
cargo check -p tokio --all-features
719+
720+
cargo check -p tokio --features $TOKIO_STABLE_FEATURES
706721
else
707722
# Check all crates in the workspace
708-
cargo check --workspace --all-features
723+
724+
cargo check -p tokio --features $TOKIO_STABLE_FEATURES
725+
# Other crates doesn't have unstable features, so we can use --all-features.
726+
cargo check -p tokio-macros -p tokio-stream -p tokio-util -p tokio-test --all-features
709727
fi
710-
env:
711-
RUSTFLAGS: "" # remove -Dwarnings
712728
713729
minimal-versions:
714730
name: minimal-versions
@@ -724,14 +740,17 @@ jobs:
724740
uses: taiki-e/install-action@cargo-hack
725741

726742
- uses: Swatinem/rust-cache@v2
727-
- name: "check --all-features -Z minimal-versions"
743+
- name: "check -Z minimal-versions"
728744
run: |
729745
# Remove dev-dependencies from Cargo.toml to prevent the next `cargo update`
730746
# from determining minimal versions based on dev-dependencies.
731747
cargo hack --remove-dev-deps --workspace
732748
# Update Cargo.lock to minimal version dependencies.
733749
cargo update -Z minimal-versions
734-
cargo hack check --all-features --ignore-private
750+
# We use `--features "full,test-util"` instead of `--all-features` since
751+
# `--all-features` includes `io_uring`, which requires '--cfg tokio_unstable'.
752+
cargo hack check -p tokio --features full,test-util --ignore-private
753+
cargo hack check -p tokio-macros -p tokio-stream -p tokio-util -p tokio-test --all-features --ignore-private
735754
- name: "check --all-features --unstable -Z minimal-versions"
736755
env:
737756
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings
@@ -766,11 +785,6 @@ jobs:
766785
clippy:
767786
name: clippy
768787
runs-on: ubuntu-latest
769-
strategy:
770-
matrix:
771-
rustflags:
772-
- ""
773-
- "--cfg tokio_unstable --cfg tokio_taskdump -Dwarnings"
774788
steps:
775789
- uses: actions/checkout@v5
776790
- name: Install Rust ${{ env.rust_clippy }}
@@ -780,10 +794,12 @@ jobs:
780794
components: clippy
781795
- uses: Swatinem/rust-cache@v2
782796
# Run clippy
783-
- name: "clippy --all ${{ matrix.rustflags }}"
784-
run: cargo clippy --all --tests --all-features --no-deps
797+
- name: "clippy --all --features ${{ env.TOKIO_STABLE_FEATURES }}"
798+
run: cargo clippy --all --tests --no-deps --features $TOKIO_STABLE_FEATURES
799+
- name: "clippy --all --all-features --unstable"
800+
run: cargo clippy --all --tests --no-deps --all-features
785801
env:
786-
RUSTFLAGS: ${{ matrix.rustflags }}
802+
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings
787803

788804
docs:
789805
name: docs
@@ -970,7 +986,7 @@ jobs:
970986
toolchain: ${{ env.rust_nightly }}
971987
target: x86_64-unknown-redox
972988
- name: check tokio on redox
973-
run: cargo check --target x86_64-unknown-redox --all-features
989+
run: cargo check --target x86_64-unknown-redox --features $TOKIO_STABLE_FEATURES
974990
working-directory: tokio
975991

976992
wasm32-unknown-unknown:
@@ -1087,7 +1103,7 @@ jobs:
10871103
with:
10881104
tool: cargo-check-external-types@0.1.13
10891105
- name: check-external-types
1090-
run: cargo check-external-types --all-features
1106+
run: cargo check-external-types --features $TOKIO_STABLE_FEATURES
10911107
working-directory: tokio
10921108

10931109
check-fuzzing:

tokio-macros/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ use proc_macro::TokenStream;
282282
/// fn main() {
283283
/// tokio::runtime::Builder::new_current_thread()
284284
/// .enable_all()
285-
/// .unhandled_panic(UnhandledPanic::ShutdownRuntime)
285+
/// .unhandled_panic(tokio::runtime::UnhandledPanic::ShutdownRuntime)
286286
/// .build()
287287
/// .unwrap()
288288
/// .block_on(async {
@@ -539,7 +539,7 @@ pub fn main_rt(args: TokenStream, item: TokenStream) -> TokenStream {
539539
/// panic!("This panic will shutdown the runtime.");
540540
/// }).await;
541541
/// }
542-
/// # #[cfg(not(tokio_unstable))]
542+
///
543543
/// # fn main() { }
544544
/// ```
545545
///
@@ -560,7 +560,7 @@ pub fn main_rt(args: TokenStream, item: TokenStream) -> TokenStream {
560560
/// }).await;
561561
/// })
562562
/// }
563-
/// # #[cfg(not(tokio_unstable))]
563+
///
564564
/// # fn main() { }
565565
/// ```
566566
///

tokio/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,9 @@ compile_error! {
474474
))]
475475
compile_error!("Only features sync,macros,io-util,rt,time are supported on wasm.");
476476

477+
#[cfg(all(not(tokio_unstable), feature = "io-uring"))]
478+
compile_error!("The `io-uring` feature requires `--cfg tokio_unstable`.");
479+
477480
#[cfg(all(not(tokio_unstable), tokio_taskdump))]
478481
compile_error!("The `tokio_taskdump` feature requires `--cfg tokio_unstable`.");
479482

0 commit comments

Comments
 (0)