Skip to content

Commit d1f1499

Browse files
ADD-SPDarksonn
andauthored
tokio: use cargo feature for taskdump support instead of cfg (#7655)
Signed-off-by: ADD-SP <[email protected]> Co-authored-by: Alice Ryhl <[email protected]>
1 parent ad6f618 commit d1f1499

File tree

24 files changed

+111
-96
lines changed

24 files changed

+111
-96
lines changed

.cirrus.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ task:
2929
# Free the disk space before the next build,
3030
# otherwise cirrus-ci complains about "No space left on device".
3131
- 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
32+
# Enable all unstable features except `taskdump`, which is Linux-only.
33+
- |
34+
RUSTFLAGS="$RUSTFLAGS --cfg tokio_unstable" \
35+
RUSTDOCFLAGS="$RUSTDOCFLAGS --cfg tokio_unstable" \
36+
cargo test \
37+
--features $TOKIO_STABLE_FEATURES,io-uring,tracing
3538
3639
task:
3740
name: FreeBSD docs
@@ -48,7 +51,9 @@ task:
4851
rustc --version
4952
test_script:
5053
- . $HOME/.cargo/env
51-
- cargo doc --lib --no-deps --all-features --document-private-items
54+
# We use `--features $TOKIO_STABLE_FEATURES,io-uring,tracing` instead of
55+
# `--all-features` to exclude `taskdump`, which is Linux-only.
56+
- cargo doc --lib --no-deps --features $TOKIO_STABLE_FEATURES,io-uring,tracing --document-private-items
5257

5358
task:
5459
name: FreeBSD 32-bit

.github/workflows/ci.yml

Lines changed: 59 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,14 @@ jobs:
309309
- name: test tokio full --cfg unstable --cfg taskdump
310310
run: |
311311
set -euxo pipefail
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
312+
cargo nextest run --features $TOKIO_STABLE_FEATURES,taskdump
316313
cargo test --doc --features $TOKIO_STABLE_FEATURES
317314
working-directory: tokio
318315
env:
319-
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings
316+
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
320317
# in order to run doctests for unstable features, we must also pass
321318
# the unstable cfg to RustDoc
322-
RUSTDOCFLAGS: --cfg tokio_unstable --cfg tokio_taskdump
319+
RUSTDOCFLAGS: --cfg tokio_unstable
323320

324321
check-unstable-mt-counters:
325322
name: check tokio full --internal-mt-counters
@@ -484,7 +481,7 @@ jobs:
484481

485482
- uses: Swatinem/rust-cache@v2
486483
# We don't use --all-features since io-uring will be enabled and is not supported on those targets.
487-
- run: cargo check --workspace --features full,test-util --target ${{ matrix.target }}
484+
- run: cargo check --workspace --features $TOKIO_STABLE_FEATURES --target ${{ matrix.target }}
488485
env:
489486
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
490487

@@ -496,8 +493,9 @@ jobs:
496493
matrix:
497494
target:
498495
- name: x86_64-unknown-haiku
496+
exclude_features: "taskdump" # taskdump is only available on Linux
499497
- name: armv7-sony-vita-newlibeabihf
500-
exclude_features: "process,signal,rt-process-signal,full"
498+
exclude_features: "process,signal,rt-process-signal,full,taskdump"
501499
steps:
502500
- uses: actions/checkout@v5
503501
- name: Install Rust ${{ env.rust_nightly }}
@@ -522,14 +520,14 @@ jobs:
522520
include:
523521
- target: i686-unknown-linux-gnu
524522
os: ubuntu-latest
525-
rustflags: --cfg tokio_taskdump
523+
extra_features: "taskdump"
526524
- target: armv5te-unknown-linux-gnueabi
527525
os: ubuntu-latest
528526
- target: armv7-unknown-linux-gnueabihf
529527
os: ubuntu-24.04-arm
530528
- target: aarch64-unknown-linux-gnu
531529
os: ubuntu-24.04-arm
532-
rustflags: --cfg tokio_taskdump
530+
extra_features: "io-uring,taskdump"
533531
- target: aarch64-pc-windows-msvc
534532
os: windows-11-arm
535533
steps:
@@ -554,13 +552,15 @@ jobs:
554552
- name: Tests run with all features (including parking_lot)
555553
run: |
556554
set -euxo pipefail
557-
# We use `--features "full,test-util"` instead of `--all-features` since
558-
# `--all-features` includes `io_uring`, which is not available on all targets.
559-
cargo nextest run -p tokio --features full,test-util --target ${{ matrix.target }}
560-
cargo test --doc -p tokio --features full,test-util --target ${{ matrix.target }}
555+
# We use `--features "$TOKIO_STABLE_FEATURES"` instead of `--all-features` since
556+
# `--all-features` includes `io_uring` and `taskdump`,
557+
# which is not available on all targets.
558+
cargo nextest run -p tokio --features $TOKIO_STABLE_FEATURES,${{ matrix.extra_features }} --target ${{ matrix.target }}
559+
cargo test --doc -p tokio --features $TOKIO_STABLE_FEATURES,${{ matrix.extra_features }} --target ${{ matrix.target }}
561560
env:
562561
RUST_TEST_THREADS: 1
563-
RUSTFLAGS: --cfg tokio_unstable -Dwarnings --cfg tokio_no_tuning_tests ${{ matrix.rustflags }}
562+
RUSTFLAGS: --cfg tokio_unstable -Dwarnings --cfg tokio_no_tuning_tests
563+
RUSTDOCFLAGS: --cfg tokio_unstable -Dwarnings
564564

565565
cross-test-without-parking_lot:
566566
needs: basics
@@ -570,14 +570,14 @@ jobs:
570570
include:
571571
- target: i686-unknown-linux-gnu
572572
os: ubuntu-latest
573-
rustflags: --cfg tokio_taskdump
573+
extra_features: "taskdump"
574574
- target: armv5te-unknown-linux-gnueabi
575575
os: ubuntu-latest
576576
- target: armv7-unknown-linux-gnueabihf
577577
os: ubuntu-24.04-arm
578578
- target: aarch64-unknown-linux-gnu
579579
os: ubuntu-24.04-arm
580-
rustflags: --cfg tokio_taskdump
580+
extra_features: "io-uring,taskdump"
581581
- target: aarch64-pc-windows-msvc
582582
os: windows-11-arm
583583
steps:
@@ -606,13 +606,15 @@ jobs:
606606
- name: Tests run with all features (without parking_lot)
607607
run: |
608608
set -euxo pipefail
609-
# We use `--features "full,test-util"` instead of `--all-features` since
610-
# `--all-features` includes `io_uring`, which is not available on all targets.
611-
cargo nextest run -p tokio --features full,test-util --target ${{ matrix.target }}
612-
cargo test --doc -p tokio --features full,test-util --target ${{ matrix.target }}
609+
# We use `--features "$TOKIO_STABLE_FEATURES"` instead of `--all-features` since
610+
# `--all-features` includes `io_uring` and `taskdump`,
611+
# which is not available on all targets.
612+
cargo nextest run -p tokio --features $TOKIO_STABLE_FEATURES,${{ matrix.extra_features }} --target ${{ matrix.target }}
613+
cargo test --doc -p tokio --features $TOKIO_STABLE_FEATURES,${{ matrix.extra_features }} --target ${{ matrix.target }}
613614
env:
614615
RUST_TEST_THREADS: 1
615616
RUSTFLAGS: --cfg tokio_unstable -Dwarnings --cfg tokio_no_parking_lot --cfg tokio_no_tuning_tests ${{ matrix.rustflags }}
617+
RUSTDOCFLAGS: --cfg tokio_unstable -Dwarnings
616618

617619
# See https://github.com/tokio-rs/tokio/issues/5187
618620
no-atomic-u64-test:
@@ -640,13 +642,11 @@ jobs:
640642
- uses: Swatinem/rust-cache@v2
641643
- name: test tokio --all-features
642644
run: |
643-
# We use `--features "full,test-util"` instead of `--all-features` since
644-
# `--all-features` includes `io_uring`, which is not available on all targets.
645-
cargo nextest run -Zbuild-std --target target-specs/i686-unknown-linux-gnu.json -p tokio --features full,test-util
646-
cargo test --doc -Zbuild-std --target target-specs/i686-unknown-linux-gnu.json -p tokio --features full,test-util
645+
cargo nextest run -Zbuild-std --target target-specs/i686-unknown-linux-gnu.json -p tokio --features $TOKIO_STABLE_FEATURES,taskdump
646+
cargo test --doc -Zbuild-std --target target-specs/i686-unknown-linux-gnu.json -p tokio --features $TOKIO_STABLE_FEATURES,taskdump
647647
env:
648648
RUST_TEST_THREADS: 1
649-
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings --cfg tokio_no_tuning_tests
649+
RUSTFLAGS: --cfg tokio_unstable -Dwarnings --cfg tokio_no_tuning_tests
650650

651651
no-atomic-u64-check:
652652
name: Check tokio --feature-powerset --depth 2 on i686-unknown-linux-gnu without AtomicU64
@@ -672,18 +672,24 @@ jobs:
672672
# We use `--skip io-uring` since io-uring crate doesn't provide a binding for the i686 target.
673673
run: cargo hack check -Zbuild-std --target target-specs/i686-unknown-linux-gnu.json -p tokio --feature-powerset --skip io-uring --depth 2 --keep-going
674674
env:
675-
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings
675+
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
676676

677677
features:
678-
name: features ${{ matrix.name }}
678+
name: features exclude ${{ matrix.name }}
679679
needs: basics
680680
runs-on: ubuntu-latest
681681
strategy:
682682
matrix:
683683
include:
684-
- { name: "", rustflags: "", exclude_features: "io-uring" }
685-
- { name: "--unstable", rustflags: "--cfg tokio_unstable -Dwarnings", exclude_features: "" }
686-
- { name: "--unstable --taskdump", rustflags: "--cfg tokio_unstable -Dwarnings --cfg tokio_taskdump", exclude_features: "" }
684+
- name: ""
685+
rustflags: ""
686+
exclude_features: "io-uring,taskdump"
687+
- name: "--unstable"
688+
rustflags: "--cfg tokio_unstable -Dwarnings"
689+
exclude_features: "io-uring,taskdump"
690+
- name: "--unstable io-uring,taskdump"
691+
rustflags: "--cfg tokio_unstable -Dwarnings"
692+
exclude_features: ""
687693
steps:
688694
- uses: actions/checkout@v5
689695
- name: Install Rust ${{ env.rust_nightly }}
@@ -749,7 +755,7 @@ jobs:
749755
cargo hack check -p tokio-macros -p tokio-stream -p tokio-util -p tokio-test --all-features --ignore-private
750756
- name: "check --all-features --unstable -Z minimal-versions"
751757
env:
752-
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings
758+
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
753759
run: |
754760
# Remove dev-dependencies from Cargo.toml to prevent the next `cargo update`
755761
# from determining minimal versions based on dev-dependencies.
@@ -795,7 +801,7 @@ jobs:
795801
- name: "clippy --all --all-features --unstable"
796802
run: cargo clippy --all --tests --no-deps --all-features
797803
env:
798-
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings
804+
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
799805

800806
docs:
801807
name: docs
@@ -804,9 +810,9 @@ jobs:
804810
matrix:
805811
run:
806812
- os: windows-latest
813+
extra_features: "tracing"
807814
- os: ubuntu-latest
808-
RUSTFLAGS: --cfg tokio_taskdump
809-
RUSTDOCFLAGS: --cfg tokio_taskdump
815+
extra_features: "tracing,io-uring,taskdump"
810816

811817
steps:
812818
- uses: actions/checkout@v5
@@ -816,11 +822,10 @@ jobs:
816822
toolchain: ${{ env.rust_nightly }}
817823
- uses: Swatinem/rust-cache@v2
818824
- name: "doc --lib --all-features"
819-
run: |
820-
cargo doc --lib --no-deps --all-features --document-private-items
825+
run: cargo doc --lib --no-deps --document-private-items --features $TOKIO_STABLE_FEATURES,${{ matrix.run.extra_features }}
821826
env:
822-
RUSTFLAGS: --cfg docsrs --cfg tokio_unstable ${{ matrix.run.RUSTFLAGS }}
823-
RUSTDOCFLAGS: --cfg docsrs --cfg tokio_unstable -Dwarnings ${{ matrix.run.RUSTDOCFLAGS }}
827+
RUSTFLAGS: --cfg docsrs --cfg tokio_unstable
828+
RUSTDOCFLAGS: --cfg docsrs --cfg tokio_unstable -Dwarnings
824829

825830
loom-compile:
826831
name: build loom tests
@@ -1083,26 +1088,31 @@ jobs:
10831088
runs-on: ${{ matrix.os }}
10841089
strategy:
10851090
matrix:
1086-
os:
1087-
- windows-latest
1088-
- ubuntu-latest
1089-
rust:
1090-
# `check-external-types` requires a specific Rust nightly version. See
1091-
# the README for details: https://github.com/awslabs/cargo-check-external-types
1092-
- nightly-2024-06-30
1091+
include:
1092+
- os: windows-latest
1093+
# Windows neither supports io-uring nor taskdump.
1094+
extra_features: "tracing"
1095+
- os: ubuntu-latest
1096+
# includes all unstable features.
1097+
extra_features: "tracing,io-uring,taskdump"
10931098
steps:
10941099
- uses: actions/checkout@v5
10951100
- name: Install Rust ${{ matrix.rust }}
10961101
uses: dtolnay/rust-toolchain@stable
10971102
with:
1098-
toolchain: ${{ matrix.rust }}
1103+
# `check-external-types` requires a specific Rust nightly version. See
1104+
# the README for details: https://github.com/awslabs/cargo-check-external-types
1105+
toolchain: nightly-2025-08-06
10991106
- uses: Swatinem/rust-cache@v2
11001107
- name: Install cargo-check-external-types
11011108
uses: taiki-e/cache-cargo-install-action@v1
11021109
with:
1103-
tool: cargo-check-external-types@0.1.13
1110+
tool: cargo-check-external-types@0.3.0
11041111
- name: check-external-types
1105-
run: cargo check-external-types --features $TOKIO_STABLE_FEATURES
1112+
env:
1113+
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
1114+
RUSTDOCFLAGS: --cfg tokio_unstable
1115+
run: cargo check-external-types --features $TOKIO_STABLE_FEATURES,${{ matrix.extra_features }}
11061116
working-directory: tokio
11071117

11081118
check-fuzzing:

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ unexpected_cfgs = { level = "warn", check-cfg = [
2727
'cfg(tokio_internal_mt_counters)',
2828
'cfg(tokio_no_parking_lot)',
2929
'cfg(tokio_no_tuning_tests)',
30-
'cfg(tokio_taskdump)',
3130
'cfg(tokio_unstable)',
3231
'cfg(target_os, values("cygwin"))',
3332
] }

examples/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ httparse = "1.0"
2424
httpdate = "1.0"
2525
once_cell = "1.5.2"
2626

27+
[target.'cfg(all(tokio_unstable, target_os = "linux"))'.dev-dependencies]
28+
tokio = { version = "1.0.0", path = "../tokio", features = ["full", "tracing", "taskdump"] }
29+
2730
[target.'cfg(windows)'.dev-dependencies.windows-sys]
2831
version = "0.61"
2932

examples/dump.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
55
#[cfg(all(
66
tokio_unstable,
7-
tokio_taskdump,
87
target_os = "linux",
98
any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")
109
))]
@@ -82,7 +81,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
8281

8382
#[cfg(not(all(
8483
tokio_unstable,
85-
tokio_taskdump,
8684
target_os = "linux",
8785
any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")
8886
)))]

netlify.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
RUSTDOCFLAGS="""
1818
--cfg docsrs \
1919
--cfg tokio_unstable \
20-
--cfg tokio_taskdump \
2120
"""
22-
RUSTFLAGS="--cfg tokio_unstable --cfg tokio_taskdump --cfg docsrs"
21+
RUSTFLAGS="""
22+
--cfg docsrs \
23+
--cfg tokio_unstable
24+
"""
2325

2426
[[redirects]]
2527
from = "/"

tokio/Cargo.toml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ test-util = ["rt", "sync", "time"]
8686
time = []
8787
# Unstable feature. Requires `--cfg tokio_unstable` to enable.
8888
io-uring = ["dep:io-uring", "libc", "mio/os-poll", "mio/os-ext", "dep:slab"]
89+
# Unstable feature. Requires `--cfg tokio_unstable` to enable.
90+
taskdump = ["dep:backtrace"]
8991

9092
[dependencies]
9193
tokio-macros = { version = "~2.5.0", path = "../tokio-macros", optional = true }
@@ -112,11 +114,7 @@ io-uring = { version = "0.7.6", default-features = false, optional = true }
112114
libc = { version = "0.2.168", optional = true }
113115
mio = { version = "1.0.1", default-features = false, features = ["os-poll", "os-ext"], optional = true }
114116
slab = { version = "0.4.9", optional = true }
115-
116-
# Currently unstable. The API exposed by these features may be broken at any time.
117-
# Requires `--cfg tokio_unstable` to enable.
118-
[target.'cfg(tokio_taskdump)'.dependencies]
119-
backtrace = { version = "0.3.58" }
117+
backtrace = { version = "0.3.58", optional = true }
120118

121119
[target.'cfg(unix)'.dependencies]
122120
libc = { version = "0.2.168", optional = true }
@@ -169,10 +167,10 @@ tracing-mock = "= 0.1.0-beta.1"
169167
[package.metadata.docs.rs]
170168
all-features = true
171169
# enable unstable features in the documentation
172-
rustdoc-args = ["--cfg", "docsrs", "--cfg", "tokio_unstable", "--cfg", "tokio_taskdump"]
173-
# it's necessary to _also_ pass `--cfg tokio_unstable` and `--cfg tokio_taskdump`
170+
rustdoc-args = ["--cfg", "docsrs", "--cfg", "tokio_unstable"]
171+
# it's necessary to _also_ pass `--cfg tokio_unstable`
174172
# to rustc, or else dependencies will not be enabled, and the docs build will fail.
175-
rustc-args = ["--cfg", "tokio_unstable", "--cfg", "tokio_taskdump"]
173+
rustc-args = ["--cfg", "tokio_unstable"]
176174

177175
[package.metadata.playground]
178176
features = ["full", "test-util"]

tokio/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,19 +483,19 @@ compile_error!("Only features sync,macros,io-util,rt,time are supported on wasm.
483483
#[cfg(all(not(tokio_unstable), feature = "io-uring"))]
484484
compile_error!("The `io-uring` feature requires `--cfg tokio_unstable`.");
485485

486-
#[cfg(all(not(tokio_unstable), tokio_taskdump))]
487-
compile_error!("The `tokio_taskdump` feature requires `--cfg tokio_unstable`.");
486+
#[cfg(all(not(tokio_unstable), feature = "taskdump"))]
487+
compile_error!("The `taskdump` feature requires `--cfg tokio_unstable`.");
488488

489489
#[cfg(all(
490-
tokio_taskdump,
490+
feature = "taskdump",
491491
not(doc),
492492
not(all(
493493
target_os = "linux",
494494
any(target_arch = "aarch64", target_arch = "x86", target_arch = "x86_64")
495495
))
496496
))]
497497
compile_error!(
498-
"The `tokio_taskdump` feature is only currently supported on \
498+
"The `taskdump` feature is only currently supported on \
499499
linux, on `aarch64`, `x86` and `x86_64`."
500500
);
501501

0 commit comments

Comments
 (0)