From d4fa34c0d7ee866e09ffd30f356ce3e20b2ce706 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sat, 22 Jul 2023 21:25:18 +1000 Subject: [PATCH 01/12] Bump tokio MSRV to 1.63 Also cleanup `build.rs` and remove dependency `autocfg`. Signed-off-by: Jiahao XU --- .github/workflows/ci.yml | 2 +- README.md | 5 +- tokio/Cargo.toml | 5 +- tokio/build.rs | 185 +----------------------- tokio/src/lib.rs | 19 ++- tokio/src/runtime/config.rs | 2 +- tokio/src/runtime/mod.rs | 2 +- tokio/src/runtime/park.rs | 4 +- tokio/src/runtime/task/mod.rs | 2 +- tokio/src/sync/tests/atomic_waker.rs | 2 +- tokio/src/sync/tests/notify.rs | 2 +- tokio/src/sync/tests/semaphore_batch.rs | 2 +- 12 files changed, 28 insertions(+), 204 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 62be91bac8a..5e283e7c682 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,7 @@ env: # - tokio-util/Cargo.toml # - tokio-test/Cargo.toml # - tokio-stream/Cargo.toml - rust_min: 1.56.0 + rust_min: 1.63.0 defaults: run: diff --git a/README.md b/README.md index fb2c149abdd..0dd06287451 100644 --- a/README.md +++ b/README.md @@ -187,12 +187,13 @@ When updating this, also update: Tokio will keep a rolling MSRV (minimum supported rust version) policy of **at least** 6 months. When increasing the MSRV, the new Rust version must have been -released at least six months ago. The current MSRV is 1.56.0. +released at least six months ago. The current MSRV is 1.63.0. Note that the MSRV is not increased automatically, and only as part of a minor release. The MSRV history for past minor releases can be found below: - * 1.27 to now - Rust 1.56 + * 1.30 to now - Rust 1.63 + * 1.27 to 1.29.1 - Rust 1.56 * 1.17 to 1.26 - Rust 1.49 * 1.15 to 1.16 - Rust 1.46 * 1.0 to 1.14 - Rust 1.45 diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index fa5ec3b8553..6e419348e11 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -8,7 +8,7 @@ name = "tokio" # - Create "v1.x.y" git tag. version = "1.29.1" edition = "2021" -rust-version = "1.56" +rust-version = "1.63" authors = ["Tokio Contributors "] license = "MIT" readme = "README.md" @@ -93,9 +93,6 @@ time = [] # a few releases. stats = [] -[build-dependencies] -autocfg = "1.1" - [dependencies] tokio-macros = { version = "~2.1.0", path = "../tokio-macros", optional = true } diff --git a/tokio/build.rs b/tokio/build.rs index b8234dde9a0..cf2e8bf6621 100644 --- a/tokio/build.rs +++ b/tokio/build.rs @@ -1,192 +1,15 @@ -use autocfg::AutoCfg; - -const CONST_THREAD_LOCAL_PROBE: &str = r#" -{ - thread_local! { - static MY_PROBE: usize = const { 10 }; - } - - MY_PROBE.with(|val| *val) -} -"#; - -const CONST_MUTEX_NEW_PROBE: &str = r#" -{ - static MY_MUTEX: ::std::sync::Mutex = ::std::sync::Mutex::new(1); - *MY_MUTEX.lock().unwrap() -} -"#; - -const AS_FD_PROBE: &str = r#" -{ - #[allow(unused_imports)] - #[cfg(unix)] - use std::os::unix::prelude::AsFd as _; - #[allow(unused_imports)] - #[cfg(windows)] - use std::os::windows::prelude::AsSocket as _; - #[allow(unused_imports)] - #[cfg(target_os = "wasi")] - use std::os::wasi::prelude::AsFd as _; -} -"#; - -const TARGET_HAS_ATOMIC_PROBE: &str = r#" -{ - #[cfg(target_has_atomic = "ptr")] - let _ = (); -} -"#; - -const TARGET_ATOMIC_U64_PROBE: &str = r#" -{ - #[allow(unused_imports)] - use std::sync::atomic::AtomicU64 as _; +fn emit(cfg: &str) { + println!("cargo:rustc-cfg={}", cfg); } -"#; fn main() { - let mut enable_const_thread_local = false; - let mut enable_target_has_atomic = false; - let mut enable_const_mutex_new = false; - let mut enable_as_fd = false; - let mut target_needs_atomic_u64_fallback = false; - - match AutoCfg::new() { - Ok(ac) => { - // These checks prefer to call only `probe_rustc_version` if that is - // enough to determine whether the feature is supported. This is - // because the `probe_expression` call involves a call to rustc, - // which the `probe_rustc_version` call avoids. - - // Const-initialized thread locals were stabilized in 1.59. - if ac.probe_rustc_version(1, 60) { - enable_const_thread_local = true; - } else if ac.probe_rustc_version(1, 59) { - // This compiler claims to be 1.59, but there are some nightly - // compilers that claim to be 1.59 without supporting the - // feature. Explicitly probe to check if code using them - // compiles. - // - // The oldest nightly that supports the feature is 2021-12-06. - if ac.probe_expression(CONST_THREAD_LOCAL_PROBE) { - enable_const_thread_local = true; - } - } - - // The `target_has_atomic` cfg was stabilized in 1.60. - if ac.probe_rustc_version(1, 61) { - enable_target_has_atomic = true; - } else if ac.probe_rustc_version(1, 60) { - // This compiler claims to be 1.60, but there are some nightly - // compilers that claim to be 1.60 without supporting the - // feature. Explicitly probe to check if code using them - // compiles. - // - // The oldest nightly that supports the feature is 2022-02-11. - if ac.probe_expression(TARGET_HAS_ATOMIC_PROBE) { - enable_target_has_atomic = true; - } - } - - // If we can't tell using `target_has_atomic`, tell if the target - // has `AtomicU64` by trying to use it. - if !enable_target_has_atomic && !ac.probe_expression(TARGET_ATOMIC_U64_PROBE) { - target_needs_atomic_u64_fallback = true; - } - - // The `Mutex::new` method was made const in 1.63. - if ac.probe_rustc_version(1, 64) { - enable_const_mutex_new = true; - } else if ac.probe_rustc_version(1, 63) { - // This compiler claims to be 1.63, but there are some nightly - // compilers that claim to be 1.63 without supporting the - // feature. Explicitly probe to check if code using them - // compiles. - // - // The oldest nightly that supports the feature is 2022-06-20. - if ac.probe_expression(CONST_MUTEX_NEW_PROBE) { - enable_const_mutex_new = true; - } - } - - // The `AsFd` family of traits were made stable in 1.63. - if ac.probe_rustc_version(1, 64) { - enable_as_fd = true; - } else if ac.probe_rustc_version(1, 63) { - // This compiler claims to be 1.63, but there are some nightly - // compilers that claim to be 1.63 without supporting the - // feature. Explicitly probe to check if code using them - // compiles. - // - // The oldest nightly that supports the feature is 2022-06-16. - if ac.probe_expression(AS_FD_PROBE) { - enable_as_fd = true; - } - } - } - - Err(e) => { - // If we couldn't detect the compiler version and features, just - // print a warning. This isn't a fatal error: we can still build - // Tokio, we just can't enable cfgs automatically. - println!( - "cargo:warning=tokio: failed to detect compiler features: {}", - e - ); - } - } - - if !enable_const_thread_local { - // To disable this feature on compilers that support it, you can - // explicitly pass this flag with the following environment variable: - // - // RUSTFLAGS="--cfg tokio_no_const_thread_local" - autocfg::emit("tokio_no_const_thread_local") - } - - if !enable_target_has_atomic { - // To disable this feature on compilers that support it, you can - // explicitly pass this flag with the following environment variable: - // - // RUSTFLAGS="--cfg tokio_no_target_has_atomic" - autocfg::emit("tokio_no_target_has_atomic") - } - - if !enable_const_mutex_new { - // To disable this feature on compilers that support it, you can - // explicitly pass this flag with the following environment variable: - // - // RUSTFLAGS="--cfg tokio_no_const_mutex_new" - autocfg::emit("tokio_no_const_mutex_new") - } - - if !enable_as_fd { - // To disable this feature on compilers that support it, you can - // explicitly pass this flag with the following environment variable: - // - // RUSTFLAGS="--cfg tokio_no_as_fd" - autocfg::emit("tokio_no_as_fd"); - } - - if target_needs_atomic_u64_fallback { - // To disable this feature on compilers that support it, you can - // explicitly pass this flag with the following environment variable: - // - // RUSTFLAGS="--cfg tokio_no_atomic_u64" - autocfg::emit("tokio_no_atomic_u64") - } - let target = ::std::env::var("TARGET").unwrap_or_default(); - // We emit cfgs instead of using `target_family = "wasm"` that requires Rust 1.54. - // Note that these cfgs are unavailable in `Cargo.toml`. if target.starts_with("wasm") { - autocfg::emit("tokio_wasm"); if target.contains("wasi") { - autocfg::emit("tokio_wasi"); + emit("tokio_wasi"); } else { - autocfg::emit("tokio_wasm_not_wasi"); + emit("tokio_wasm_not_wasi"); } } } diff --git a/tokio/src/lib.rs b/tokio/src/lib.rs index c712945a480..9453365adad 100644 --- a/tokio/src/lib.rs +++ b/tokio/src/lib.rs @@ -461,21 +461,24 @@ compile_error! { // Each condition is written all(a, not(b)). This should be read as // "if a, then we must also have b". #[cfg(any( - all(target_arch = "wasm32", not(tokio_wasm)), - all(target_arch = "wasm64", not(tokio_wasm)), - all(target_family = "wasm", not(tokio_wasm)), - all(target_os = "wasi", not(tokio_wasm)), + all(target_arch = "wasm32", not(target_family = "wasm")), + all(target_arch = "wasm64", not(target_family = "wasm")), + all(target_family = "wasm", not(target_family = "wasm")), + all(target_os = "wasi", not(target_family = "wasm")), all(target_os = "wasi", not(tokio_wasi)), all(target_os = "wasi", tokio_wasm_not_wasi), - all(tokio_wasm, not(any(target_arch = "wasm32", target_arch = "wasm64"))), - all(tokio_wasm_not_wasi, not(tokio_wasm)), - all(tokio_wasi, not(tokio_wasm)) + all( + target_family = "wasm", + not(any(target_arch = "wasm32", target_arch = "wasm64")) + ), + all(tokio_wasm_not_wasi, not(target_family = "wasm")), + all(tokio_wasi, not(target_family = "wasm")) ))] compile_error!("Tokio's build script has incorrectly detected wasm."); #[cfg(all( not(tokio_unstable), - tokio_wasm, + target_family = "wasm", any( feature = "fs", feature = "io-std", diff --git a/tokio/src/runtime/config.rs b/tokio/src/runtime/config.rs index c42e4fe5a80..acae6ef5a55 100644 --- a/tokio/src/runtime/config.rs +++ b/tokio/src/runtime/config.rs @@ -1,4 +1,4 @@ -#![cfg_attr(any(not(feature = "full"), tokio_wasm), allow(dead_code))] +#![cfg_attr(any(not(feature = "full"), target_family = "wasm"), allow(dead_code))] use crate::runtime::Callback; use crate::util::RngSeedGenerator; diff --git a/tokio/src/runtime/mod.rs b/tokio/src/runtime/mod.rs index f8b651745b2..f0d3a0e6c2e 100644 --- a/tokio/src/runtime/mod.rs +++ b/tokio/src/runtime/mod.rs @@ -175,7 +175,7 @@ // At the top due to macros #[cfg(test)] -#[cfg(not(tokio_wasm))] +#[cfg(not(target_family = "wasm"))] #[macro_use] mod tests; diff --git a/tokio/src/runtime/park.rs b/tokio/src/runtime/park.rs index 97e14fb2acb..3e4374551b9 100644 --- a/tokio/src/runtime/park.rs +++ b/tokio/src/runtime/park.rs @@ -67,9 +67,9 @@ impl ParkThread { CURRENT_THREAD_PARK_COUNT.with(|count| count.fetch_add(1, SeqCst)); // Wasm doesn't have threads, so just sleep. - #[cfg(not(tokio_wasm))] + #[cfg(not(target_family = "wasm"))] self.inner.park_timeout(duration); - #[cfg(tokio_wasm)] + #[cfg(target_family = "wasm")] std::thread::sleep(duration); } diff --git a/tokio/src/runtime/task/mod.rs b/tokio/src/runtime/task/mod.rs index 932552fb915..abf7cc266e7 100644 --- a/tokio/src/runtime/task/mod.rs +++ b/tokio/src/runtime/task/mod.rs @@ -404,7 +404,7 @@ impl LocalNotified { impl UnownedTask { // Used in test of the inject queue. #[cfg(test)] - #[cfg_attr(tokio_wasm, allow(dead_code))] + #[cfg_attr(target_family = "wasm", allow(dead_code))] pub(super) fn into_notified(self) -> Notified { Notified(self.into_task()) } diff --git a/tokio/src/sync/tests/atomic_waker.rs b/tokio/src/sync/tests/atomic_waker.rs index 8ebfb915f4a..bfc5c77d3fe 100644 --- a/tokio/src/sync/tests/atomic_waker.rs +++ b/tokio/src/sync/tests/atomic_waker.rs @@ -37,7 +37,7 @@ fn wake_without_register() { } #[test] -#[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding +#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding fn atomic_waker_panic_safe() { use std::panic; use std::ptr; diff --git a/tokio/src/sync/tests/notify.rs b/tokio/src/sync/tests/notify.rs index 13d462666ab..a806a1b11e2 100644 --- a/tokio/src/sync/tests/notify.rs +++ b/tokio/src/sync/tests/notify.rs @@ -101,7 +101,7 @@ fn notify_simple() { } #[test] -#[cfg(not(tokio_wasm))] +#[cfg(not(target_family = "wasm"))] fn watch_test() { let rt = crate::runtime::Builder::new_current_thread() .build() diff --git a/tokio/src/sync/tests/semaphore_batch.rs b/tokio/src/sync/tests/semaphore_batch.rs index 85089cd2213..a75266941df 100644 --- a/tokio/src/sync/tests/semaphore_batch.rs +++ b/tokio/src/sync/tests/semaphore_batch.rs @@ -177,7 +177,7 @@ fn max_permits_doesnt_panic() { #[test] #[should_panic] -#[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding +#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding fn validates_max_permits() { Semaphore::new(MAX_PERMITS + 1); } From ee335b7b5a957edd8bbccadbc29bffa64025a123 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sat, 22 Jul 2023 21:36:32 +1000 Subject: [PATCH 02/12] Update README.md Co-authored-by: Alice Ryhl --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0dd06287451..7badb87bf16 100644 --- a/README.md +++ b/README.md @@ -193,7 +193,7 @@ Note that the MSRV is not increased automatically, and only as part of a minor release. The MSRV history for past minor releases can be found below: * 1.30 to now - Rust 1.63 - * 1.27 to 1.29.1 - Rust 1.56 + * 1.27 to 1.29 - Rust 1.56 * 1.17 to 1.26 - Rust 1.49 * 1.15 to 1.16 - Rust 1.46 * 1.0 to 1.14 - Rust 1.45 From 08b046c4228ad6ee0c24202e935529b409002e3b Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sat, 22 Jul 2023 21:38:35 +1000 Subject: [PATCH 03/12] Fix `/tokio/README.md`: It should be identical to `/README.md` Signed-off-by: Jiahao XU --- tokio/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tokio/README.md b/tokio/README.md index fb2c149abdd..1868a1aed16 100644 --- a/tokio/README.md +++ b/tokio/README.md @@ -192,7 +192,8 @@ released at least six months ago. The current MSRV is 1.56.0. Note that the MSRV is not increased automatically, and only as part of a minor release. The MSRV history for past minor releases can be found below: - * 1.27 to now - Rust 1.56 + * 1.30 to now - Rust 1.63 + * 1.27 to 1.29 - Rust 1.56 * 1.17 to 1.26 - Rust 1.49 * 1.15 to 1.16 - Rust 1.46 * 1.0 to 1.14 - Rust 1.45 From 8ee51c1a09eaa7daf6f79a0b00cb37d04b62b2e6 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sat, 22 Jul 2023 21:41:08 +1000 Subject: [PATCH 04/12] Bump dep socket2 to v0.5.3 Signed-off-by: Jiahao XU --- tokio/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index 6e419348e11..c6ea0d60a22 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -105,7 +105,7 @@ num_cpus = { version = "1.8.0", optional = true } parking_lot = { version = "0.12.0", optional = true } [target.'cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))'.dependencies] -socket2 = { version = "0.4.9", optional = true, features = [ "all" ] } +socket2 = { version = "0.5.3", optional = true, features = [ "all" ] } # Currently unstable. The API exposed by these features may be broken at any time. # Requires `--cfg tokio_unstable` to enable. @@ -144,7 +144,7 @@ mockall = "0.11.1" async-stream = "0.3" [target.'cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))'.dev-dependencies] -socket2 = "0.4.9" +socket2 = "0.5.3" tempfile = "3.1.0" [target.'cfg(not(all(any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown")))'.dev-dependencies] From 84feca0806eaea533dccc06b1c6c7ff81967ac24 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sat, 22 Jul 2023 21:43:39 +1000 Subject: [PATCH 05/12] Update url link to socket2 in comment Signed-off-by: Jiahao XU --- tokio/src/net/tcp/socket.rs | 4 ++-- tokio/src/net/udp.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tokio/src/net/tcp/socket.rs b/tokio/src/net/tcp/socket.rs index df792f9a615..5c7030d821d 100644 --- a/tokio/src/net/tcp/socket.rs +++ b/tokio/src/net/tcp/socket.rs @@ -457,7 +457,7 @@ impl TcpSocket { /// Windows Server 2012+.](https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options) /// /// [`set_tos`]: Self::set_tos - // https://docs.rs/socket2/0.4.2/src/socket2/socket.rs.html#1178 + // https://docs.rs/socket2/0.5.3/src/socket2/socket.rs.html#1464 #[cfg(not(any( target_os = "fuchsia", target_os = "redox", @@ -484,7 +484,7 @@ impl TcpSocket { /// /// **NOTE:** On Windows, `IP_TOS` is only supported on [Windows 8+ or /// Windows Server 2012+.](https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options) - // https://docs.rs/socket2/0.4.2/src/socket2/socket.rs.html#1178 + // https://docs.rs/socket2/0.5.3/src/socket2/socket.rs.html#1446 #[cfg(not(any( target_os = "fuchsia", target_os = "redox", diff --git a/tokio/src/net/udp.rs b/tokio/src/net/udp.rs index 8da377e16a7..cd3d6a85d7e 100644 --- a/tokio/src/net/udp.rs +++ b/tokio/src/net/udp.rs @@ -1855,7 +1855,7 @@ impl UdpSocket { /// Windows Server 2012+.](https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options) /// /// [`set_tos`]: Self::set_tos - // https://docs.rs/socket2/0.4.2/src/socket2/socket.rs.html#1178 + // https://docs.rs/socket2/0.5.3/src/socket2/socket.rs.html#1464 #[cfg(not(any( target_os = "fuchsia", target_os = "redox", @@ -1882,7 +1882,7 @@ impl UdpSocket { /// /// **NOTE:** On Windows, `IP_TOS` is only supported on [Windows 8+ or /// Windows Server 2012+.](https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options) - // https://docs.rs/socket2/0.4.2/src/socket2/socket.rs.html#1178 + // https://docs.rs/socket2/0.5.3/src/socket2/socket.rs.html#1446 #[cfg(not(any( target_os = "fuchsia", target_os = "redox", From 13563a427f73ea25c233d417c7afd0f94a509104 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sat, 22 Jul 2023 21:46:24 +1000 Subject: [PATCH 06/12] Fix `/tokio/README.md`: Make it identical to `/README.md` Signed-off-by: Jiahao XU --- tokio/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tokio/README.md b/tokio/README.md index 1868a1aed16..7badb87bf16 100644 --- a/tokio/README.md +++ b/tokio/README.md @@ -187,7 +187,7 @@ When updating this, also update: Tokio will keep a rolling MSRV (minimum supported rust version) policy of **at least** 6 months. When increasing the MSRV, the new Rust version must have been -released at least six months ago. The current MSRV is 1.56.0. +released at least six months ago. The current MSRV is 1.63.0. Note that the MSRV is not increased automatically, and only as part of a minor release. The MSRV history for past minor releases can be found below: From 1d1e5e24da9c77295f7fce01d68e5818eb78d09b Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sat, 22 Jul 2023 22:17:52 +1000 Subject: [PATCH 07/12] Replace use of `tokio_wasm` in tests with `target_family = "wasm"` Signed-off-by: Jiahao XU --- tokio/tests/_require_full.rs | 2 +- tokio/tests/sync_broadcast.rs | 6 +++--- tokio/tests/sync_mpsc.rs | 10 +++++----- tokio/tests/sync_oneshot.rs | 2 +- tokio/tests/sync_semaphore.rs | 8 ++++---- tokio/tests/sync_semaphore_owned.rs | 2 +- tokio/tests/sync_watch.rs | 2 +- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tokio/tests/_require_full.rs b/tokio/tests/_require_full.rs index 4b9698afedd..d33943a960d 100644 --- a/tokio/tests/_require_full.rs +++ b/tokio/tests/_require_full.rs @@ -1,4 +1,4 @@ -#[cfg(not(any(feature = "full", tokio_wasm)))] +#[cfg(not(any(feature = "full", target_family = "wasm")))] compile_error!("run main Tokio tests with `--features full`"); // CI sets `--cfg tokio_no_parking_lot` when trying to run tests with diff --git a/tokio/tests/sync_broadcast.rs b/tokio/tests/sync_broadcast.rs index feed03148af..59190a9603d 100644 --- a/tokio/tests/sync_broadcast.rs +++ b/tokio/tests/sync_broadcast.rs @@ -276,14 +276,14 @@ fn send_no_rx() { #[test] #[should_panic] -#[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding +#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding fn zero_capacity() { broadcast::channel::<()>(0); } #[test] #[should_panic] -#[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding +#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding fn capacity_too_big() { use std::usize; @@ -292,7 +292,7 @@ fn capacity_too_big() { #[test] #[cfg(panic = "unwind")] -#[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding +#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding fn panic_in_clone() { use std::panic::{self, AssertUnwindSafe}; diff --git a/tokio/tests/sync_mpsc.rs b/tokio/tests/sync_mpsc.rs index 6e870964113..84211a7c272 100644 --- a/tokio/tests/sync_mpsc.rs +++ b/tokio/tests/sync_mpsc.rs @@ -15,7 +15,7 @@ use tokio::sync::mpsc::error::{TryRecvError, TrySendError}; use tokio::test as maybe_tokio_test; use tokio_test::*; -#[cfg(not(tokio_wasm))] +#[cfg(not(target_family = "wasm"))] mod support { pub(crate) mod mpsc_stream; } @@ -154,7 +154,7 @@ async fn start_send_past_cap() { #[test] #[should_panic] -#[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding +#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding fn buffer_gteq_one() { mpsc::channel::(0); } @@ -470,7 +470,7 @@ fn blocking_recv() { #[tokio::test] #[should_panic] -#[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding +#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding async fn blocking_recv_async() { let (_tx, mut rx) = mpsc::channel::<()>(1); let _ = rx.blocking_recv(); @@ -495,7 +495,7 @@ fn blocking_send() { #[tokio::test] #[should_panic] -#[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding +#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding async fn blocking_send_async() { let (tx, _rx) = mpsc::channel::<()>(1); let _ = tx.blocking_send(()); @@ -648,7 +648,7 @@ async fn recv_timeout() { #[test] #[should_panic = "there is no reactor running, must be called from the context of a Tokio 1.x runtime"] -#[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding +#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding fn recv_timeout_panic() { use futures::future::FutureExt; use tokio::time::Duration; diff --git a/tokio/tests/sync_oneshot.rs b/tokio/tests/sync_oneshot.rs index 15b6923701f..f11b1071cd0 100644 --- a/tokio/tests/sync_oneshot.rs +++ b/tokio/tests/sync_oneshot.rs @@ -179,7 +179,7 @@ fn explicit_close_try_recv() { #[test] #[should_panic] -#[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding +#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding fn close_try_recv_poll() { let (_tx, rx) = oneshot::channel::(); let mut rx = task::spawn(rx); diff --git a/tokio/tests/sync_semaphore.rs b/tokio/tests/sync_semaphore.rs index 3d47ed0ed73..52c65fdb1f7 100644 --- a/tokio/tests/sync_semaphore.rs +++ b/tokio/tests/sync_semaphore.rs @@ -78,7 +78,7 @@ fn merge() { } #[test] -#[cfg(not(tokio_wasm))] // No stack unwinding on wasm targets +#[cfg(not(target_family = "wasm"))] // No stack unwinding on wasm targets #[should_panic] fn merge_unrelated_permits() { let sem1 = Arc::new(Semaphore::new(3)); @@ -118,7 +118,7 @@ fn add_max_amount_permits() { assert_eq!(s.available_permits(), tokio::sync::Semaphore::MAX_PERMITS); } -#[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding +#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding #[test] #[should_panic] fn add_more_than_max_amount_permits1() { @@ -126,7 +126,7 @@ fn add_more_than_max_amount_permits1() { s.add_permits(tokio::sync::Semaphore::MAX_PERMITS); } -#[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding +#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding #[test] #[should_panic] fn add_more_than_max_amount_permits2() { @@ -135,7 +135,7 @@ fn add_more_than_max_amount_permits2() { s.add_permits(1); } -#[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding +#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding #[test] #[should_panic] fn panic_when_exceeds_maxpermits() { diff --git a/tokio/tests/sync_semaphore_owned.rs b/tokio/tests/sync_semaphore_owned.rs index f6945764786..6f66d6adc98 100644 --- a/tokio/tests/sync_semaphore_owned.rs +++ b/tokio/tests/sync_semaphore_owned.rs @@ -104,7 +104,7 @@ fn merge() { } #[test] -#[cfg(not(tokio_wasm))] // No stack unwinding on wasm targets +#[cfg(not(target_family = "wasm"))] // No stack unwinding on wasm targets #[should_panic] fn merge_unrelated_permits() { let sem1 = Arc::new(Semaphore::new(3)); diff --git a/tokio/tests/sync_watch.rs b/tokio/tests/sync_watch.rs index d4f8ce87d95..9d169641d23 100644 --- a/tokio/tests/sync_watch.rs +++ b/tokio/tests/sync_watch.rs @@ -214,7 +214,7 @@ fn reopened_after_subscribe() { #[test] #[cfg(panic = "unwind")] -#[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding +#[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding fn send_modify_panic() { let (tx, mut rx) = watch::channel("one"); From c2c13d483babb04167447a7b0f6e24cd2d2b75e2 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sat, 22 Jul 2023 22:57:24 +1000 Subject: [PATCH 08/12] Rm `build.rs` and replace `tokio_wasi` & `tokio_wasm_not_wasi` Replace `tokio_wasi` with `target_os = "wasi"` and replace latter with `cfg_is_wasm_not_wasi!` or `all(target_family = "wasm", not(target_os = "wasi"))`. Signed-off-by: Jiahao XU --- tokio/build.rs | 15 -------- tokio/src/io/mod.rs | 4 +-- tokio/src/lib.rs | 20 ----------- tokio/src/macros/cfg.rs | 12 +++---- tokio/src/net/tcp/listener.rs | 4 +-- tokio/src/net/tcp/stream.rs | 4 +-- tokio/src/runtime/blocking/pool.rs | 2 +- tokio/src/runtime/blocking/schedule.rs | 8 ++--- tokio/src/runtime/builder.rs | 12 +++---- tokio/src/runtime/coop.rs | 5 +-- tokio/src/runtime/handle.rs | 12 +++---- tokio/src/runtime/io/driver.rs | 10 +++--- tokio/src/runtime/io/registration.rs | 2 +- tokio/src/runtime/mod.rs | 2 +- tokio/src/runtime/runtime.rs | 12 +++---- tokio/src/runtime/scheduler/inject/shared.rs | 5 ++- tokio/src/runtime/scheduler/mod.rs | 32 ++++++++--------- tokio/src/runtime/task/trace/mod.rs | 8 +++-- tokio/src/runtime/time/tests/mod.rs | 2 +- tokio/src/sync/tests/atomic_waker.rs | 5 +-- tokio/src/sync/tests/notify.rs | 5 +-- tokio/src/sync/tests/semaphore_batch.rs | 5 +-- tokio/tests/async_send_sync.rs | 2 +- tokio/tests/buffered.rs | 2 +- tokio/tests/fs.rs | 2 +- tokio/tests/fs_canonicalize_dir.rs | 2 +- tokio/tests/fs_copy.rs | 2 +- tokio/tests/fs_dir.rs | 2 +- tokio/tests/fs_file.rs | 2 +- tokio/tests/fs_link.rs | 2 +- tokio/tests/fs_open_options.rs | 2 +- tokio/tests/fs_open_options_windows.rs | 2 +- tokio/tests/fs_remove_dir_all.rs | 2 +- tokio/tests/fs_remove_file.rs | 2 +- tokio/tests/fs_rename.rs | 2 +- tokio/tests/fs_symlink_dir_windows.rs | 2 +- tokio/tests/fs_symlink_file_windows.rs | 2 +- tokio/tests/fs_try_exists.rs | 2 +- tokio/tests/io_copy_bidirectional.rs | 2 +- tokio/tests/io_driver.rs | 2 +- tokio/tests/io_driver_drop.rs | 2 +- tokio/tests/io_fill_buf.rs | 2 +- tokio/tests/io_panic.rs | 2 +- tokio/tests/io_read.rs | 2 +- tokio/tests/io_split.rs | 2 +- tokio/tests/io_take.rs | 2 +- tokio/tests/join_handle_panic.rs | 2 +- tokio/tests/macros_join.rs | 6 ++-- tokio/tests/macros_pin.rs | 4 +-- tokio/tests/macros_rename_test.rs | 2 +- tokio/tests/macros_select.rs | 6 ++-- tokio/tests/macros_test.rs | 2 +- tokio/tests/macros_try_join.rs | 4 +-- tokio/tests/net_bind_resource.rs | 2 +- tokio/tests/net_lookup_host.rs | 2 +- tokio/tests/net_panic.rs | 2 +- tokio/tests/no_rt.rs | 2 +- tokio/tests/process_smoke.rs | 2 +- tokio/tests/rt_basic.rs | 10 +++--- tokio/tests/rt_common.rs | 20 +++++------ tokio/tests/rt_handle.rs | 2 +- tokio/tests/rt_handle_block_on.rs | 16 ++++----- tokio/tests/rt_metrics.rs | 2 +- tokio/tests/rt_panic.rs | 2 +- tokio/tests/rt_threaded.rs | 2 +- tokio/tests/rt_threaded_alt.rs | 2 +- tokio/tests/signal_no_rt.rs | 2 +- tokio/tests/sync_barrier.rs | 2 +- tokio/tests/sync_broadcast.rs | 4 +-- tokio/tests/sync_errors.rs | 2 +- tokio/tests/sync_mpsc.rs | 17 ++++----- tokio/tests/sync_mpsc_weak.rs | 2 +- tokio/tests/sync_mutex.rs | 6 ++-- tokio/tests/sync_mutex_owned.rs | 6 ++-- tokio/tests/sync_notify.rs | 2 +- tokio/tests/sync_oneshot.rs | 6 ++-- tokio/tests/sync_panic.rs | 2 +- tokio/tests/sync_rwlock.rs | 8 ++--- tokio/tests/sync_semaphore.rs | 2 +- tokio/tests/sync_semaphore_owned.rs | 2 +- tokio/tests/sync_watch.rs | 2 +- tokio/tests/task_abort.rs | 2 +- tokio/tests/task_blocking.rs | 2 +- tokio/tests/task_id.rs | 26 +++++++------- tokio/tests/task_local.rs | 2 +- tokio/tests/task_local_set.rs | 37 +++++++++++--------- tokio/tests/task_panic.rs | 2 +- tokio/tests/tcp_accept.rs | 2 +- tokio/tests/tcp_connect.rs | 2 +- tokio/tests/tcp_echo.rs | 2 +- tokio/tests/tcp_into_split.rs | 2 +- tokio/tests/tcp_into_std.rs | 2 +- tokio/tests/tcp_peek.rs | 2 +- tokio/tests/tcp_shutdown.rs | 2 +- tokio/tests/tcp_socket.rs | 2 +- tokio/tests/tcp_split.rs | 2 +- tokio/tests/tcp_stream.rs | 2 +- tokio/tests/time_panic.rs | 2 +- tokio/tests/time_pause.rs | 6 ++-- tokio/tests/time_rt.rs | 2 +- tokio/tests/time_sleep.rs | 2 +- tokio/tests/time_timeout.rs | 2 +- tokio/tests/udp.rs | 2 +- tokio/tests/unwindsafe.rs | 2 +- 104 files changed, 240 insertions(+), 260 deletions(-) delete mode 100644 tokio/build.rs diff --git a/tokio/build.rs b/tokio/build.rs deleted file mode 100644 index cf2e8bf6621..00000000000 --- a/tokio/build.rs +++ /dev/null @@ -1,15 +0,0 @@ -fn emit(cfg: &str) { - println!("cargo:rustc-cfg={}", cfg); -} - -fn main() { - let target = ::std::env::var("TARGET").unwrap_or_default(); - - if target.starts_with("wasm") { - if target.contains("wasi") { - emit("tokio_wasi"); - } else { - emit("tokio_wasm_not_wasi"); - } - } -} diff --git a/tokio/src/io/mod.rs b/tokio/src/io/mod.rs index 666d69cb438..0fd6cc2c5cb 100644 --- a/tokio/src/io/mod.rs +++ b/tokio/src/io/mod.rs @@ -223,11 +223,11 @@ cfg_io_driver_impl! { pub use ready::Ready; } - #[cfg_attr(tokio_wasi, allow(unused_imports))] + #[cfg_attr(target_os = "wasi", allow(unused_imports))] mod poll_evented; #[cfg(not(loom))] - #[cfg_attr(tokio_wasi, allow(unused_imports))] + #[cfg_attr(target_os = "wasi", allow(unused_imports))] pub(crate) use poll_evented::PollEvented; } diff --git a/tokio/src/lib.rs b/tokio/src/lib.rs index 9453365adad..21d19bac9d9 100644 --- a/tokio/src/lib.rs +++ b/tokio/src/lib.rs @@ -456,26 +456,6 @@ compile_error! { "Tokio requires the platform pointer width to be 32, 64, or 128 bits" } -// Ensure that our build script has correctly set cfg flags for wasm. -// -// Each condition is written all(a, not(b)). This should be read as -// "if a, then we must also have b". -#[cfg(any( - all(target_arch = "wasm32", not(target_family = "wasm")), - all(target_arch = "wasm64", not(target_family = "wasm")), - all(target_family = "wasm", not(target_family = "wasm")), - all(target_os = "wasi", not(target_family = "wasm")), - all(target_os = "wasi", not(tokio_wasi)), - all(target_os = "wasi", tokio_wasm_not_wasi), - all( - target_family = "wasm", - not(any(target_arch = "wasm32", target_arch = "wasm64")) - ), - all(tokio_wasm_not_wasi, not(target_family = "wasm")), - all(tokio_wasi, not(target_family = "wasm")) -))] -compile_error!("Tokio's build script has incorrectly detected wasm."); - #[cfg(all( not(tokio_unstable), target_family = "wasm", diff --git a/tokio/src/macros/cfg.rs b/tokio/src/macros/cfg.rs index a80e323cf43..f60c040fd01 100644 --- a/tokio/src/macros/cfg.rs +++ b/tokio/src/macros/cfg.rs @@ -85,7 +85,7 @@ macro_rules! cfg_fs { ($($item:item)*) => { $( #[cfg(feature = "fs")] - #[cfg(not(tokio_wasi))] + #[cfg(not(target_os = "wasi"))] #[cfg_attr(docsrs, doc(cfg(feature = "fs")))] $item )* @@ -276,7 +276,7 @@ macro_rules! cfg_process { #[cfg(feature = "process")] #[cfg_attr(docsrs, doc(cfg(feature = "process")))] #[cfg(not(loom))] - #[cfg(not(tokio_wasi))] + #[cfg(not(target_os = "wasi"))] $item )* } @@ -305,7 +305,7 @@ macro_rules! cfg_signal { #[cfg(feature = "signal")] #[cfg_attr(docsrs, doc(cfg(feature = "signal")))] #[cfg(not(loom))] - #[cfg(not(tokio_wasi))] + #[cfg(not(target_os = "wasi"))] $item )* } @@ -372,7 +372,7 @@ macro_rules! cfg_not_rt { macro_rules! cfg_rt_multi_thread { ($($item:item)*) => { $( - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] #[cfg_attr(docsrs, doc(cfg(feature = "rt-multi-thread")))] $item )* @@ -585,7 +585,7 @@ macro_rules! cfg_not_has_const_mutex_new { macro_rules! cfg_not_wasi { ($($item:item)*) => { $( - #[cfg(not(tokio_wasi))] + #[cfg(not(target_os = "wasi"))] $item )* } @@ -594,7 +594,7 @@ macro_rules! cfg_not_wasi { macro_rules! cfg_is_wasm_not_wasi { ($($item:item)*) => { $( - #[cfg(tokio_wasm_not_wasi)] + #[cfg(all(target_family = "wasm", not(target_os = "wasi")))] $item )* } diff --git a/tokio/src/net/tcp/listener.rs b/tokio/src/net/tcp/listener.rs index 34e393c895f..07ac6311d1e 100644 --- a/tokio/src/net/tcp/listener.rs +++ b/tokio/src/net/tcp/listener.rs @@ -281,7 +281,7 @@ impl TcpListener { .map(|raw_socket| unsafe { std::net::TcpListener::from_raw_socket(raw_socket) }) } - #[cfg(tokio_wasi)] + #[cfg(target_os = "wasi")] { use std::os::wasi::io::{FromRawFd, IntoRawFd}; self.io @@ -416,7 +416,7 @@ mod sys { } cfg_unstable! { - #[cfg(tokio_wasi)] + #[cfg(target_os = "wasi")] mod sys { use super::TcpListener; use std::os::wasi::prelude::*; diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index b7104d78b40..1c9f1fc56e6 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -258,7 +258,7 @@ impl TcpStream { .map(|raw_socket| unsafe { std::net::TcpStream::from_raw_socket(raw_socket) }) } - #[cfg(tokio_wasi)] + #[cfg(target_os = "wasi")] { use std::os::wasi::io::{FromRawFd, IntoRawFd}; self.io @@ -1405,7 +1405,7 @@ cfg_windows! { } } -#[cfg(all(tokio_unstable, tokio_wasi))] +#[cfg(all(tokio_unstable, target_os = "wasi"))] mod sys { use super::TcpStream; use std::os::wasi::prelude::*; diff --git a/tokio/src/runtime/blocking/pool.rs b/tokio/src/runtime/blocking/pool.rs index a23b0a0d2de..33778670c98 100644 --- a/tokio/src/runtime/blocking/pool.rs +++ b/tokio/src/runtime/blocking/pool.rs @@ -173,7 +173,7 @@ const KEEP_ALIVE: Duration = Duration::from_secs(10); /// Tasks will be scheduled as non-mandatory, meaning they may not get executed /// in case of runtime shutdown. #[track_caller] -#[cfg_attr(tokio_wasi, allow(dead_code))] +#[cfg_attr(target_os = "wasi", allow(dead_code))] pub(crate) fn spawn_blocking(func: F) -> JoinHandle where F: FnOnce() -> R + Send + 'static, diff --git a/tokio/src/runtime/blocking/schedule.rs b/tokio/src/runtime/blocking/schedule.rs index b4c6a2862b3..8dfe5fd10f2 100644 --- a/tokio/src/runtime/blocking/schedule.rs +++ b/tokio/src/runtime/blocking/schedule.rs @@ -23,9 +23,9 @@ impl BlockingSchedule { scheduler::Handle::CurrentThread(handle) => { handle.driver.clock.inhibit_auto_advance(); } - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] scheduler::Handle::MultiThread(_) => {} - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] scheduler::Handle::MultiThreadAlt(_) => {} } } @@ -45,9 +45,9 @@ impl task::Schedule for BlockingSchedule { handle.driver.clock.allow_auto_advance(); handle.driver.unpark(); } - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] scheduler::Handle::MultiThread(_) => {} - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] scheduler::Handle::MultiThreadAlt(_) => {} } } diff --git a/tokio/src/runtime/builder.rs b/tokio/src/runtime/builder.rs index d2e10b004ae..38462ef485d 100644 --- a/tokio/src/runtime/builder.rs +++ b/tokio/src/runtime/builder.rs @@ -197,9 +197,9 @@ pub(crate) type ThreadNameFn = std::sync::Arc String + Send + Sync + #[derive(Clone, Copy)] pub(crate) enum Kind { CurrentThread, - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] MultiThread, - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] MultiThreadAlt, } @@ -676,9 +676,9 @@ impl Builder { pub fn build(&mut self) -> io::Result { match &self.kind { Kind::CurrentThread => self.build_current_thread_runtime(), - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Kind::MultiThread => self.build_threaded_runtime(), - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] Kind::MultiThreadAlt => self.build_alt_threaded_runtime(), } } @@ -687,9 +687,9 @@ impl Builder { driver::Cfg { enable_pause_time: match self.kind { Kind::CurrentThread => true, - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Kind::MultiThread => false, - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] Kind::MultiThreadAlt => false, }, enable_io: self.enable_io, diff --git a/tokio/src/runtime/coop.rs b/tokio/src/runtime/coop.rs index 2dba2461592..32c13b80e8e 100644 --- a/tokio/src/runtime/coop.rs +++ b/tokio/src/runtime/coop.rs @@ -246,8 +246,9 @@ cfg_coop! { mod test { use super::*; - #[cfg(tokio_wasm_not_wasi)] - use wasm_bindgen_test::wasm_bindgen_test as test; + cfg_is_wasm_not_wasi! { + use wasm_bindgen_test::wasm_bindgen_test as test; + } fn get() -> Budget { context::budget(|cell| cell.get()).unwrap_or(Budget::unconstrained()) diff --git a/tokio/src/runtime/handle.rs b/tokio/src/runtime/handle.rs index 121ed8815f8..ebc7bbaff63 100644 --- a/tokio/src/runtime/handle.rs +++ b/tokio/src/runtime/handle.rs @@ -355,9 +355,9 @@ impl Handle { pub fn runtime_flavor(&self) -> RuntimeFlavor { match self.inner { scheduler::Handle::CurrentThread(_) => RuntimeFlavor::CurrentThread, - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] scheduler::Handle::MultiThread(_) => RuntimeFlavor::MultiThread, - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] scheduler::Handle::MultiThreadAlt(_) => RuntimeFlavor::MultiThreadAlt, } } @@ -385,9 +385,9 @@ impl Handle { pub fn id(&self) -> runtime::Id { let owned_id = match &self.inner { scheduler::Handle::CurrentThread(handle) => handle.owned_id(), - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] scheduler::Handle::MultiThread(handle) => handle.owned_id(), - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] scheduler::Handle::MultiThreadAlt(handle) => handle.owned_id(), }; owned_id.into() @@ -529,7 +529,7 @@ cfg_taskdump! { pub async fn dump(&self) -> crate::runtime::Dump { match &self.inner { scheduler::Handle::CurrentThread(handle) => handle.dump(), - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] scheduler::Handle::MultiThread(handle) => { // perform the trace in a separate thread so that the // trace itself does not appear in the taskdump. @@ -539,7 +539,7 @@ cfg_taskdump! { handle.dump().await }).await }, - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] scheduler::Handle::MultiThreadAlt(_) => panic!("task dump not implemented for this runtime flavor"), } } diff --git a/tokio/src/runtime/io/driver.rs b/tokio/src/runtime/io/driver.rs index a55129210f6..755cb9d1413 100644 --- a/tokio/src/runtime/io/driver.rs +++ b/tokio/src/runtime/io/driver.rs @@ -45,7 +45,7 @@ pub(crate) struct Handle { /// Used to wake up the reactor from a call to `turn`. /// Not supported on Wasi due to lack of threading support. - #[cfg(not(tokio_wasi))] + #[cfg(not(target_os = "wasi"))] waker: mio::Waker, pub(crate) metrics: IoDriverMetrics, @@ -97,7 +97,7 @@ impl Driver { /// creation. pub(crate) fn new(nevents: usize) -> io::Result<(Driver, Handle)> { let poll = mio::Poll::new()?; - #[cfg(not(tokio_wasi))] + #[cfg(not(target_os = "wasi"))] let waker = mio::Waker::new(poll.registry(), TOKEN_WAKEUP)?; let registry = poll.registry().try_clone()?; @@ -114,7 +114,7 @@ impl Driver { registry, registrations, synced: Mutex::new(synced), - #[cfg(not(tokio_wasi))] + #[cfg(not(target_os = "wasi"))] waker, metrics: IoDriverMetrics::default(), }; @@ -156,7 +156,7 @@ impl Driver { match self.poll.poll(events, max_wait) { Ok(_) => {} Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {} - #[cfg(tokio_wasi)] + #[cfg(target_os = "wasi")] Err(e) if e.kind() == io::ErrorKind::InvalidInput => { // In case of wasm32_wasi this error happens, when trying to poll without subscriptions // just return from the park, as there would be nothing, which wakes us up. @@ -212,7 +212,7 @@ impl Handle { /// blocked in `turn`, then the next call to `turn` will not block and /// return immediately. pub(crate) fn unpark(&self) { - #[cfg(not(tokio_wasi))] + #[cfg(not(target_os = "wasi"))] self.waker.wake().expect("failed to wake I/O driver"); } diff --git a/tokio/src/runtime/io/registration.rs b/tokio/src/runtime/io/registration.rs index 4e52d28476c..759589863eb 100644 --- a/tokio/src/runtime/io/registration.rs +++ b/tokio/src/runtime/io/registration.rs @@ -118,7 +118,7 @@ impl Registration { // Uses the poll path, requiring the caller to ensure mutual exclusion for // correctness. Only the last task to call this function is notified. - #[cfg(not(tokio_wasi))] + #[cfg(not(target_os = "wasi"))] pub(crate) fn poll_read_io( &self, cx: &mut Context<'_>, diff --git a/tokio/src/runtime/mod.rs b/tokio/src/runtime/mod.rs index f0d3a0e6c2e..e3369cb2249 100644 --- a/tokio/src/runtime/mod.rs +++ b/tokio/src/runtime/mod.rs @@ -212,7 +212,7 @@ cfg_rt! { use config::Config; mod blocking; - #[cfg_attr(tokio_wasi, allow(unused_imports))] + #[cfg_attr(target_os = "wasi", allow(unused_imports))] pub(crate) use blocking::spawn_blocking; cfg_trace! { diff --git a/tokio/src/runtime/runtime.rs b/tokio/src/runtime/runtime.rs index ddec2ab5f20..5d79685300b 100644 --- a/tokio/src/runtime/runtime.rs +++ b/tokio/src/runtime/runtime.rs @@ -125,11 +125,11 @@ pub(super) enum Scheduler { CurrentThread(CurrentThread), /// Execute tasks across multiple threads. - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] MultiThread(MultiThread), /// Execute tasks across multiple threads. - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] MultiThreadAlt(MultiThreadAlt), } @@ -345,9 +345,9 @@ impl Runtime { match &self.scheduler { Scheduler::CurrentThread(exec) => exec.block_on(&self.handle.inner, future), - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Scheduler::MultiThread(exec) => exec.block_on(&self.handle.inner, future), - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] Scheduler::MultiThreadAlt(exec) => exec.block_on(&self.handle.inner, future), } } @@ -463,13 +463,13 @@ impl Drop for Runtime { let _guard = context::try_set_current(&self.handle.inner); current_thread.shutdown(&self.handle.inner); } - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Scheduler::MultiThread(multi_thread) => { // The threaded scheduler drops its tasks on its worker threads, which is // already in the runtime's context. multi_thread.shutdown(&self.handle.inner); } - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] Scheduler::MultiThreadAlt(multi_thread) => { // The threaded scheduler drops its tasks on its worker threads, which is // already in the runtime's context. diff --git a/tokio/src/runtime/scheduler/inject/shared.rs b/tokio/src/runtime/scheduler/inject/shared.rs index 7fdd2839dd2..5a7b9c6a903 100644 --- a/tokio/src/runtime/scheduler/inject/shared.rs +++ b/tokio/src/runtime/scheduler/inject/shared.rs @@ -38,7 +38,10 @@ impl Shared { } // Kind of annoying to have to include the cfg here - #[cfg(any(tokio_taskdump, all(feature = "rt-multi-thread", not(tokio_wasi))))] + #[cfg(any( + tokio_taskdump, + all(feature = "rt-multi-thread", not(target_os = "wasi")) + ))] pub(crate) fn is_closed(&self, synced: &Synced) -> bool { synced.is_closed } diff --git a/tokio/src/runtime/scheduler/mod.rs b/tokio/src/runtime/scheduler/mod.rs index de49dae5e81..d02c0272c90 100644 --- a/tokio/src/runtime/scheduler/mod.rs +++ b/tokio/src/runtime/scheduler/mod.rs @@ -32,10 +32,10 @@ pub(crate) enum Handle { #[cfg(feature = "rt")] CurrentThread(Arc), - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] MultiThread(Arc), - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] MultiThreadAlt(Arc), // TODO: This is to avoid triggering "dead code" warnings many other places @@ -49,10 +49,10 @@ pub(crate) enum Handle { pub(super) enum Context { CurrentThread(current_thread::Context), - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] MultiThread(multi_thread::Context), - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] MultiThreadAlt(multi_thread_alt::Context), } @@ -63,10 +63,10 @@ impl Handle { #[cfg(feature = "rt")] Handle::CurrentThread(ref h) => &h.driver, - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Handle::MultiThread(ref h) => &h.driver, - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] Handle::MultiThreadAlt(ref h) => &h.driver, #[cfg(not(feature = "rt"))] @@ -89,10 +89,10 @@ cfg_rt! { match $self { $ty::CurrentThread($h) => $e, - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] $ty::MultiThread($h) => $e, - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] $ty::MultiThreadAlt($h) => $e, } } @@ -119,10 +119,10 @@ cfg_rt! { match self { Handle::CurrentThread(h) => current_thread::Handle::spawn(h, future, id), - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Handle::MultiThread(h) => multi_thread::Handle::spawn(h, future, id), - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] Handle::MultiThreadAlt(h) => multi_thread_alt::Handle::spawn(h, future, id), } } @@ -131,10 +131,10 @@ cfg_rt! { match *self { Handle::CurrentThread(_) => {}, - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Handle::MultiThread(ref h) => h.shutdown(), - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] Handle::MultiThreadAlt(ref h) => h.shutdown(), } } @@ -146,7 +146,7 @@ cfg_rt! { pub(crate) fn as_current_thread(&self) -> &Arc { match self { Handle::CurrentThread(handle) => handle, - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] _ => panic!("not a CurrentThread handle"), } } @@ -170,9 +170,9 @@ cfg_rt! { pub(crate) fn num_workers(&self) -> usize { match self { Handle::CurrentThread(_) => 1, - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Handle::MultiThread(handle) => handle.num_workers(), - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(target_os = "wasi")))] Handle::MultiThreadAlt(handle) => handle.num_workers(), } } @@ -216,7 +216,7 @@ cfg_rt! { pub(crate) fn expect_current_thread(&self) -> ¤t_thread::Context { match self { Context::CurrentThread(context) => context, - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] _ => panic!("expected `CurrentThread::Context`") } } diff --git a/tokio/src/runtime/task/trace/mod.rs b/tokio/src/runtime/task/trace/mod.rs index 9c61014e865..af2c5644b1a 100644 --- a/tokio/src/runtime/task/trace/mod.rs +++ b/tokio/src/runtime/task/trace/mod.rs @@ -184,9 +184,13 @@ pub(crate) fn trace_leaf(cx: &mut task::Context<'_>) -> Poll<()> { if let Some(scheduler) = scheduler { match scheduler { scheduler::Context::CurrentThread(s) => s.defer.defer(cx.waker()), - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] scheduler::Context::MultiThread(s) => s.defer.defer(cx.waker()), - #[cfg(all(tokio_unstable, feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all( + tokio_unstable, + feature = "rt-multi-thread", + not(target_os = "wasi") + ))] scheduler::Context::MultiThreadAlt(_) => unimplemented!(), } } diff --git a/tokio/src/runtime/time/tests/mod.rs b/tokio/src/runtime/time/tests/mod.rs index 155d99a348f..e7ab222ef63 100644 --- a/tokio/src/runtime/time/tests/mod.rs +++ b/tokio/src/runtime/time/tests/mod.rs @@ -1,4 +1,4 @@ -#![cfg(not(tokio_wasi))] +#![cfg(not(target_os = "wasi"))] use std::{task::Context, time::Duration}; diff --git a/tokio/src/sync/tests/atomic_waker.rs b/tokio/src/sync/tests/atomic_waker.rs index bfc5c77d3fe..d01aefc897d 100644 --- a/tokio/src/sync/tests/atomic_waker.rs +++ b/tokio/src/sync/tests/atomic_waker.rs @@ -12,8 +12,9 @@ impl AssertSync for AtomicWaker {} impl AssertSend for Waker {} impl AssertSync for Waker {} -#[cfg(tokio_wasm_not_wasi)] -use wasm_bindgen_test::wasm_bindgen_test as test; +cfg_is_wasm_not_wasi! { + use wasm_bindgen_test::wasm_bindgen_test as test; +} #[test] fn basic_usage() { diff --git a/tokio/src/sync/tests/notify.rs b/tokio/src/sync/tests/notify.rs index a806a1b11e2..4af495ad601 100644 --- a/tokio/src/sync/tests/notify.rs +++ b/tokio/src/sync/tests/notify.rs @@ -3,8 +3,9 @@ use std::future::Future; use std::sync::Arc; use std::task::{Context, RawWaker, RawWakerVTable, Waker}; -#[cfg(tokio_wasm_not_wasi)] -use wasm_bindgen_test::wasm_bindgen_test as test; +cfg_is_wasm_not_wasi! { + use wasm_bindgen_test::wasm_bindgen_test as test; +} #[test] fn notify_clones_waker_before_lock() { diff --git a/tokio/src/sync/tests/semaphore_batch.rs b/tokio/src/sync/tests/semaphore_batch.rs index a75266941df..403b6caa381 100644 --- a/tokio/src/sync/tests/semaphore_batch.rs +++ b/tokio/src/sync/tests/semaphore_batch.rs @@ -3,8 +3,9 @@ use tokio_test::*; const MAX_PERMITS: usize = crate::sync::Semaphore::MAX_PERMITS; -#[cfg(tokio_wasm_not_wasi)] -use wasm_bindgen_test::wasm_bindgen_test as test; +cfg_is_wasm_not_wasi! { + use wasm_bindgen_test::wasm_bindgen_test as test; +} #[test] fn poll_acquire_one_available() { diff --git a/tokio/tests/async_send_sync.rs b/tokio/tests/async_send_sync.rs index 32c03a54be2..dfd26f9e9e7 100644 --- a/tokio/tests/async_send_sync.rs +++ b/tokio/tests/async_send_sync.rs @@ -130,7 +130,7 @@ macro_rules! assert_value { macro_rules! cfg_not_wasi { ($($item:item)*) => { $( - #[cfg(not(tokio_wasi))] + #[cfg(not(target_os = "wasi"))] $item )* } diff --git a/tokio/tests/buffered.rs b/tokio/tests/buffered.rs index 4251c3fcc0b..27e75d10d52 100644 --- a/tokio/tests/buffered.rs +++ b/tokio/tests/buffered.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi does not support bind() +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support bind() use tokio::net::TcpListener; use tokio_test::assert_ok; diff --git a/tokio/tests/fs.rs b/tokio/tests/fs.rs index ba38b719f2c..9f739f60c44 100644 --- a/tokio/tests/fs.rs +++ b/tokio/tests/fs.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi does not support file operations +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support file operations use tokio::fs; use tokio_test::assert_ok; diff --git a/tokio/tests/fs_canonicalize_dir.rs b/tokio/tests/fs_canonicalize_dir.rs index 83f0d813737..e7f6c68ea91 100644 --- a/tokio/tests/fs_canonicalize_dir.rs +++ b/tokio/tests/fs_canonicalize_dir.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // WASI does not support all fs operations +#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations use tokio::fs; diff --git a/tokio/tests/fs_copy.rs b/tokio/tests/fs_copy.rs index e6e5b666f4a..3311710e9dc 100644 --- a/tokio/tests/fs_copy.rs +++ b/tokio/tests/fs_copy.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // WASI does not support all fs operations +#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations use tempfile::tempdir; use tokio::fs; diff --git a/tokio/tests/fs_dir.rs b/tokio/tests/fs_dir.rs index 5f653cb2135..3f28c1a07b3 100644 --- a/tokio/tests/fs_dir.rs +++ b/tokio/tests/fs_dir.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // WASI does not support all fs operations +#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations use tokio::fs; use tokio_test::{assert_err, assert_ok}; diff --git a/tokio/tests/fs_file.rs b/tokio/tests/fs_file.rs index 94d872a57aa..40bd4fce564 100644 --- a/tokio/tests/fs_file.rs +++ b/tokio/tests/fs_file.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // WASI does not support all fs operations +#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations use std::io::prelude::*; use tempfile::NamedTempFile; diff --git a/tokio/tests/fs_link.rs b/tokio/tests/fs_link.rs index 681b566607e..48da5f67dd9 100644 --- a/tokio/tests/fs_link.rs +++ b/tokio/tests/fs_link.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // WASI does not support all fs operations +#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations use tokio::fs; diff --git a/tokio/tests/fs_open_options.rs b/tokio/tests/fs_open_options.rs index e8d8b51b39f..41cfb45460c 100644 --- a/tokio/tests/fs_open_options.rs +++ b/tokio/tests/fs_open_options.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // WASI does not support all fs operations +#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations use std::io::Write; use tempfile::NamedTempFile; diff --git a/tokio/tests/fs_open_options_windows.rs b/tokio/tests/fs_open_options_windows.rs index 398e6a12b36..f09e8b4520c 100644 --- a/tokio/tests/fs_open_options_windows.rs +++ b/tokio/tests/fs_open_options_windows.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // WASI does not support all fs operations +#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations #![cfg(windows)] use tokio::fs::OpenOptions; diff --git a/tokio/tests/fs_remove_dir_all.rs b/tokio/tests/fs_remove_dir_all.rs index 53a2fd34f36..5c71bdfda63 100644 --- a/tokio/tests/fs_remove_dir_all.rs +++ b/tokio/tests/fs_remove_dir_all.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // WASI does not support all fs operations +#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations use tempfile::tempdir; use tokio::fs; diff --git a/tokio/tests/fs_remove_file.rs b/tokio/tests/fs_remove_file.rs index 14fd680dabe..ea477213988 100644 --- a/tokio/tests/fs_remove_file.rs +++ b/tokio/tests/fs_remove_file.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // WASI does not support all fs operations +#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations use tempfile::tempdir; use tokio::fs; diff --git a/tokio/tests/fs_rename.rs b/tokio/tests/fs_rename.rs index 382fea079bd..91bb39ee359 100644 --- a/tokio/tests/fs_rename.rs +++ b/tokio/tests/fs_rename.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // WASI does not support all fs operations +#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations use tempfile::tempdir; use tokio::fs; diff --git a/tokio/tests/fs_symlink_dir_windows.rs b/tokio/tests/fs_symlink_dir_windows.rs index d80354268a2..bcfba214be5 100644 --- a/tokio/tests/fs_symlink_dir_windows.rs +++ b/tokio/tests/fs_symlink_dir_windows.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // WASI does not support all fs operations +#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations #![cfg(windows)] use tempfile::tempdir; diff --git a/tokio/tests/fs_symlink_file_windows.rs b/tokio/tests/fs_symlink_file_windows.rs index 50eaf8aab75..4bc032ed79f 100644 --- a/tokio/tests/fs_symlink_file_windows.rs +++ b/tokio/tests/fs_symlink_file_windows.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // WASI does not support all fs operations +#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations #![cfg(windows)] use tempfile::tempdir; diff --git a/tokio/tests/fs_try_exists.rs b/tokio/tests/fs_try_exists.rs index 00d23650015..dca554dda45 100644 --- a/tokio/tests/fs_try_exists.rs +++ b/tokio/tests/fs_try_exists.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // WASI does not support all fs operations +#![cfg(all(feature = "full", not(target_os = "wasi")))] // WASI does not support all fs operations use tempfile::tempdir; use tokio::fs; diff --git a/tokio/tests/io_copy_bidirectional.rs b/tokio/tests/io_copy_bidirectional.rs index c5496759550..10eba3166ac 100644 --- a/tokio/tests/io_copy_bidirectional.rs +++ b/tokio/tests/io_copy_bidirectional.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi does not support bind() +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support bind() use std::time::Duration; use tokio::io::{self, copy_bidirectional, AsyncReadExt, AsyncWriteExt}; diff --git a/tokio/tests/io_driver.rs b/tokio/tests/io_driver.rs index 97018e0f967..2e2c84746c9 100644 --- a/tokio/tests/io_driver.rs +++ b/tokio/tests/io_driver.rs @@ -1,6 +1,6 @@ #![warn(rust_2018_idioms)] // Wasi does not support panic recovery or threading -#![cfg(all(feature = "full", not(tokio_wasi)))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::net::TcpListener; use tokio::runtime; diff --git a/tokio/tests/io_driver_drop.rs b/tokio/tests/io_driver_drop.rs index 0a384d4196d..c3182637916 100644 --- a/tokio/tests/io_driver_drop.rs +++ b/tokio/tests/io_driver_drop.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi does not support bind +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support bind use tokio::net::TcpListener; use tokio::runtime; diff --git a/tokio/tests/io_fill_buf.rs b/tokio/tests/io_fill_buf.rs index 62c3f1b370d..534417c855d 100644 --- a/tokio/tests/io_fill_buf.rs +++ b/tokio/tests/io_fill_buf.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi does not support file operations +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support file operations use tempfile::NamedTempFile; use tokio::fs::File; diff --git a/tokio/tests/io_panic.rs b/tokio/tests/io_panic.rs index 922d7c076e7..9b2bf6a3bd8 100644 --- a/tokio/tests/io_panic.rs +++ b/tokio/tests/io_panic.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi does not support panic recovery +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery use std::task::{Context, Poll}; use std::{error::Error, pin::Pin}; diff --git a/tokio/tests/io_read.rs b/tokio/tests/io_read.rs index 7f74c5e857a..6bea0ac865e 100644 --- a/tokio/tests/io_read.rs +++ b/tokio/tests/io_read.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi does not support panic recovery +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery use tokio::io::{AsyncRead, AsyncReadExt, ReadBuf}; use tokio_test::assert_ok; diff --git a/tokio/tests/io_split.rs b/tokio/tests/io_split.rs index 4cbd2a2d1fb..77b77a3a04c 100644 --- a/tokio/tests/io_split.rs +++ b/tokio/tests/io_split.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi does not support panic recovery +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery use tokio::io::{split, AsyncRead, AsyncWrite, ReadBuf, ReadHalf, WriteHalf}; diff --git a/tokio/tests/io_take.rs b/tokio/tests/io_take.rs index fba01d2e0c6..539f17f3a2d 100644 --- a/tokio/tests/io_take.rs +++ b/tokio/tests/io_take.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi does not support panic recovery +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery use std::pin::Pin; use std::task::{Context, Poll}; diff --git a/tokio/tests/join_handle_panic.rs b/tokio/tests/join_handle_panic.rs index bc34fd0ea59..c25a5f88568 100644 --- a/tokio/tests/join_handle_panic.rs +++ b/tokio/tests/join_handle_panic.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi does not support panic recovery +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery struct PanicsOnDrop; diff --git a/tokio/tests/macros_join.rs b/tokio/tests/macros_join.rs index 7866ac086fa..37dd05f0e13 100644 --- a/tokio/tests/macros_join.rs +++ b/tokio/tests/macros_join.rs @@ -2,13 +2,13 @@ #![allow(clippy::disallowed_names)] use std::sync::Arc; -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] #[cfg(target_pointer_width = "64")] use wasm_bindgen_test::wasm_bindgen_test as test; -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; -#[cfg(not(tokio_wasm_not_wasi))] +#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] use tokio::test as maybe_tokio_test; use tokio::sync::{oneshot, Semaphore}; diff --git a/tokio/tests/macros_pin.rs b/tokio/tests/macros_pin.rs index e99a3ee2017..2de68ad031f 100644 --- a/tokio/tests/macros_pin.rs +++ b/tokio/tests/macros_pin.rs @@ -1,9 +1,9 @@ #![cfg(feature = "macros")] -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; -#[cfg(not(tokio_wasm_not_wasi))] +#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] use tokio::test as maybe_tokio_test; async fn one() {} diff --git a/tokio/tests/macros_rename_test.rs b/tokio/tests/macros_rename_test.rs index 6c2ce2f57aa..0c5eba20f8d 100644 --- a/tokio/tests/macros_rename_test.rs +++ b/tokio/tests/macros_rename_test.rs @@ -1,4 +1,4 @@ -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support threading +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threading #[allow(unused_imports)] use std as tokio; diff --git a/tokio/tests/macros_select.rs b/tokio/tests/macros_select.rs index 0514c864d5e..68a607b27f4 100644 --- a/tokio/tests/macros_select.rs +++ b/tokio/tests/macros_select.rs @@ -1,10 +1,10 @@ #![cfg(feature = "macros")] #![allow(clippy::disallowed_names)] -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; -#[cfg(not(tokio_wasm_not_wasi))] +#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] use tokio::test as maybe_tokio_test; use tokio::sync::oneshot; @@ -633,7 +633,7 @@ mod unstable { } #[test] - #[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] fn deterministic_select_multi_thread() { let seed = b"bytes used to generate seed"; let rt1 = tokio::runtime::Builder::new_multi_thread() diff --git a/tokio/tests/macros_test.rs b/tokio/tests/macros_test.rs index 85279b7edc0..b5095e36e4b 100644 --- a/tokio/tests/macros_test.rs +++ b/tokio/tests/macros_test.rs @@ -1,4 +1,4 @@ -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support threading +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threading use tokio::test; diff --git a/tokio/tests/macros_try_join.rs b/tokio/tests/macros_try_join.rs index 74b1c9f9481..c8ed00bcd13 100644 --- a/tokio/tests/macros_try_join.rs +++ b/tokio/tests/macros_try_join.rs @@ -6,10 +6,10 @@ use std::sync::Arc; use tokio::sync::{oneshot, Semaphore}; use tokio_test::{assert_pending, assert_ready, task}; -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; -#[cfg(not(tokio_wasm_not_wasi))] +#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] use tokio::test as maybe_tokio_test; #[maybe_tokio_test] diff --git a/tokio/tests/net_bind_resource.rs b/tokio/tests/net_bind_resource.rs index 76378b3ea1e..05fd1604b87 100644 --- a/tokio/tests/net_bind_resource.rs +++ b/tokio/tests/net_bind_resource.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support panic recovery or bind +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery or bind use tokio::net::TcpListener; diff --git a/tokio/tests/net_lookup_host.rs b/tokio/tests/net_lookup_host.rs index 2b346e65e37..667030c7e02 100644 --- a/tokio/tests/net_lookup_host.rs +++ b/tokio/tests/net_lookup_host.rs @@ -1,4 +1,4 @@ -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi does not support direct socket operations +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support direct socket operations use tokio::net; use tokio_test::assert_ok; diff --git a/tokio/tests/net_panic.rs b/tokio/tests/net_panic.rs index fc2209ad4b0..79807618973 100644 --- a/tokio/tests/net_panic.rs +++ b/tokio/tests/net_panic.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use std::error::Error; use tokio::net::{TcpListener, TcpStream}; diff --git a/tokio/tests/no_rt.rs b/tokio/tests/no_rt.rs index 747fab6af7d..89c7ce0aa57 100644 --- a/tokio/tests/no_rt.rs +++ b/tokio/tests/no_rt.rs @@ -1,4 +1,4 @@ -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi does not support panic recovery +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery use tokio::net::TcpStream; use tokio::sync::oneshot; diff --git a/tokio/tests/process_smoke.rs b/tokio/tests/process_smoke.rs index 81d2020a079..635b951a065 100644 --- a/tokio/tests/process_smoke.rs +++ b/tokio/tests/process_smoke.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi cannot run system commands +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi cannot run system commands use tokio::process::Command; use tokio_test::assert_ok; diff --git a/tokio/tests/rt_basic.rs b/tokio/tests/rt_basic.rs index 6caf0a44bf8..789c0475da4 100644 --- a/tokio/tests/rt_basic.rs +++ b/tokio/tests/rt_basic.rs @@ -178,7 +178,7 @@ fn drop_tasks_in_context() { } #[test] -#[cfg_attr(tokio_wasi, ignore = "Wasi does not support panic recovery")] +#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")] #[should_panic(expected = "boom")] fn wake_in_drop_after_panic() { let (tx, rx) = oneshot::channel::<()>(); @@ -239,7 +239,7 @@ fn spawn_two() { } } -#[cfg_attr(tokio_wasi, ignore = "WASI: std::thread::spawn not supported")] +#[cfg_attr(target_os = "wasi", ignore = "WASI: std::thread::spawn not supported")] #[test] fn spawn_remote() { let rt = rt(); @@ -276,7 +276,7 @@ fn spawn_remote() { } #[test] -#[cfg_attr(tokio_wasi, ignore = "Wasi does not support panic recovery")] +#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")] #[should_panic( expected = "A Tokio 1.x context was found, but timers are disabled. Call `enable_time` on the runtime builder to enable timers." )] @@ -315,7 +315,7 @@ mod unstable { } #[test] - #[cfg_attr(tokio_wasi, ignore = "Wasi does not support panic recovery")] + #[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")] fn spawns_do_nothing() { use std::sync::Arc; @@ -344,7 +344,7 @@ mod unstable { } #[test] - #[cfg_attr(tokio_wasi, ignore = "Wasi does not support panic recovery")] + #[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")] fn shutdown_all_concurrent_block_on() { const N: usize = 2; use std::sync::{mpsc, Arc}; diff --git a/tokio/tests/rt_common.rs b/tokio/tests/rt_common.rs index 9ab7fd3516e..58df53f0170 100644 --- a/tokio/tests/rt_common.rs +++ b/tokio/tests/rt_common.rs @@ -21,7 +21,7 @@ macro_rules! rt_test { } } - #[cfg(not(tokio_wasi))] // Wasi doesn't support threads + #[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads mod threaded_scheduler_4_threads { $($t)* @@ -37,7 +37,7 @@ macro_rules! rt_test { } } - #[cfg(not(tokio_wasi))] // Wasi doesn't support threads + #[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads mod threaded_scheduler_1_thread { $($t)* @@ -53,7 +53,7 @@ macro_rules! rt_test { } } - #[cfg(not(tokio_wasi))] // Wasi doesn't support threads + #[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[cfg(tokio_unstable)] mod alt_threaded_scheduler_4_threads { $($t)* @@ -70,7 +70,7 @@ macro_rules! rt_test { } } - #[cfg(not(tokio_wasi))] // Wasi doesn't support threads + #[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[cfg(tokio_unstable)] mod alt_threaded_scheduler_1_thread { $($t)* @@ -844,7 +844,7 @@ rt_test! { assert_err!(rx.try_recv()); } - #[cfg_attr(tokio_wasi, ignore = "Wasi does not support threads or panic recovery")] + #[cfg_attr(target_os = "wasi", ignore = "Wasi does not support threads or panic recovery")] #[test] fn panic_in_task() { let rt = rt(); @@ -873,7 +873,7 @@ rt_test! { #[test] #[should_panic] - #[cfg_attr(tokio_wasi, ignore = "Wasi does not support panic recovery")] + #[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")] fn panic_in_block_on() { let rt = rt(); rt.block_on(async { panic!() }); @@ -1103,7 +1103,7 @@ rt_test! { // See https://github.com/rust-lang/rust/issues/74875 #[test] #[cfg(not(windows))] - #[cfg_attr(tokio_wasi, ignore = "Wasi does not support threads")] + #[cfg_attr(target_os = "wasi", ignore = "Wasi does not support threads")] fn runtime_in_thread_local() { use std::cell::RefCell; use std::thread; @@ -1148,7 +1148,7 @@ rt_test! { tx.send(()).unwrap(); } - #[cfg(not(tokio_wasi))] // Wasi does not support bind + #[cfg(not(target_os = "wasi"))] // Wasi does not support bind #[test] fn local_set_block_on_socket() { let rt = rt(); @@ -1170,7 +1170,7 @@ rt_test! { }); } - #[cfg(not(tokio_wasi))] // Wasi does not support bind + #[cfg(not(target_os = "wasi"))] // Wasi does not support bind #[test] fn local_set_client_server_block_on() { let rt = rt(); @@ -1184,7 +1184,7 @@ rt_test! { assert_err!(rx.try_recv()); } - #[cfg(not(tokio_wasi))] // Wasi does not support bind + #[cfg(not(target_os = "wasi"))] // Wasi does not support bind async fn client_server_local(tx: mpsc::Sender<()>) { let server = assert_ok!(TcpListener::bind("127.0.0.1:0").await); diff --git a/tokio/tests/rt_handle.rs b/tokio/tests/rt_handle.rs index 14d6524f62e..5d4b53f6319 100644 --- a/tokio/tests/rt_handle.rs +++ b/tokio/tests/rt_handle.rs @@ -42,7 +42,7 @@ fn interleave_enter_same_rt() { } #[test] -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] fn interleave_then_enter() { let _ = std::panic::catch_unwind(|| { let rt1 = rt(); diff --git a/tokio/tests/rt_handle_block_on.rs b/tokio/tests/rt_handle_block_on.rs index 5ec783e5588..54b9002c075 100644 --- a/tokio/tests/rt_handle_block_on.rs +++ b/tokio/tests/rt_handle_block_on.rs @@ -10,10 +10,10 @@ use std::time::Duration; use tokio::runtime::{Handle, Runtime}; use tokio::sync::mpsc; -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] use tokio::{net, time}; -#[cfg(not(tokio_wasi))] // Wasi doesn't support threads +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads macro_rules! multi_threaded_rt_test { ($($t:tt)*) => { mod threaded_scheduler_4_threads_only { @@ -46,7 +46,7 @@ macro_rules! multi_threaded_rt_test { } } -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] macro_rules! rt_test { ($($t:tt)*) => { mod current_thread_scheduler { @@ -126,7 +126,7 @@ fn unbounded_mpsc_channel() { }) } -#[cfg(not(tokio_wasi))] // Wasi doesn't support file operations or bind +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support file operations or bind rt_test! { use tokio::fs; // ==== spawn blocking futures ====== @@ -419,7 +419,7 @@ rt_test! { } } -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] multi_threaded_rt_test! { #[cfg(unix)] #[test] @@ -482,7 +482,7 @@ multi_threaded_rt_test! { // ==== utils ====== /// Create a new multi threaded runtime -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] fn new_multi_thread(n: usize) -> Runtime { tokio::runtime::Builder::new_multi_thread() .worker_threads(n) @@ -513,7 +513,7 @@ where f(); } - #[cfg(not(tokio_wasi))] + #[cfg(not(target_os = "wasi"))] { let rt = new_multi_thread(1); let _enter = rt.enter(); @@ -523,7 +523,7 @@ where f(); } - #[cfg(not(tokio_wasi))] + #[cfg(not(target_os = "wasi"))] { let rt = new_multi_thread(4); let _enter = rt.enter(); diff --git a/tokio/tests/rt_metrics.rs b/tokio/tests/rt_metrics.rs index 0fe839a2f97..7b7a957c419 100644 --- a/tokio/tests/rt_metrics.rs +++ b/tokio/tests/rt_metrics.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", tokio_unstable, not(tokio_wasi)))] +#![cfg(all(feature = "full", tokio_unstable, not(target_os = "wasi")))] use std::future::Future; use std::sync::{Arc, Mutex}; diff --git a/tokio/tests/rt_panic.rs b/tokio/tests/rt_panic.rs index f9a684fdada..57f327481b6 100644 --- a/tokio/tests/rt_panic.rs +++ b/tokio/tests/rt_panic.rs @@ -1,6 +1,6 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "full")] -#![cfg(not(tokio_wasi))] // Wasi doesn't support panic recovery +#![cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery use futures::future; use std::error::Error; diff --git a/tokio/tests/rt_threaded.rs b/tokio/tests/rt_threaded.rs index 3c77c7e5c50..83df6ed480f 100644 --- a/tokio/tests/rt_threaded.rs +++ b/tokio/tests/rt_threaded.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::net::{TcpListener, TcpStream}; diff --git a/tokio/tests/rt_threaded_alt.rs b/tokio/tests/rt_threaded_alt.rs index b8af6a7b8a9..b0eb4279af0 100644 --- a/tokio/tests/rt_threaded_alt.rs +++ b/tokio/tests/rt_threaded_alt.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] #![cfg(tokio_unstable)] use tokio::io::{AsyncReadExt, AsyncWriteExt}; diff --git a/tokio/tests/signal_no_rt.rs b/tokio/tests/signal_no_rt.rs index ffcc6651c4d..db284e16513 100644 --- a/tokio/tests/signal_no_rt.rs +++ b/tokio/tests/signal_no_rt.rs @@ -4,7 +4,7 @@ use tokio::signal::unix::{signal, SignalKind}; -#[cfg_attr(tokio_wasi, ignore = "Wasi does not support panic recovery")] +#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")] #[test] #[should_panic] fn no_runtime_panics_creating_signals() { diff --git a/tokio/tests/sync_barrier.rs b/tokio/tests/sync_barrier.rs index 2001c3598cb..ac5977f24d8 100644 --- a/tokio/tests/sync_barrier.rs +++ b/tokio/tests/sync_barrier.rs @@ -2,7 +2,7 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; use tokio::sync::Barrier; diff --git a/tokio/tests/sync_broadcast.rs b/tokio/tests/sync_broadcast.rs index 59190a9603d..16b9a0abb73 100644 --- a/tokio/tests/sync_broadcast.rs +++ b/tokio/tests/sync_broadcast.rs @@ -2,7 +2,7 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; use tokio::sync::broadcast; @@ -563,7 +563,7 @@ fn sender_len() { } #[test] -#[cfg(not(tokio_wasm_not_wasi))] +#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] fn sender_len_random() { use rand::Rng; diff --git a/tokio/tests/sync_errors.rs b/tokio/tests/sync_errors.rs index bf0a6cf7374..4e43c8f311e 100644 --- a/tokio/tests/sync_errors.rs +++ b/tokio/tests/sync_errors.rs @@ -1,7 +1,7 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; fn is_error() {} diff --git a/tokio/tests/sync_mpsc.rs b/tokio/tests/sync_mpsc.rs index 84211a7c272..d2b7078b4ea 100644 --- a/tokio/tests/sync_mpsc.rs +++ b/tokio/tests/sync_mpsc.rs @@ -2,17 +2,18 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; +#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] +use tokio::test as maybe_tokio_test; + use std::fmt; use std::sync::Arc; use tokio::sync::mpsc; use tokio::sync::mpsc::error::{TryRecvError, TrySendError}; -#[cfg(not(tokio_wasm_not_wasi))] -use tokio::test as maybe_tokio_test; use tokio_test::*; #[cfg(not(target_family = "wasm"))] @@ -87,7 +88,7 @@ async fn reserve_disarm() { } #[tokio::test] -#[cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support threads +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads async fn send_recv_stream_with_buffer() { use tokio_stream::StreamExt; @@ -191,7 +192,7 @@ async fn async_send_recv_unbounded() { } #[tokio::test] -#[cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support threads +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads async fn send_recv_stream_unbounded() { use tokio_stream::StreamExt; @@ -452,7 +453,7 @@ fn unconsumed_messages_are_dropped() { } #[test] -#[cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support threads +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads fn blocking_recv() { let (tx, mut rx) = mpsc::channel::(1); @@ -477,7 +478,7 @@ async fn blocking_recv_async() { } #[test] -#[cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support threads +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads fn blocking_send() { let (tx, mut rx) = mpsc::channel::(1); diff --git a/tokio/tests/sync_mpsc_weak.rs b/tokio/tests/sync_mpsc_weak.rs index 0fdfc00708b..fad4c72f799 100644 --- a/tokio/tests/sync_mpsc_weak.rs +++ b/tokio/tests/sync_mpsc_weak.rs @@ -2,7 +2,7 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; use std::sync::atomic::AtomicUsize; diff --git a/tokio/tests/sync_mutex.rs b/tokio/tests/sync_mutex.rs index 1e35a558c1d..f423c82e7b1 100644 --- a/tokio/tests/sync_mutex.rs +++ b/tokio/tests/sync_mutex.rs @@ -1,12 +1,12 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; -#[cfg(not(tokio_wasm_not_wasi))] +#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] use tokio::test as maybe_tokio_test; use tokio::sync::Mutex; diff --git a/tokio/tests/sync_mutex_owned.rs b/tokio/tests/sync_mutex_owned.rs index ba472fee78e..badcef3d08e 100644 --- a/tokio/tests/sync_mutex_owned.rs +++ b/tokio/tests/sync_mutex_owned.rs @@ -1,12 +1,12 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; -#[cfg(not(tokio_wasm_not_wasi))] +#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] use tokio::test as maybe_tokio_test; use tokio::sync::Mutex; diff --git a/tokio/tests/sync_notify.rs b/tokio/tests/sync_notify.rs index aa58039fac1..e31b9d49cff 100644 --- a/tokio/tests/sync_notify.rs +++ b/tokio/tests/sync_notify.rs @@ -1,7 +1,7 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; use tokio::sync::Notify; diff --git a/tokio/tests/sync_oneshot.rs b/tokio/tests/sync_oneshot.rs index f11b1071cd0..163d50de9d2 100644 --- a/tokio/tests/sync_oneshot.rs +++ b/tokio/tests/sync_oneshot.rs @@ -1,12 +1,12 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; -#[cfg(not(tokio_wasm_not_wasi))] +#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] use tokio::test as maybe_tokio_test; use tokio::sync::oneshot; diff --git a/tokio/tests/sync_panic.rs b/tokio/tests/sync_panic.rs index 6c23664998f..bcdaaae56d0 100644 --- a/tokio/tests/sync_panic.rs +++ b/tokio/tests/sync_panic.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use std::{error::Error, sync::Arc}; use tokio::{ diff --git a/tokio/tests/sync_rwlock.rs b/tokio/tests/sync_rwlock.rs index 667f621721f..f711804ce26 100644 --- a/tokio/tests/sync_rwlock.rs +++ b/tokio/tests/sync_rwlock.rs @@ -1,12 +1,12 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; -#[cfg(not(tokio_wasm_not_wasi))] +#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] use tokio::test as maybe_tokio_test; use std::task::Poll; @@ -172,7 +172,7 @@ async fn write_order() { } // A single RwLock is contested by tasks in multiple threads -#[cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support threads +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread", worker_threads = 8)] async fn multithreaded() { use futures::stream::{self, StreamExt}; diff --git a/tokio/tests/sync_semaphore.rs b/tokio/tests/sync_semaphore.rs index 52c65fdb1f7..40a5a0802a6 100644 --- a/tokio/tests/sync_semaphore.rs +++ b/tokio/tests/sync_semaphore.rs @@ -1,6 +1,6 @@ #![cfg(feature = "sync")] -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; use std::sync::Arc; diff --git a/tokio/tests/sync_semaphore_owned.rs b/tokio/tests/sync_semaphore_owned.rs index 6f66d6adc98..d4b12d40e45 100644 --- a/tokio/tests/sync_semaphore_owned.rs +++ b/tokio/tests/sync_semaphore_owned.rs @@ -1,6 +1,6 @@ #![cfg(feature = "sync")] -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; use std::sync::Arc; diff --git a/tokio/tests/sync_watch.rs b/tokio/tests/sync_watch.rs index 9d169641d23..dab57aa5af6 100644 --- a/tokio/tests/sync_watch.rs +++ b/tokio/tests/sync_watch.rs @@ -2,7 +2,7 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(tokio_wasm_not_wasi)] +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; use tokio::sync::watch; diff --git a/tokio/tests/task_abort.rs b/tokio/tests/task_abort.rs index 492f8b551a3..4798246c374 100644 --- a/tokio/tests/task_abort.rs +++ b/tokio/tests/task_abort.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support panic recovery +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery use std::sync::Arc; use std::thread::sleep; diff --git a/tokio/tests/task_blocking.rs b/tokio/tests/task_blocking.rs index 2999758ff36..62e20f6c0fe 100644 --- a/tokio/tests/task_blocking.rs +++ b/tokio/tests/task_blocking.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support threads +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads use tokio::{runtime, task, time}; use tokio_test::assert_ok; diff --git a/tokio/tests/task_id.rs b/tokio/tests/task_id.rs index d7b7c0cd812..e10f24be99c 100644 --- a/tokio/tests/task_id.rs +++ b/tokio/tests/task_id.rs @@ -2,21 +2,21 @@ #![allow(clippy::declare_interior_mutable_const)] #![cfg(all(feature = "full", tokio_unstable))] -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] use std::error::Error; use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] use tokio::runtime::{Builder, Runtime}; use tokio::sync::oneshot; use tokio::task::{self, Id, LocalSet}; -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] mod support { pub mod panic; } -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] use support::panic::test_panic; #[tokio::test(flavor = "current_thread")] @@ -26,7 +26,7 @@ async fn task_id_spawn() { .unwrap(); } -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] #[tokio::test(flavor = "current_thread")] async fn task_id_spawn_blocking() { task::spawn_blocking(|| println!("task id: {}", task::id())) @@ -43,7 +43,7 @@ async fn task_id_collision_current_thread() { assert_ne!(id1.unwrap(), id2.unwrap()); } -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] #[tokio::test(flavor = "multi_thread")] async fn task_id_collision_multi_thread() { let handle1 = tokio::spawn(async { task::id() }); @@ -64,7 +64,7 @@ async fn task_ids_match_current_thread() { handle.await.unwrap(); } -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] #[tokio::test(flavor = "multi_thread")] async fn task_ids_match_multi_thread() { let (tx, rx) = oneshot::channel(); @@ -76,7 +76,7 @@ async fn task_ids_match_multi_thread() { handle.await.unwrap(); } -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] #[tokio::test(flavor = "multi_thread")] async fn task_id_future_destructor_completion() { struct MyFuture { @@ -104,7 +104,7 @@ async fn task_id_future_destructor_completion() { assert_eq!(rx.await.unwrap(), id); } -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] #[tokio::test(flavor = "multi_thread")] async fn task_id_future_destructor_abort() { struct MyFuture { @@ -210,7 +210,7 @@ fn task_try_id_outside_task() { assert_eq!(None, task::try_id()); } -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] #[test] fn task_try_id_inside_block_on() { let rt = Runtime::new().unwrap(); @@ -253,7 +253,7 @@ async fn task_id_nested_spawn_local() { .await; } -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] #[tokio::test(flavor = "multi_thread")] async fn task_id_block_in_place_block_on_spawn() { task::spawn(async { @@ -273,7 +273,7 @@ async fn task_id_block_in_place_block_on_spawn() { .unwrap(); } -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] #[test] fn task_id_outside_task_panic_caller() -> Result<(), Box> { let panic_location_file = test_panic(|| { @@ -286,7 +286,7 @@ fn task_id_outside_task_panic_caller() -> Result<(), Box> { Ok(()) } -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] #[test] fn task_id_inside_block_on_panic_caller() -> Result<(), Box> { let panic_location_file = test_panic(|| { diff --git a/tokio/tests/task_local.rs b/tokio/tests/task_local.rs index 949a40c2a4d..a9ffaa15acc 100644 --- a/tokio/tests/task_local.rs +++ b/tokio/tests/task_local.rs @@ -1,4 +1,4 @@ -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support threads +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads #![allow(clippy::declare_interior_mutable_const)] use std::future::Future; use std::pin::Pin; diff --git a/tokio/tests/task_local_set.rs b/tokio/tests/task_local_set.rs index 2da87f5aed2..baca58b776c 100644 --- a/tokio/tests/task_local_set.rs +++ b/tokio/tests/task_local_set.rs @@ -11,13 +11,13 @@ use tokio::sync::{mpsc, oneshot}; use tokio::task::{self, LocalSet}; use tokio::time; -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] use std::cell::Cell; use std::sync::atomic::AtomicBool; -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] use std::sync::atomic::Ordering::SeqCst; use std::time::Duration; @@ -30,7 +30,7 @@ async fn local_current_thread_scheduler() { .await; } -#[cfg(not(tokio_wasi))] // Wasi doesn't support threads +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread")] async fn local_threadpool() { thread_local! { @@ -51,7 +51,7 @@ async fn local_threadpool() { .await; } -#[cfg(not(tokio_wasi))] // Wasi doesn't support threads +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread")] async fn localset_future_threadpool() { thread_local! { @@ -67,7 +67,7 @@ async fn localset_future_threadpool() { local.await; } -#[cfg(not(tokio_wasi))] // Wasi doesn't support threads +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread")] async fn localset_future_timers() { static RAN1: AtomicBool = AtomicBool::new(false); @@ -112,7 +112,7 @@ async fn localset_future_drives_all_local_futs() { assert!(RAN3.load(Ordering::SeqCst)); } -#[cfg(not(tokio_wasi))] // Wasi doesn't support threads +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread")] async fn local_threadpool_timer() { // This test ensures that runtime services like the timer are properly @@ -151,7 +151,7 @@ fn enter_guard_spawn() { }); } -#[cfg(not(tokio_wasi))] // Wasi doesn't support panic recovery +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[test] // This will panic, since the thread that calls `block_on` cannot use // in-place blocking inside of `block_on`. @@ -178,7 +178,7 @@ fn local_threadpool_blocking_in_place() { }); } -#[cfg(not(tokio_wasi))] // Wasi doesn't support threads +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread")] async fn local_threadpool_blocking_run() { thread_local! { @@ -207,7 +207,7 @@ async fn local_threadpool_blocking_run() { .await; } -#[cfg(not(tokio_wasi))] // Wasi doesn't support threads +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread")] async fn all_spawns_are_local() { use futures::future; @@ -234,7 +234,7 @@ async fn all_spawns_are_local() { .await; } -#[cfg(not(tokio_wasi))] // Wasi doesn't support threads +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread")] async fn nested_spawn_is_local() { thread_local! { @@ -270,7 +270,7 @@ async fn nested_spawn_is_local() { .await; } -#[cfg(not(tokio_wasi))] // Wasi doesn't support threads +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn join_local_future_elsewhere() { thread_local! { @@ -307,7 +307,7 @@ fn join_local_future_elsewhere() { } // Tests for -#[cfg(not(tokio_wasi))] // Wasi doesn't support threads +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread")] async fn localset_in_thread_local() { thread_local! { @@ -398,7 +398,10 @@ fn with_timeout(timeout: Duration, f: impl FnOnce() + Send + 'static) { thread.join().expect("test thread should not panic!") } -#[cfg_attr(tokio_wasi, ignore = "`unwrap()` in `with_timeout()` panics on Wasi")] +#[cfg_attr( + target_os = "wasi", + ignore = "`unwrap()` in `with_timeout()` panics on Wasi" +)] #[test] fn drop_cancels_remote_tasks() { // This test reproduces issue #1885. @@ -422,7 +425,7 @@ fn drop_cancels_remote_tasks() { } #[cfg_attr( - tokio_wasi, + target_os = "wasi", ignore = "FIXME: `task::spawn_local().await.unwrap()` panics on Wasi" )] #[test] @@ -446,7 +449,7 @@ fn local_tasks_wake_join_all() { }); } -#[cfg(not(tokio_wasi))] // Wasi doesn't support panic recovery +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[test] fn local_tasks_are_polled_after_tick() { // This test depends on timing, so we run it up to five times. @@ -463,7 +466,7 @@ fn local_tasks_are_polled_after_tick() { local_tasks_are_polled_after_tick_inner(); } -#[cfg(not(tokio_wasi))] // Wasi doesn't support panic recovery +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[tokio::main(flavor = "current_thread")] async fn local_tasks_are_polled_after_tick_inner() { // Reproduces issues #1899 and #1900 diff --git a/tokio/tests/task_panic.rs b/tokio/tests/task_panic.rs index e4cedce2798..2ca21b1ded2 100644 --- a/tokio/tests/task_panic.rs +++ b/tokio/tests/task_panic.rs @@ -1,6 +1,6 @@ #![warn(rust_2018_idioms)] #![allow(clippy::declare_interior_mutable_const)] -#![cfg(all(feature = "full", not(tokio_wasi)))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use futures::future; use std::error::Error; diff --git a/tokio/tests/tcp_accept.rs b/tokio/tests/tcp_accept.rs index ba4a498d1a5..d547c48daa3 100644 --- a/tokio/tests/tcp_accept.rs +++ b/tokio/tests/tcp_accept.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support bind +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use tokio::net::{TcpListener, TcpStream}; use tokio::sync::{mpsc, oneshot}; diff --git a/tokio/tests/tcp_connect.rs b/tokio/tests/tcp_connect.rs index f2384420ed3..03f7b34ff43 100644 --- a/tokio/tests/tcp_connect.rs +++ b/tokio/tests/tcp_connect.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support bind +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use tokio::net::{TcpListener, TcpStream}; use tokio::sync::oneshot; diff --git a/tokio/tests/tcp_echo.rs b/tokio/tests/tcp_echo.rs index f47d4ac185a..dfd4dd7b9f4 100644 --- a/tokio/tests/tcp_echo.rs +++ b/tokio/tests/tcp_echo.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support bind +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use tokio::io::{self, AsyncReadExt, AsyncWriteExt}; use tokio::net::{TcpListener, TcpStream}; diff --git a/tokio/tests/tcp_into_split.rs b/tokio/tests/tcp_into_split.rs index 010984af8cc..2a030691f64 100644 --- a/tokio/tests/tcp_into_split.rs +++ b/tokio/tests/tcp_into_split.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support bind +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use std::io::{Error, ErrorKind, Result}; use std::io::{Read, Write}; diff --git a/tokio/tests/tcp_into_std.rs b/tokio/tests/tcp_into_std.rs index 320d9946e81..58996f75c90 100644 --- a/tokio/tests/tcp_into_std.rs +++ b/tokio/tests/tcp_into_std.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support bind +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use std::io::Read; use std::io::Result; diff --git a/tokio/tests/tcp_peek.rs b/tokio/tests/tcp_peek.rs index a5fd6ba4fe5..b2d3eda097e 100644 --- a/tokio/tests/tcp_peek.rs +++ b/tokio/tests/tcp_peek.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support bind +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use tokio::io::AsyncReadExt; use tokio::net::TcpStream; diff --git a/tokio/tests/tcp_shutdown.rs b/tokio/tests/tcp_shutdown.rs index 1d477f37c22..86c1485a4a4 100644 --- a/tokio/tests/tcp_shutdown.rs +++ b/tokio/tests/tcp_shutdown.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support bind +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use tokio::io::{self, AsyncReadExt, AsyncWriteExt}; use tokio::net::{TcpListener, TcpStream}; diff --git a/tokio/tests/tcp_socket.rs b/tokio/tests/tcp_socket.rs index 66309d30411..b431196f1c6 100644 --- a/tokio/tests/tcp_socket.rs +++ b/tokio/tests/tcp_socket.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support bind +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use std::time::Duration; use tokio::net::TcpSocket; diff --git a/tokio/tests/tcp_split.rs b/tokio/tests/tcp_split.rs index 335b21f2940..32aaa1f771b 100644 --- a/tokio/tests/tcp_split.rs +++ b/tokio/tests/tcp_split.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support bind +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use std::io::Result; use std::io::{Read, Write}; diff --git a/tokio/tests/tcp_stream.rs b/tokio/tests/tcp_stream.rs index 31fe3baa296..725a60169ea 100644 --- a/tokio/tests/tcp_stream.rs +++ b/tokio/tests/tcp_stream.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support bind +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use tokio::io::{AsyncReadExt, AsyncWriteExt, Interest}; use tokio::net::{TcpListener, TcpStream}; diff --git a/tokio/tests/time_panic.rs b/tokio/tests/time_panic.rs index aaff11bb4f0..02b928bb83e 100644 --- a/tokio/tests/time_panic.rs +++ b/tokio/tests/time_panic.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support panic recovery +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery use futures::future; use std::error::Error; diff --git a/tokio/tests/time_pause.rs b/tokio/tests/time_pause.rs index c772e387384..6251b4b829f 100644 --- a/tokio/tests/time_pause.rs +++ b/tokio/tests/time_pause.rs @@ -6,7 +6,7 @@ use rand::{rngs::StdRng, Rng}; use tokio::time::{self, Duration, Instant, Sleep}; use tokio_test::{assert_elapsed, assert_pending, assert_ready, assert_ready_eq, task}; -#[cfg(not(tokio_wasi))] +#[cfg(not(target_os = "wasi"))] use tokio_test::assert_err; use std::{ @@ -29,14 +29,14 @@ async fn pause_time_in_task() { t.await.unwrap(); } -#[cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support threads +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread", worker_threads = 1)] #[should_panic] async fn pause_time_in_main_threads() { tokio::time::pause(); } -#[cfg(all(feature = "full", not(tokio_wasi)))] // Wasi doesn't support threads +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn pause_time_in_spawn_threads() { let t = tokio::spawn(async { diff --git a/tokio/tests/time_rt.rs b/tokio/tests/time_rt.rs index 20f9e181b4b..13f888c1791 100644 --- a/tokio/tests/time_rt.rs +++ b/tokio/tests/time_rt.rs @@ -5,7 +5,7 @@ use tokio::time::*; use std::sync::mpsc; -#[cfg(all(feature = "rt-multi-thread", not(tokio_wasi)))] // Wasi doesn't support threads +#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] // Wasi doesn't support threads #[test] fn timer_with_threaded_runtime() { use tokio::runtime::Runtime; diff --git a/tokio/tests/time_sleep.rs b/tokio/tests/time_sleep.rs index 94022e3c00c..4afcc12c10d 100644 --- a/tokio/tests/time_sleep.rs +++ b/tokio/tests/time_sleep.rs @@ -168,7 +168,7 @@ async fn reset_sleep_to_past() { assert_ready!(sleep.poll()); } -#[cfg(not(tokio_wasi))] // Wasi doesn't support panic recovery +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[test] #[should_panic] fn creating_sleep_outside_of_context() { diff --git a/tokio/tests/time_timeout.rs b/tokio/tests/time_timeout.rs index be6b8fb4462..ec871cf62fe 100644 --- a/tokio/tests/time_timeout.rs +++ b/tokio/tests/time_timeout.rs @@ -17,7 +17,7 @@ async fn simultaneous_deadline_future_completion() { assert_ready_ok!(fut.poll()); } -#[cfg_attr(tokio_wasi, ignore = "FIXME: `fut.poll()` panics on Wasi")] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: `fut.poll()` panics on Wasi")] #[tokio::test] async fn completed_future_past_deadline() { // Wrap it with a deadline diff --git a/tokio/tests/udp.rs b/tokio/tests/udp.rs index 565323b3742..eea281c2316 100644 --- a/tokio/tests/udp.rs +++ b/tokio/tests/udp.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi does not support bind or UDP +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support bind or UDP use futures::future::poll_fn; use std::io; diff --git a/tokio/tests/unwindsafe.rs b/tokio/tests/unwindsafe.rs index 3e63820864d..8ab6654295b 100644 --- a/tokio/tests/unwindsafe.rs +++ b/tokio/tests/unwindsafe.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(tokio_wasi)))] // Wasi does not support panic recovery +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery use std::panic::{RefUnwindSafe, UnwindSafe}; From 4be910974930de24e7b7068b35ec194dac051bf8 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sat, 22 Jul 2023 23:40:36 +1000 Subject: [PATCH 09/12] Fix CI test for `wasm32-unknown-unknown` Signed-off-by: Jiahao XU --- tokio/src/runtime/coop.rs | 5 +++- tokio/src/sync/tests/atomic_waker.rs | 9 ++++--- tokio/src/sync/tests/notify.rs | 11 +++++--- tokio/src/sync/tests/semaphore_batch.rs | 35 ++++++++++++++----------- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/tokio/src/runtime/coop.rs b/tokio/src/runtime/coop.rs index 32c13b80e8e..d94b940d475 100644 --- a/tokio/src/runtime/coop.rs +++ b/tokio/src/runtime/coop.rs @@ -250,11 +250,14 @@ mod test { use wasm_bindgen_test::wasm_bindgen_test as test; } + #[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] + use std::prelude::v1::test; + fn get() -> Budget { context::budget(|cell| cell.get()).unwrap_or(Budget::unconstrained()) } - #[test] + #[self::test] fn budgeting() { use futures::future::poll_fn; use tokio_test::*; diff --git a/tokio/src/sync/tests/atomic_waker.rs b/tokio/src/sync/tests/atomic_waker.rs index d01aefc897d..acd81ac0656 100644 --- a/tokio/src/sync/tests/atomic_waker.rs +++ b/tokio/src/sync/tests/atomic_waker.rs @@ -16,7 +16,10 @@ cfg_is_wasm_not_wasi! { use wasm_bindgen_test::wasm_bindgen_test as test; } -#[test] +#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] +use std::prelude::v1::test; + +#[self::test] fn basic_usage() { let mut waker = task::spawn(AtomicWaker::new()); @@ -26,7 +29,7 @@ fn basic_usage() { assert!(waker.is_woken()); } -#[test] +#[self::test] fn wake_without_register() { let mut waker = task::spawn(AtomicWaker::new()); waker.wake(); @@ -37,7 +40,7 @@ fn wake_without_register() { assert!(!waker.is_woken()); } -#[test] +#[self::test] #[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding fn atomic_waker_panic_safe() { use std::panic; diff --git a/tokio/src/sync/tests/notify.rs b/tokio/src/sync/tests/notify.rs index 4af495ad601..3b48bd8929d 100644 --- a/tokio/src/sync/tests/notify.rs +++ b/tokio/src/sync/tests/notify.rs @@ -7,7 +7,10 @@ cfg_is_wasm_not_wasi! { use wasm_bindgen_test::wasm_bindgen_test as test; } -#[test] +#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] +use std::prelude::v1::test; + +#[self::test] fn notify_clones_waker_before_lock() { const VTABLE: &RawWakerVTable = &RawWakerVTable::new(clone_w, wake, wake_by_ref, drop_w); @@ -47,7 +50,7 @@ fn notify_clones_waker_before_lock() { } #[cfg(panic = "unwind")] -#[test] +#[self::test] fn notify_waiters_handles_panicking_waker() { use futures::task::ArcWake; @@ -85,7 +88,7 @@ fn notify_waiters_handles_panicking_waker() { } } -#[test] +#[self::test] fn notify_simple() { let notify = Notify::new(); @@ -101,7 +104,7 @@ fn notify_simple() { assert!(fut2.poll().is_ready()); } -#[test] +#[self::test] #[cfg(not(target_family = "wasm"))] fn watch_test() { let rt = crate::runtime::Builder::new_current_thread() diff --git a/tokio/src/sync/tests/semaphore_batch.rs b/tokio/src/sync/tests/semaphore_batch.rs index 403b6caa381..6c8fd2f74c6 100644 --- a/tokio/src/sync/tests/semaphore_batch.rs +++ b/tokio/src/sync/tests/semaphore_batch.rs @@ -7,7 +7,10 @@ cfg_is_wasm_not_wasi! { use wasm_bindgen_test::wasm_bindgen_test as test; } -#[test] +#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] +use std::prelude::v1::test; + +#[self::test] fn poll_acquire_one_available() { let s = Semaphore::new(100); assert_eq!(s.available_permits(), 100); @@ -17,7 +20,7 @@ fn poll_acquire_one_available() { assert_eq!(s.available_permits(), 99); } -#[test] +#[self::test] fn poll_acquire_many_available() { let s = Semaphore::new(100); assert_eq!(s.available_permits(), 100); @@ -30,7 +33,7 @@ fn poll_acquire_many_available() { assert_eq!(s.available_permits(), 90); } -#[test] +#[self::test] fn try_acquire_one_available() { let s = Semaphore::new(100); assert_eq!(s.available_permits(), 100); @@ -42,7 +45,7 @@ fn try_acquire_one_available() { assert_eq!(s.available_permits(), 98); } -#[test] +#[self::test] fn try_acquire_many_available() { let s = Semaphore::new(100); assert_eq!(s.available_permits(), 100); @@ -54,7 +57,7 @@ fn try_acquire_many_available() { assert_eq!(s.available_permits(), 90); } -#[test] +#[self::test] fn poll_acquire_one_unavailable() { let s = Semaphore::new(1); @@ -78,7 +81,7 @@ fn poll_acquire_one_unavailable() { assert_eq!(s.available_permits(), 1); } -#[test] +#[self::test] fn poll_acquire_many_unavailable() { let s = Semaphore::new(5); @@ -115,7 +118,7 @@ fn poll_acquire_many_unavailable() { assert_ready_ok!(acquire_3.poll()); } -#[test] +#[self::test] fn try_acquire_one_unavailable() { let s = Semaphore::new(1); @@ -134,7 +137,7 @@ fn try_acquire_one_unavailable() { assert_eq!(s.available_permits(), 1); } -#[test] +#[self::test] fn try_acquire_many_unavailable() { let s = Semaphore::new(5); @@ -156,7 +159,7 @@ fn try_acquire_many_unavailable() { assert_eq!(s.available_permits(), 2); } -#[test] +#[self::test] fn poll_acquire_one_zero_permits() { let s = Semaphore::new(0); assert_eq!(s.available_permits(), 0); @@ -171,19 +174,19 @@ fn poll_acquire_one_zero_permits() { assert_ready_ok!(acquire.poll()); } -#[test] +#[self::test] fn max_permits_doesnt_panic() { Semaphore::new(MAX_PERMITS); } -#[test] +#[self::test] #[should_panic] #[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding fn validates_max_permits() { Semaphore::new(MAX_PERMITS + 1); } -#[test] +#[self::test] fn close_semaphore_prevents_acquire() { let s = Semaphore::new(5); s.close(); @@ -197,7 +200,7 @@ fn close_semaphore_prevents_acquire() { assert_eq!(5, s.available_permits()); } -#[test] +#[self::test] fn close_semaphore_notifies_permit1() { let s = Semaphore::new(0); let mut acquire = task::spawn(s.acquire(1)); @@ -210,7 +213,7 @@ fn close_semaphore_notifies_permit1() { assert_ready_err!(acquire.poll()); } -#[test] +#[self::test] fn close_semaphore_notifies_permit2() { let s = Semaphore::new(2); @@ -244,7 +247,7 @@ fn close_semaphore_notifies_permit2() { assert_eq!(2, s.available_permits()); } -#[test] +#[self::test] fn cancel_acquire_releases_permits() { let s = Semaphore::new(10); s.try_acquire(4).expect("uncontended try_acquire succeeds"); @@ -260,7 +263,7 @@ fn cancel_acquire_releases_permits() { assert_ok!(s.try_acquire(6)); } -#[test] +#[self::test] fn release_permits_at_drop() { use crate::sync::semaphore::*; use futures::task::ArcWake; From 128f4114c9796e16abd84be7ab2e1db7ed8b7a3b Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Tue, 25 Jul 2023 11:56:28 +1000 Subject: [PATCH 10/12] Simplify cfg for import of `wasm_bindgen_test::wasm_bindgen_test` Co-authored-by: Taiki Endo Signed-off-by: Jiahao XU --- tokio/src/runtime/coop.rs | 10 ++----- tokio/src/sync/tests/atomic_waker.rs | 14 ++++----- tokio/src/sync/tests/notify.rs | 16 ++++------ tokio/src/sync/tests/semaphore_batch.rs | 40 +++++++++++-------------- 4 files changed, 32 insertions(+), 48 deletions(-) diff --git a/tokio/src/runtime/coop.rs b/tokio/src/runtime/coop.rs index d94b940d475..15a4d98c08d 100644 --- a/tokio/src/runtime/coop.rs +++ b/tokio/src/runtime/coop.rs @@ -246,18 +246,14 @@ cfg_coop! { mod test { use super::*; - cfg_is_wasm_not_wasi! { - use wasm_bindgen_test::wasm_bindgen_test as test; - } - - #[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] - use std::prelude::v1::test; + #[cfg(all(target_family = "wasm", not(target_os = "wasi")))] + use wasm_bindgen_test::wasm_bindgen_test as test; fn get() -> Budget { context::budget(|cell| cell.get()).unwrap_or(Budget::unconstrained()) } - #[self::test] + #[test] fn budgeting() { use futures::future::poll_fn; use tokio_test::*; diff --git a/tokio/src/sync/tests/atomic_waker.rs b/tokio/src/sync/tests/atomic_waker.rs index acd81ac0656..989175a53a9 100644 --- a/tokio/src/sync/tests/atomic_waker.rs +++ b/tokio/src/sync/tests/atomic_waker.rs @@ -12,14 +12,10 @@ impl AssertSync for AtomicWaker {} impl AssertSend for Waker {} impl AssertSync for Waker {} -cfg_is_wasm_not_wasi! { - use wasm_bindgen_test::wasm_bindgen_test as test; -} - -#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] -use std::prelude::v1::test; +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] +use wasm_bindgen_test::wasm_bindgen_test as test; -#[self::test] +#[test] fn basic_usage() { let mut waker = task::spawn(AtomicWaker::new()); @@ -29,7 +25,7 @@ fn basic_usage() { assert!(waker.is_woken()); } -#[self::test] +#[test] fn wake_without_register() { let mut waker = task::spawn(AtomicWaker::new()); waker.wake(); @@ -40,7 +36,7 @@ fn wake_without_register() { assert!(!waker.is_woken()); } -#[self::test] +#[test] #[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding fn atomic_waker_panic_safe() { use std::panic; diff --git a/tokio/src/sync/tests/notify.rs b/tokio/src/sync/tests/notify.rs index 3b48bd8929d..323b5c65ae3 100644 --- a/tokio/src/sync/tests/notify.rs +++ b/tokio/src/sync/tests/notify.rs @@ -3,14 +3,10 @@ use std::future::Future; use std::sync::Arc; use std::task::{Context, RawWaker, RawWakerVTable, Waker}; -cfg_is_wasm_not_wasi! { - use wasm_bindgen_test::wasm_bindgen_test as test; -} - -#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] -use std::prelude::v1::test; +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] +use wasm_bindgen_test::wasm_bindgen_test as test; -#[self::test] +#[test] fn notify_clones_waker_before_lock() { const VTABLE: &RawWakerVTable = &RawWakerVTable::new(clone_w, wake, wake_by_ref, drop_w); @@ -50,7 +46,7 @@ fn notify_clones_waker_before_lock() { } #[cfg(panic = "unwind")] -#[self::test] +#[test] fn notify_waiters_handles_panicking_waker() { use futures::task::ArcWake; @@ -88,7 +84,7 @@ fn notify_waiters_handles_panicking_waker() { } } -#[self::test] +#[test] fn notify_simple() { let notify = Notify::new(); @@ -104,7 +100,7 @@ fn notify_simple() { assert!(fut2.poll().is_ready()); } -#[self::test] +#[test] #[cfg(not(target_family = "wasm"))] fn watch_test() { let rt = crate::runtime::Builder::new_current_thread() diff --git a/tokio/src/sync/tests/semaphore_batch.rs b/tokio/src/sync/tests/semaphore_batch.rs index 6c8fd2f74c6..391797b3f66 100644 --- a/tokio/src/sync/tests/semaphore_batch.rs +++ b/tokio/src/sync/tests/semaphore_batch.rs @@ -3,14 +3,10 @@ use tokio_test::*; const MAX_PERMITS: usize = crate::sync::Semaphore::MAX_PERMITS; -cfg_is_wasm_not_wasi! { - use wasm_bindgen_test::wasm_bindgen_test as test; -} - -#[cfg(not(all(target_family = "wasm", not(target_os = "wasi"))))] -use std::prelude::v1::test; +#[cfg(all(target_family = "wasm", not(target_os = "wasi")))] +use wasm_bindgen_test::wasm_bindgen_test as test; -#[self::test] +#[test] fn poll_acquire_one_available() { let s = Semaphore::new(100); assert_eq!(s.available_permits(), 100); @@ -20,7 +16,7 @@ fn poll_acquire_one_available() { assert_eq!(s.available_permits(), 99); } -#[self::test] +#[test] fn poll_acquire_many_available() { let s = Semaphore::new(100); assert_eq!(s.available_permits(), 100); @@ -33,7 +29,7 @@ fn poll_acquire_many_available() { assert_eq!(s.available_permits(), 90); } -#[self::test] +#[test] fn try_acquire_one_available() { let s = Semaphore::new(100); assert_eq!(s.available_permits(), 100); @@ -45,7 +41,7 @@ fn try_acquire_one_available() { assert_eq!(s.available_permits(), 98); } -#[self::test] +#[test] fn try_acquire_many_available() { let s = Semaphore::new(100); assert_eq!(s.available_permits(), 100); @@ -57,7 +53,7 @@ fn try_acquire_many_available() { assert_eq!(s.available_permits(), 90); } -#[self::test] +#[test] fn poll_acquire_one_unavailable() { let s = Semaphore::new(1); @@ -81,7 +77,7 @@ fn poll_acquire_one_unavailable() { assert_eq!(s.available_permits(), 1); } -#[self::test] +#[test] fn poll_acquire_many_unavailable() { let s = Semaphore::new(5); @@ -118,7 +114,7 @@ fn poll_acquire_many_unavailable() { assert_ready_ok!(acquire_3.poll()); } -#[self::test] +#[test] fn try_acquire_one_unavailable() { let s = Semaphore::new(1); @@ -137,7 +133,7 @@ fn try_acquire_one_unavailable() { assert_eq!(s.available_permits(), 1); } -#[self::test] +#[test] fn try_acquire_many_unavailable() { let s = Semaphore::new(5); @@ -159,7 +155,7 @@ fn try_acquire_many_unavailable() { assert_eq!(s.available_permits(), 2); } -#[self::test] +#[test] fn poll_acquire_one_zero_permits() { let s = Semaphore::new(0); assert_eq!(s.available_permits(), 0); @@ -174,19 +170,19 @@ fn poll_acquire_one_zero_permits() { assert_ready_ok!(acquire.poll()); } -#[self::test] +#[test] fn max_permits_doesnt_panic() { Semaphore::new(MAX_PERMITS); } -#[self::test] +#[test] #[should_panic] #[cfg(not(target_family = "wasm"))] // wasm currently doesn't support unwinding fn validates_max_permits() { Semaphore::new(MAX_PERMITS + 1); } -#[self::test] +#[test] fn close_semaphore_prevents_acquire() { let s = Semaphore::new(5); s.close(); @@ -200,7 +196,7 @@ fn close_semaphore_prevents_acquire() { assert_eq!(5, s.available_permits()); } -#[self::test] +#[test] fn close_semaphore_notifies_permit1() { let s = Semaphore::new(0); let mut acquire = task::spawn(s.acquire(1)); @@ -213,7 +209,7 @@ fn close_semaphore_notifies_permit1() { assert_ready_err!(acquire.poll()); } -#[self::test] +#[test] fn close_semaphore_notifies_permit2() { let s = Semaphore::new(2); @@ -247,7 +243,7 @@ fn close_semaphore_notifies_permit2() { assert_eq!(2, s.available_permits()); } -#[self::test] +#[test] fn cancel_acquire_releases_permits() { let s = Semaphore::new(10); s.try_acquire(4).expect("uncontended try_acquire succeeds"); @@ -263,7 +259,7 @@ fn cancel_acquire_releases_permits() { assert_ok!(s.try_acquire(6)); } -#[self::test] +#[test] fn release_permits_at_drop() { use crate::sync::semaphore::*; use futures::task::ArcWake; From 63150942ddfdd4baa58a778c0a4d698ef8a38539 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Tue, 25 Jul 2023 22:47:27 +1000 Subject: [PATCH 11/12] Apply suggestions from code review Co-authored-by: Taiki Endo --- README.md | 2 +- tokio/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7badb87bf16..07d39aadf79 100644 --- a/README.md +++ b/README.md @@ -187,7 +187,7 @@ When updating this, also update: Tokio will keep a rolling MSRV (minimum supported rust version) policy of **at least** 6 months. When increasing the MSRV, the new Rust version must have been -released at least six months ago. The current MSRV is 1.63.0. +released at least six months ago. The current MSRV is 1.63. Note that the MSRV is not increased automatically, and only as part of a minor release. The MSRV history for past minor releases can be found below: diff --git a/tokio/README.md b/tokio/README.md index 7badb87bf16..07d39aadf79 100644 --- a/tokio/README.md +++ b/tokio/README.md @@ -187,7 +187,7 @@ When updating this, also update: Tokio will keep a rolling MSRV (minimum supported rust version) policy of **at least** 6 months. When increasing the MSRV, the new Rust version must have been -released at least six months ago. The current MSRV is 1.63.0. +released at least six months ago. The current MSRV is 1.63. Note that the MSRV is not increased automatically, and only as part of a minor release. The MSRV history for past minor releases can be found below: From 09fb572b166b364b85ef5b3cd2ac3ec1c689bce1 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Tue, 25 Jul 2023 22:57:32 +1000 Subject: [PATCH 12/12] Simplify `Cargo.toml` dependencies declaration By replacing `any(target_arch = "wasm32", target_arch = "wasm64")` with `target_family = "wasm"`. Signed-off-by: Jiahao XU --- tokio/Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index c6ea0d60a22..80a1a090041 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -104,7 +104,7 @@ mio = { version = "0.8.6", optional = true, default-features = false } num_cpus = { version = "1.8.0", optional = true } parking_lot = { version = "0.12.0", optional = true } -[target.'cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))'.dependencies] +[target.'cfg(not(target_family = "wasm"))'.dependencies] socket2 = { version = "0.5.3", optional = true, features = [ "all" ] } # Currently unstable. The API exposed by these features may be broken at any time. @@ -143,14 +143,14 @@ futures = { version = "0.3.0", features = ["async-await"] } mockall = "0.11.1" async-stream = "0.3" -[target.'cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))'.dev-dependencies] +[target.'cfg(not(target_family = "wasm"))'.dev-dependencies] socket2 = "0.5.3" tempfile = "3.1.0" -[target.'cfg(not(all(any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown")))'.dev-dependencies] +[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dev-dependencies] rand = "0.8.0" -[target.'cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), not(target_os = "wasi")))'.dev-dependencies] +[target.'cfg(all(target_family = "wasm", not(target_os = "wasi")))'.dev-dependencies] wasm-bindgen-test = "0.3.0" [target.'cfg(target_os = "freebsd")'.dev-dependencies]