Skip to content

Commit dd08212

Browse files
authored
Merge branch 'tokio-rs:master' into master
2 parents 8012200 + 6fcd9c0 commit dd08212

File tree

110 files changed

+1797
-910
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1797
-910
lines changed

.cirrus.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ freebsd_instance:
44
image_family: freebsd-14-0
55
env:
66
RUST_STABLE: stable
7-
RUST_NIGHTLY: nightly-2023-10-21
7+
RUST_NIGHTLY: nightly-2024-05-05
88
RUSTFLAGS: -D warnings
99

1010
# Test FreeBSD in a full VM on cirrus-ci.com. Test the i686 target too, in the

.github/workflows/ci.yml

+48-14
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ env:
1515
RUST_BACKTRACE: 1
1616
# Change to specific Rust release to pin
1717
rust_stable: stable
18-
rust_nightly: nightly-2023-10-21
18+
rust_nightly: nightly-2024-05-05
1919
rust_clippy: '1.77'
2020
# When updating this, also update:
2121
# - README.md
@@ -67,7 +67,7 @@ jobs:
6767
- x86_64-fortanix-unknown-sgx
6868
- check-redox
6969
- wasm32-unknown-unknown
70-
- wasm32-wasi
70+
- wasm32-wasip1
7171
- check-external-types
7272
- check-fuzzing
7373
- check-unstable-mt-counters
@@ -908,17 +908,22 @@ jobs:
908908
run: wasm-pack test --node -- --features "macros sync"
909909
working-directory: tokio
910910

911-
wasm32-wasi:
912-
name: wasm32-wasi
911+
wasm32-wasip1:
912+
name: ${{ matrix.target }}
913913
needs: basics
914914
runs-on: ubuntu-latest
915+
strategy:
916+
matrix:
917+
target:
918+
- wasm32-wasip1
919+
- wasm32-wasip1-threads
915920
steps:
916921
- uses: actions/checkout@v4
917922
- name: Install Rust ${{ env.rust_stable }}
918923
uses: dtolnay/rust-toolchain@stable
919924
with:
920925
toolchain: ${{ env.rust_stable }}
921-
targets: wasm32-wasi
926+
targets: ${{ matrix.target }}
922927

923928
# Install dependencies
924929
- name: Install cargo-hack, wasmtime, and cargo-wasi
@@ -928,28 +933,40 @@ jobs:
928933

929934
- uses: Swatinem/rust-cache@v2
930935
- name: WASI test tokio full
931-
run: cargo test -p tokio --target wasm32-wasi --features full
936+
run: cargo test -p tokio --target ${{ matrix.target }} --features full
932937
env:
933-
CARGO_TARGET_WASM32_WASI_RUNNER: "wasmtime run --"
934-
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
938+
CARGO_TARGET_WASM32_WASIP1_RUNNER: "wasmtime run --"
939+
CARGO_TARGET_WASM32_WASIP1_THREADS_RUNNER: "wasmtime run -W bulk-memory=y -W threads=y -S threads=y --"
940+
RUSTFLAGS: --cfg tokio_unstable -Dwarnings -C target-feature=+atomics,+bulk-memory -C link-args=--max-memory=67108864
935941

936942
- name: WASI test tokio-util full
937-
run: cargo test -p tokio-util --target wasm32-wasi --features full
943+
run: cargo test -p tokio-util --target ${{ matrix.target }} --features full
938944
env:
939-
CARGO_TARGET_WASM32_WASI_RUNNER: "wasmtime run --"
940-
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
945+
CARGO_TARGET_WASM32_WASIP1_RUNNER: "wasmtime run --"
946+
CARGO_TARGET_WASM32_WASIP1_THREADS_RUNNER: "wasmtime run -W bulk-memory=y -W threads=y -S threads=y --"
947+
RUSTFLAGS: --cfg tokio_unstable -Dwarnings -C target-feature=+atomics,+bulk-memory -C link-args=--max-memory=67108864
941948

942949
- name: WASI test tokio-stream
943-
run: cargo test -p tokio-stream --target wasm32-wasi --features time,net,io-util,sync
950+
run: cargo test -p tokio-stream --target ${{ matrix.target }} --features time,net,io-util,sync
944951
env:
945-
CARGO_TARGET_WASM32_WASI_RUNNER: "wasmtime run --"
946-
RUSTFLAGS: --cfg tokio_unstable -Dwarnings
952+
CARGO_TARGET_WASM32_WASIP1_RUNNER: "wasmtime run --"
953+
CARGO_TARGET_WASM32_WASIP1_THREADS_RUNNER: "wasmtime run -W bulk-memory=y -W threads=y -S threads=y --"
954+
RUSTFLAGS: --cfg tokio_unstable -Dwarnings -C target-feature=+atomics,+bulk-memory -C link-args=--max-memory=67108864
947955

948956
- name: test tests-integration --features wasi-rt
949957
# TODO: this should become: `cargo hack wasi test --each-feature`
950958
run: cargo wasi test --test rt_yield --features wasi-rt
959+
if: matrix.target == 'wasm32-wasip1'
951960
working-directory: tests-integration
952961

962+
- name: test tests-integration --features wasi-threads-rt
963+
run: cargo test --target ${{ matrix.target }} --features wasi-threads-rt
964+
if: matrix.target == 'wasm32-wasip1-threads'
965+
working-directory: tests-integration
966+
env:
967+
CARGO_TARGET_WASM32_WASIP1_THREADS_RUNNER: "wasmtime run -W bulk-memory=y -W threads=y -S threads=y --"
968+
RUSTFLAGS: --cfg tokio_unstable -Dwarnings -C target-feature=+atomics,+bulk-memory -C link-args=--max-memory=67108864
969+
953970
check-external-types:
954971
name: check-external-types (${{ matrix.os }})
955972
needs: basics
@@ -978,6 +995,23 @@ jobs:
978995
run: cargo check-external-types --all-features
979996
working-directory: tokio
980997

998+
check-unexpected-lints-cfgs:
999+
name: check unexpected lints and cfgs
1000+
needs: basics
1001+
runs-on: ubuntu-latest
1002+
steps:
1003+
- uses: actions/checkout@v4
1004+
- name: Install Rust ${{ env.rust_nightly }}
1005+
uses: dtolnay/rust-toolchain@master
1006+
with:
1007+
toolchain: ${{ env.rust_nightly }}
1008+
- name: don't allow warnings
1009+
run: sed -i '/#!\[allow(unknown_lints, unexpected_cfgs)\]/d' */src/lib.rs */tests/*.rs
1010+
- name: check for unknown lints and cfgs
1011+
run: cargo check --all-features --tests
1012+
env:
1013+
RUSTFLAGS: -Dwarnings --check-cfg=cfg(loom,tokio_unstable,tokio_taskdump,fuzzing,mio_unsupported_force_poll_poll,tokio_internal_mt_counters,fs,tokio_no_parking_lot,tokio_no_tuning_tests) -Funexpected_cfgs -Funknown_lints
1014+
9811015
check-fuzzing:
9821016
name: check-fuzzing
9831017
needs: basics

CONTRIBUTING.md

+17-9
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,28 @@ When updating this, also update:
152152
cargo +1.77 clippy --all --tests --all-features
153153
```
154154

155-
When building documentation normally, the markers that list the features
156-
required for various parts of Tokio are missing. To build the documentation
157-
correctly, use this command:
155+
When building documentation, a simple `cargo doc` is not sufficient. To produce
156+
documentation equivalent to what will be produced in docs.rs's builds of Tokio's
157+
docs, please use:
158158

159159
```
160-
RUSTDOCFLAGS="--cfg docsrs" RUSTFLAGS="--cfg docsrs" cargo +nightly doc --all-features
160+
RUSTDOCFLAGS="--cfg docsrs --cfg tokio_unstable" RUSTFLAGS="--cfg docsrs --cfg tokio_unstable" cargo +nightly doc --all-features [--open]
161161
```
162162

163-
To build documentation including Tokio's unstable features, it is necessary to
164-
pass `--cfg tokio_unstable` to both RustDoc *and* rustc. To build the
165-
documentation for unstable features, use this command:
163+
This turns on indicators to display the Cargo features required for
164+
conditionally compiled APIs in Tokio, and it enables documentation of unstable
165+
Tokio features. Notice that it is necessary to pass cfg flags to both RustDoc
166+
*and* rustc.
167+
168+
There is a more concise way to build docs.rs-equivalent docs by using [`cargo
169+
docs-rs`], which reads the above documentation flags out of Tokio's Cargo.toml
170+
as docs.rs itself does.
171+
172+
[`cargo docs-rs`]: https://github.com/dtolnay/cargo-docs-rs
166173

167174
```
168-
RUSTDOCFLAGS="--cfg docsrs --cfg tokio_unstable" RUSTFLAGS="--cfg docsrs --cfg tokio_unstable" cargo +nightly doc --all-features
175+
cargo install --locked cargo-docs-rs
176+
cargo +nightly docs-rs [--open]
169177
```
170178

171179
The `cargo fmt` command does not work on the Tokio codebase. You can use the
@@ -253,7 +261,7 @@ directory `fuzz`. It is a good idea to run fuzz tests after each change.
253261
To get started with fuzz testing you'll need to install
254262
[cargo-fuzz](https://github.com/rust-fuzz/cargo-fuzz).
255263

256-
`cargo install cargo-fuzz`
264+
`cargo install --locked cargo-fuzz`
257265

258266
To list the available fuzzing harnesses you can run;
259267

benches/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,8 @@ harness = false
9090
name = "time_now"
9191
path = "time_now.rs"
9292
harness = false
93+
94+
[[bench]]
95+
name = "time_timeout"
96+
path = "time_timeout.rs"
97+
harness = false

benches/time_timeout.rs

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
use std::time::{Duration, Instant};
2+
3+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
4+
use tokio::{
5+
runtime::Runtime,
6+
time::{sleep, timeout},
7+
};
8+
9+
// a very quick async task, but might timeout
10+
async fn quick_job() -> usize {
11+
1
12+
}
13+
14+
fn build_run_time(workers: usize) -> Runtime {
15+
if workers == 1 {
16+
tokio::runtime::Builder::new_current_thread()
17+
.enable_all()
18+
.build()
19+
.unwrap()
20+
} else {
21+
tokio::runtime::Builder::new_multi_thread()
22+
.enable_all()
23+
.worker_threads(workers)
24+
.build()
25+
.unwrap()
26+
}
27+
}
28+
29+
fn single_thread_scheduler_timeout(c: &mut Criterion) {
30+
do_timeout_test(c, 1, "single_thread_timeout");
31+
}
32+
33+
fn multi_thread_scheduler_timeout(c: &mut Criterion) {
34+
do_timeout_test(c, 8, "multi_thread_timeout-8");
35+
}
36+
37+
fn do_timeout_test(c: &mut Criterion, workers: usize, name: &str) {
38+
let runtime = build_run_time(workers);
39+
c.bench_function(name, |b| {
40+
b.iter_custom(|iters| {
41+
let start = Instant::now();
42+
runtime.block_on(async {
43+
black_box(spawn_timeout_job(iters as usize, workers).await);
44+
});
45+
start.elapsed()
46+
})
47+
});
48+
}
49+
50+
async fn spawn_timeout_job(iters: usize, procs: usize) {
51+
let mut handles = Vec::with_capacity(procs);
52+
for _ in 0..procs {
53+
handles.push(tokio::spawn(async move {
54+
for _ in 0..iters / procs {
55+
let h = timeout(Duration::from_secs(1), quick_job());
56+
assert_eq!(black_box(h.await.unwrap()), 1);
57+
}
58+
}));
59+
}
60+
for handle in handles {
61+
handle.await.unwrap();
62+
}
63+
}
64+
65+
fn single_thread_scheduler_sleep(c: &mut Criterion) {
66+
do_sleep_test(c, 1, "single_thread_sleep");
67+
}
68+
69+
fn multi_thread_scheduler_sleep(c: &mut Criterion) {
70+
do_sleep_test(c, 8, "multi_thread_sleep-8");
71+
}
72+
73+
fn do_sleep_test(c: &mut Criterion, workers: usize, name: &str) {
74+
let runtime = build_run_time(workers);
75+
76+
c.bench_function(name, |b| {
77+
b.iter_custom(|iters| {
78+
let start = Instant::now();
79+
runtime.block_on(async {
80+
black_box(spawn_sleep_job(iters as usize, workers).await);
81+
});
82+
start.elapsed()
83+
})
84+
});
85+
}
86+
87+
async fn spawn_sleep_job(iters: usize, procs: usize) {
88+
let mut handles = Vec::with_capacity(procs);
89+
for _ in 0..procs {
90+
handles.push(tokio::spawn(async move {
91+
for _ in 0..iters / procs {
92+
let _h = black_box(sleep(Duration::from_secs(1)));
93+
}
94+
}));
95+
}
96+
for handle in handles {
97+
handle.await.unwrap();
98+
}
99+
}
100+
101+
criterion_group!(
102+
timeout_benchmark,
103+
single_thread_scheduler_timeout,
104+
multi_thread_scheduler_timeout,
105+
single_thread_scheduler_sleep,
106+
multi_thread_scheduler_sleep
107+
);
108+
109+
criterion_main!(timeout_benchmark);

examples/tinyhttp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,11 @@ mod date {
259259
unix_date: u64,
260260
}
261261

262-
thread_local!(static LAST: RefCell<LastRenderedNow> = RefCell::new(LastRenderedNow {
262+
thread_local!(static LAST: RefCell<LastRenderedNow> = const { RefCell::new(LastRenderedNow {
263263
bytes: [0; 128],
264264
amt: 0,
265265
unix_date: 0,
266-
}));
266+
}) });
267267

268268
impl fmt::Display for Now {
269269
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

spellcheck.dic

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
283
1+
284
22
&
33
+
44
<
@@ -131,6 +131,7 @@ io
131131
IOCP
132132
iOS
133133
IOs
134+
io_uring
134135
IP
135136
IPv4
136137
IPv6

target-specs/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This is used for the `no-atomic-u64-test` ci check that verifies that Tokio
2+
works even if the `AtomicU64` type is missing.
3+
4+
When increasing the nightly compiler version, you may need to regenerate this
5+
target using the following command:
6+
```
7+
rustc +nightly -Z unstable-options --print target-spec-json --target i686-unknown-linux-gnu | grep -v 'is-builtin' | sed 's/"max-atomic-width": 64/"max-atomic-width": 32/' > target-specs/i686-unknown-linux-gnu.json
8+
```
9+

target-specs/i686-unknown-linux-gnu.json

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
{
22
"arch": "x86",
33
"cpu": "pentium4",
4+
"crt-objects-fallback": "false",
45
"crt-static-respected": true,
5-
"data-layout": "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128",
6+
"data-layout": "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i128:128-f64:32:64-f80:32-n8:16:32-S128",
67
"dynamic-linking": true,
78
"env": "gnu",
89
"has-rpath": true,
910
"has-thread-local": true,
11+
"linker-flavor": "gnu-cc",
1012
"llvm-target": "i686-unknown-linux-gnu",
1113
"max-atomic-width": 32,
14+
"metadata": {
15+
"description": null,
16+
"host_tools": null,
17+
"std": null,
18+
"tier": null
19+
},
1220
"os": "linux",
1321
"position-independent-executables": true,
1422
"pre-link-args": {
15-
"gcc": [
23+
"gnu-cc": [
24+
"-m32"
25+
],
26+
"gnu-lld-cc": [
1627
"-m32"
1728
]
1829
},
1930
"relro-level": "full",
2031
"stack-probes": {
21-
"kind": "inline-or-call",
22-
"min-llvm-version-for-inline": [
23-
16,
24-
0,
25-
0
26-
]
32+
"kind": "inline"
2733
},
2834
"supported-sanitizers": [
2935
"address"

tests-build/tests/fail/macros_invalid_input.rs

+20
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,24 @@ async fn test_crate_not_path_invalid() {}
4545
#[test]
4646
async fn test_has_second_test_attr() {}
4747

48+
#[tokio::test]
49+
#[::core::prelude::v1::test]
50+
async fn test_has_second_test_attr_v1() {}
51+
52+
#[tokio::test]
53+
#[core::prelude::rust_2015::test]
54+
async fn test_has_second_test_attr_rust_2015() {}
55+
56+
#[tokio::test]
57+
#[::std::prelude::rust_2018::test]
58+
async fn test_has_second_test_attr_rust_2018() {}
59+
60+
#[tokio::test]
61+
#[std::prelude::rust_2021::test]
62+
async fn test_has_second_test_attr_rust_2021() {}
63+
64+
#[tokio::test]
65+
#[tokio::test]
66+
async fn test_has_generated_second_test_attr() {}
67+
4868
fn main() {}

0 commit comments

Comments
 (0)