Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ env:
RUST_STABLE: stable
RUST_NIGHTLY: nightly-2025-01-25
RUSTFLAGS: -D warnings
# This excludes unstable features like io_uring, which require '--cfg tokio_unstable'.
TOKIO_STABLE_FEATURES: full,test-util

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

task:
name: FreeBSD docs
Expand Down Expand Up @@ -55,4 +63,4 @@ task:
rustc --version
test_script:
- . $HOME/.cargo/env
- cargo test --all --all-features --target i686-unknown-freebsd
- cargo test --all --features $TOKIO_STABLE_FEATURES --target i686-unknown-freebsd
106 changes: 59 additions & 47 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ env:
# - tokio-test/Cargo.toml
# - tokio-stream/Cargo.toml
rust_min: '1.70'
# This excludes unstable features like io_uring,
# which require '--cfg tokio_unstable'.
TOKIO_STABLE_FEATURES: "full,test-util"

defaults:
run:
Expand Down Expand Up @@ -73,15 +76,13 @@ jobs:

- uses: Swatinem/rust-cache@v2

# Run `tokio` with `full` features. This excludes testing utilities which
# Run `tokio` with stable features. This excludes testing utilities which
# can alter the runtime behavior of Tokio.
- name: test tokio full
run: |
set -euxo pipefail
# We use `--features "full,test-util"` instead of `--all-features` since
# `--all-features` includes `io_uring`, which is not available on all targets.
cargo nextest run --features full,test-util
cargo test --doc --features full,test-util
cargo nextest run --features full
cargo test --doc --features full
working-directory: tokio

test-workspace-all-features:
Expand All @@ -107,12 +108,11 @@ jobs:

- uses: Swatinem/rust-cache@v2

# Test **all** crates in the workspace with all features.
- name: test all --all-features
- name: test --features ${{ env.TOKIO_STABLE_FEATURES }}
run: |
set -euxo pipefail
cargo nextest run --workspace --all-features
cargo test --doc --workspace --all-features
cargo nextest run --workspace --features $TOKIO_STABLE_FEATURES
cargo test --doc --workspace --features $TOKIO_STABLE_FEATURES

test-workspace-all-features-panic-abort:
needs: basics
Expand All @@ -137,10 +137,15 @@ jobs:

- uses: Swatinem/rust-cache@v2

- name: test all --all-features panic=abort
- name: test --features ${{ env.TOKIO_STABLE_FEATURES }} panic=abort
run: |
set -euxo pipefail
RUSTFLAGS="$RUSTFLAGS -C panic=abort -Zpanic-abort-tests" cargo nextest run --workspace --exclude tokio-macros --exclude tests-build --all-features --tests
RUSTFLAGS="$RUSTFLAGS -C panic=abort -Zpanic-abort-tests" cargo nextest run \
--workspace \
--exclude tokio-macros \
--exclude tests-build \
--features $TOKIO_STABLE_FEATURES \
--tests

test-integration-tests-per-feature:
needs: basics
Expand Down Expand Up @@ -204,8 +209,9 @@ jobs:
run: sed -i '/\[features\]/a plsend = ["parking_lot/send_guard"]' tokio/Cargo.toml

- uses: Swatinem/rust-cache@v2
- name: Check tests with all features enabled
run: cargo check --workspace --all-features --tests

- name: Check tests --features ${{ env.TOKIO_STABLE_FEATURES }}
run: cargo check --workspace --tests --features $TOKIO_STABLE_FEATURES

valgrind:
name: valgrind
Expand Down Expand Up @@ -247,12 +253,11 @@ jobs:
strategy:
matrix:
include:
# We use `--features "full,test-util"` instead of `--all-features` since
# `--all-features` includes `io_uring`, which is not available on all targets.
- { os: windows-latest, features: "full,test-util" }
- { os: ubuntu-latest, features: "full,test-util" }
- { os: ubuntu-latest, features: "full,test-util,io-uring" }
- { os: macos-latest, features: "full,test-util" }
- { os: windows-latest, extra_features: "" }
- { os: ubuntu-latest, extra_features: "" }
# only Linux supports io_uring
- { os: ubuntu-latest, extra_features: io-uring }
- { os: macos-latest, extra_features: "" }
steps:
- uses: actions/checkout@v5
- name: Install Rust ${{ env.rust_stable }}
Expand All @@ -270,8 +275,8 @@ jobs:
- name: test tokio full --cfg unstable
run: |
set -euxo pipefail
cargo nextest run --features ${{ matrix.features }}
cargo test --doc --features ${{ matrix.features }}
cargo nextest run --features $TOKIO_STABLE_FEATURES,${{ matrix.extra_features }}
cargo test --doc --features $TOKIO_STABLE_FEATURES,${{ matrix.extra_features }}
working-directory: tokio
env:
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
Expand Down Expand Up @@ -304,8 +309,11 @@ jobs:
- name: test tokio full --cfg unstable --cfg taskdump
run: |
set -euxo pipefail
cargo nextest run --all-features
cargo test --doc --all-features
# taskdump is an unstable feature, but it can only be enabled
# by --cfg tokio_taskdump, not by a feature flag, so we can
# use $TOKIO_STABLE_FEATURES here.
cargo nextest run --features $TOKIO_STABLE_FEATURES
cargo test --doc --features $TOKIO_STABLE_FEATURES
working-directory: tokio
env:
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings
Expand All @@ -332,7 +340,8 @@ jobs:
with:
tool: cargo-nextest
- uses: Swatinem/rust-cache@v2
# Run `tokio` with "unstable" and "taskdump" cfg flags.
# Since the internal-mt-counters feature is only for debugging purposes,
# we can enable all features including unstable.
- name: check tokio full --cfg unstable --cfg internal-mt-counters
run: |
set -euxo pipefail
Expand Down Expand Up @@ -405,7 +414,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
- name: miri-doc-test
run: |
cargo miri test --doc --all-features --no-fail-fast
cargo miri test --doc --features $TOKIO_STABLE_FEATURES --no-fail-fast
working-directory: tokio
env:
MIRIFLAGS: -Zmiri-disable-isolation -Zmiri-strict-provenance -Zmiri-retag-fields
Expand All @@ -426,7 +435,7 @@ jobs:

- uses: Swatinem/rust-cache@v2
- name: asan
run: cargo test --workspace --all-features --target x86_64-unknown-linux-gnu --tests -- --test-threads 1 --nocapture
run: cargo test --workspace --features $TOKIO_STABLE_FEATURES --target x86_64-unknown-linux-gnu --tests -- --test-threads 1 --nocapture
env:
RUSTFLAGS: -Z sanitizer=address --cfg tokio_no_tuning_tests
# Ignore `trybuild` errors as they are irrelevant and flaky on nightly
Expand All @@ -444,6 +453,9 @@ jobs:
rust-toolchain: ${{ env.rust_stable }}
package: tokio
release-type: minor
feature-group: only-explicit-features
# We don't care about the semver of unstable tokio features.
features: ${{ env.TOKIO_STABLE_FEATURES }}
- name: Check semver for rest of the workspace
if: ${{ !startsWith(github.event.pull_request.base.ref, 'tokio-1.') }}
uses: obi1kenobi/cargo-semver-checks-action@v2
Expand Down Expand Up @@ -669,9 +681,9 @@ jobs:
strategy:
matrix:
include:
- { name: "", rustflags: "" }
- { name: "--unstable", rustflags: "--cfg tokio_unstable -Dwarnings" }
- { name: "--unstable --taskdump", rustflags: "--cfg tokio_unstable -Dwarnings --cfg tokio_taskdump" }
- { name: "", rustflags: "", exclude_features: "io-uring" }
- { name: "--unstable", rustflags: "--cfg tokio_unstable -Dwarnings", exclude_features: "" }
- { name: "--unstable --taskdump", rustflags: "--cfg tokio_unstable -Dwarnings --cfg tokio_taskdump", exclude_features: "" }
steps:
- uses: actions/checkout@v5
- name: Install Rust ${{ env.rust_nightly }}
Expand All @@ -684,7 +696,7 @@ jobs:

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

Expand All @@ -698,17 +710,19 @@ jobs:
with:
toolchain: ${{ env.rust_min }}
- uses: Swatinem/rust-cache@v2
- name: "check --workspace --all-features"
- name: "cargo check"
run: |
if [[ "${{ github.event.pull_request.base.ref }}" =~ ^tokio-1\..* ]]; then
# Only check `tokio` crate as the PR is backporting to an earlier tokio release.
cargo check -p tokio --all-features

cargo check -p tokio --features $TOKIO_STABLE_FEATURES
else
# Check all crates in the workspace
cargo check --workspace --all-features

cargo check -p tokio --features $TOKIO_STABLE_FEATURES
# Other crates doesn't have unstable features, so we can use --all-features.
cargo check -p tokio-macros -p tokio-stream -p tokio-util -p tokio-test --all-features
fi
env:
RUSTFLAGS: "" # remove -Dwarnings

minimal-versions:
name: minimal-versions
Expand All @@ -724,14 +738,15 @@ jobs:
uses: taiki-e/install-action@cargo-hack

- uses: Swatinem/rust-cache@v2
- name: "check --all-features -Z minimal-versions"
- name: "check -Z minimal-versions"
run: |
# Remove dev-dependencies from Cargo.toml to prevent the next `cargo update`
# from determining minimal versions based on dev-dependencies.
cargo hack --remove-dev-deps --workspace
# Update Cargo.lock to minimal version dependencies.
cargo update -Z minimal-versions
cargo hack check --all-features --ignore-private
cargo hack check -p tokio --features $TOKIO_STABLE_FEATURES --ignore-private
cargo hack check -p tokio-macros -p tokio-stream -p tokio-util -p tokio-test --all-features --ignore-private
- name: "check --all-features --unstable -Z minimal-versions"
env:
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings
Expand Down Expand Up @@ -766,11 +781,6 @@ jobs:
clippy:
name: clippy
runs-on: ubuntu-latest
strategy:
matrix:
rustflags:
- ""
- "--cfg tokio_unstable --cfg tokio_taskdump -Dwarnings"
steps:
- uses: actions/checkout@v5
- name: Install Rust ${{ env.rust_clippy }}
Expand All @@ -780,10 +790,12 @@ jobs:
components: clippy
- uses: Swatinem/rust-cache@v2
# Run clippy
- name: "clippy --all ${{ matrix.rustflags }}"
run: cargo clippy --all --tests --all-features --no-deps
- name: "clippy --all --features ${{ env.TOKIO_STABLE_FEATURES }}"
run: cargo clippy --all --tests --no-deps --features $TOKIO_STABLE_FEATURES
- name: "clippy --all --all-features --unstable"
run: cargo clippy --all --tests --no-deps --all-features
env:
RUSTFLAGS: ${{ matrix.rustflags }}
RUSTFLAGS: --cfg tokio_unstable --cfg tokio_taskdump -Dwarnings

docs:
name: docs
Expand Down Expand Up @@ -970,7 +982,7 @@ jobs:
toolchain: ${{ env.rust_nightly }}
target: x86_64-unknown-redox
- name: check tokio on redox
run: cargo check --target x86_64-unknown-redox --all-features
run: cargo check --target x86_64-unknown-redox --features $TOKIO_STABLE_FEATURES
working-directory: tokio

wasm32-unknown-unknown:
Expand Down Expand Up @@ -1090,7 +1102,7 @@ jobs:
with:
tool: [email protected]
- name: check-external-types
run: cargo check-external-types --all-features
run: cargo check-external-types --features $TOKIO_STABLE_FEATURES
working-directory: tokio

check-fuzzing:
Expand Down
11 changes: 10 additions & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
[build]
# TODO: unfreeze toolchain
# error[E0557]: feature has been removed
# --> /opt/buildhome/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/lock_api-0.4.13/src/lib.rs:89:29
# |
# 89 | #![cfg_attr(docsrs, feature(doc_auto_cfg))]
# | ^^^^^^^^^^^^ feature has been removed
# |
# = note: removed in 1.58.0; see <https://github.com/rust-lang/rust/pull/138907; for more information
# = note: merged into `doc_cfg`
command = """
rustup install nightly --profile minimal && cargo doc --no-deps --all-features
rustup install nightly-2025-01-25 --profile minimal && cargo doc --no-deps --all-features
"""
publish = "target/doc"

Expand Down
6 changes: 3 additions & 3 deletions tokio-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ use proc_macro::TokenStream;
/// fn main() {
/// tokio::runtime::Builder::new_current_thread()
/// .enable_all()
/// .unhandled_panic(UnhandledPanic::ShutdownRuntime)
/// .unhandled_panic(tokio::runtime::UnhandledPanic::ShutdownRuntime)
/// .build()
/// .unwrap()
/// .block_on(async {
Expand Down Expand Up @@ -539,7 +539,7 @@ pub fn main_rt(args: TokenStream, item: TokenStream) -> TokenStream {
/// panic!("This panic will shutdown the runtime.");
/// }).await;
/// }
/// # #[cfg(not(tokio_unstable))]
///
/// # fn main() { }
/// ```
///
Expand All @@ -560,7 +560,7 @@ pub fn main_rt(args: TokenStream, item: TokenStream) -> TokenStream {
/// }).await;
/// })
/// }
/// # #[cfg(not(tokio_unstable))]
///
/// # fn main() { }
/// ```
///
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/src/codec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@
//! [`AsyncWrite`]: tokio::io::AsyncWrite
//! [`Stream`]: futures_core::Stream
//! [`Sink`]: futures_sink::Sink
//! [`SinkExt`]: futures::sink::SinkExt
//! [`SinkExt`]: https://docs.rs/futures/0.3/futures/sink/trait.SinkExt.html
//! [`SinkExt::close`]: https://docs.rs/futures/0.3/futures/sink/trait.SinkExt.html#method.close
//! [`FramedRead`]: struct@crate::codec::FramedRead
//! [`FramedWrite`]: struct@crate::codec::FramedWrite
Expand Down
10 changes: 10 additions & 0 deletions tokio/src/fs/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
use mockall::mock;

use crate::sync::oneshot;
#[cfg(all(test, unix))]
use std::os::fd::{AsRawFd, FromRawFd, OwnedFd};
use std::{
cell::RefCell,
collections::VecDeque,
Expand Down Expand Up @@ -96,6 +98,14 @@ impl Write for &'_ MockFile {
}
}

#[cfg(all(test, unix))]
impl From<MockFile> for OwnedFd {
#[inline]
fn from(file: MockFile) -> OwnedFd {
unsafe { OwnedFd::from_raw_fd(file.as_raw_fd()) }
}
}

tokio_thread_local! {
static QUEUE: RefCell<VecDeque<Box<dyn FnOnce() + Send>>> = RefCell::new(VecDeque::new())
}
Expand Down
Loading