From 513bcee724829ffbfdea3709436bd7f368917c55 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Mon, 24 Aug 2020 17:54:41 +0200 Subject: [PATCH 01/13] first fixes --- Cargo.toml | 2 +- src/task/join_handle.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 0c18ff457..79cb7e15e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,7 +86,7 @@ blocking = { version = "1.0.0", optional = true } futures-lite = { version = "1.0.0", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] -futures-timer = { version = "3.0.2", optional = true, features = ["wasm-bindgen"] } +futures-timer = { version = "3.0.2", features = ["wasm-bindgen"] } wasm-bindgen-futures = { version = "0.4.10", optional = true } futures-channel = { version = "0.3.4", optional = true } diff --git a/src/task/join_handle.rs b/src/task/join_handle.rs index 9189ea576..25ca79dad 100644 --- a/src/task/join_handle.rs +++ b/src/task/join_handle.rs @@ -78,7 +78,17 @@ impl Drop for JoinHandle { impl Future for JoinHandle { type Output = T; + #[cfg(not(target_os = "unknown"))] fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { Pin::new(&mut self.handle.as_mut().unwrap()).poll(cx) } + + #[cfg(target_arch = "wasm32")] + fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + match Pin::new(&mut self.handle.as_mut().unwrap()).poll(cx) { + Poll::Ready(Ok(t)) => Poll::Ready(t), + Poll::Ready(Err(_)) => unreachable!("channel must not be canceled"), + Poll::Pending => Poll::Pending, + } + } } From dcc93df8d94ff3ffbdd42fbc50ad0c919a276987 Mon Sep 17 00:00:00 2001 From: Jacob Rothstein Date: Thu, 13 Aug 2020 21:33:37 -0700 Subject: [PATCH 02/13] run ci on wasm32-unknown-unknown --- .github/workflows/ci.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4f85ea2a..2489e70b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -160,6 +160,26 @@ jobs: - name: test run: cross test --all --features unstable --target ${{ matrix.target }} + check_wasm: + name: Check wasm targets + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@master + + - name: Install nightly with wasm32-unknown-unknown + uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + target: wasm32-unknown-unknown + override: true + + - name: check + uses: actions-rs/cargo@v1 + with: + command: check + args: --target wasm32-unknown-unknown + check_fmt_and_docs: name: Checking fmt and docs runs-on: ubuntu-latest From 0805363dc036bd1e895fc78f7abc69eb4e93fcdb Mon Sep 17 00:00:00 2001 From: Jacob Rothstein Date: Mon, 24 Aug 2020 08:43:00 -0700 Subject: [PATCH 03/13] use cargo cache and matrix rust --- .github/workflows/ci.yml | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2489e70b4..708b596e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -163,14 +163,23 @@ jobs: check_wasm: name: Check wasm targets runs-on: ubuntu-latest + strategy: + matrix: + rust: [nightly, beta, stable] + + - name: Cache cargo registry + uses: actions/cache@v2 + with: + path: ~/.cargo/registry + key: wasm32-${{ matrix.rust }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }} steps: - uses: actions/checkout@master - - name: Install nightly with wasm32-unknown-unknown + - name: Install rust with wasm32-unknown-unknown uses: actions-rs/toolchain@v1 with: - toolchain: nightly + toolchain: ${{ matrix.rust }} target: wasm32-unknown-unknown override: true From b351f05e52051742a24ba39a2552e53f688732bb Mon Sep 17 00:00:00 2001 From: Jacob Rothstein Date: Mon, 24 Aug 2020 08:47:08 -0700 Subject: [PATCH 04/13] fix yaml format --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 708b596e7..c83e2f480 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -167,12 +167,6 @@ jobs: matrix: rust: [nightly, beta, stable] - - name: Cache cargo registry - uses: actions/cache@v2 - with: - path: ~/.cargo/registry - key: wasm32-${{ matrix.rust }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }} - steps: - uses: actions/checkout@master @@ -183,6 +177,12 @@ jobs: target: wasm32-unknown-unknown override: true + - name: Cache cargo registry + uses: actions/cache@v2 + with: + path: ~/.cargo/registry + key: wasm32-${{ matrix.rust }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }} + - name: check uses: actions-rs/cargo@v1 with: From 34594a01faae394a73766147ee639d6fd1dffc7d Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Mon, 24 Aug 2020 17:58:02 +0200 Subject: [PATCH 05/13] check unstable --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c83e2f480..7bdc6aac9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -187,8 +187,14 @@ jobs: uses: actions-rs/cargo@v1 with: command: check - args: --target wasm32-unknown-unknown + args: --target wasm32-unknown-unknown + - name: check unstable + uses: actions-rs/cargo@v1 + with: + command: check + args: --target wasm32-unknown-unknown --tests --all --features unstable + check_fmt_and_docs: name: Checking fmt and docs runs-on: ubuntu-latest From 669aa8a39c7b4f7d1e4cbede0b5f96c90f02ce3b Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Mon, 24 Aug 2020 18:04:39 +0200 Subject: [PATCH 06/13] fix wasm32 compiles --- src/task/builder.rs | 11 ++++++----- tests/collect.rs | 6 ++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/task/builder.rs b/src/task/builder.rs index d3a353691..391201d84 100644 --- a/src/task/builder.rs +++ b/src/task/builder.rs @@ -1,4 +1,3 @@ -use std::cell::Cell; use std::future::Future; use std::pin::Pin; use std::sync::Arc; @@ -7,7 +6,7 @@ use std::task::{Context, Poll}; use pin_project_lite::pin_project; use crate::io; -use crate::task::{self, JoinHandle, Task, TaskLocalsWrapper}; +use crate::task::{JoinHandle, Task, TaskLocalsWrapper}; /// Task builder that configures the settings of a new task. #[derive(Debug, Default)] @@ -61,7 +60,7 @@ impl Builder { }); let task = wrapped.tag.task().clone(); - let handle = task::executor::spawn(wrapped); + let handle = crate::task::executor::spawn(wrapped); Ok(JoinHandle::new(handle, task)) } @@ -81,7 +80,7 @@ impl Builder { }); let task = wrapped.tag.task().clone(); - let handle = task::executor::local(wrapped); + let handle = crate::task::executor::local(wrapped); Ok(JoinHandle::new(handle, task)) } @@ -143,6 +142,8 @@ impl Builder { where F: Future, { + use std::cell::Cell; + let wrapped = self.build(future); // Log this `block_on` operation. @@ -167,7 +168,7 @@ impl Builder { TaskLocalsWrapper::set_current(&wrapped.tag, || { let res = if should_run { // The first call should run the executor - task::executor::run(wrapped) + crate::task::executor::run(wrapped) } else { futures_lite::future::block_on(wrapped) }; diff --git a/tests/collect.rs b/tests/collect.rs index d24484f4e..7ab80ccc9 100644 --- a/tests/collect.rs +++ b/tests/collect.rs @@ -1,6 +1,6 @@ #[cfg(feature = "unstable")] #[test] -fn test_send() -> async_std::io::Result<()> { +fn test_send() { use async_std::prelude::*; use async_std::{stream, task}; @@ -14,7 +14,5 @@ fn test_send() -> async_std::io::Result<()> { // This line triggers a compilation error test_send_trait(&fut); - - Ok(()) - }) + }); } From 1e5d42e89a4fd431401cb63a6365e18aca4471e0 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Mon, 14 Sep 2020 14:51:09 +0200 Subject: [PATCH 07/13] disable caching on ci --- .github/workflows/ci.yml | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7bdc6aac9..36a9a4254 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,24 +29,6 @@ jobs: toolchain: ${{ matrix.rust }} override: true - - name: Cache cargo registry - uses: actions/cache@v2 - with: - path: ~/.cargo/registry - key: ${{ matrix.os }}-${{ matrix.rust }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }} - - - name: Cache cargo index - uses: actions/cache@v2 - with: - path: ~/.cargo/git - key: ${{ matrix.os }}-${{ matrix.rust }}-cargo-index-${{ hashFiles('**/Cargo.toml') }} - - - name: Cache cargo build - uses: actions/cache@v2 - with: - path: target - key: ${{ matrix.os }}-${{ matrix.rust }}-cargo-build-target-${{ hashFiles('**/Cargo.toml') }} - - name: check uses: actions-rs/cargo@v1 with: From 3058abe311b8ad89855ad58faf5d969ba3db96ef Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Mon, 14 Sep 2020 15:57:34 +0200 Subject: [PATCH 08/13] remove futures-timer in favor of gloo timers directly --- Cargo.toml | 16 ++-------------- src/utils.rs | 6 ++++-- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 79cb7e15e..170a3c2d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,6 @@ default = [ docs = ["attributes", "unstable", "default"] unstable = [ "std", - "futures-timer", ] attributes = ["async-attributes"] std = [ @@ -74,10 +73,7 @@ once_cell = { version = "1.3.1", optional = true } pin-project-lite = { version = "0.1.4", optional = true } pin-utils = { version = "0.1.0-alpha.4", optional = true } slab = { version = "0.4.2", optional = true } -futures-timer = { version = "3.0.2", optional = true } -# Devdepencency, but they are not allowed to be optional :/ -surf = { version = "1.0.3", optional = true } [target.'cfg(not(target_os = "unknown"))'.dependencies] async-executor = { version = "1.0.0", optional = true } @@ -86,9 +82,9 @@ blocking = { version = "1.0.0", optional = true } futures-lite = { version = "1.0.0", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] -futures-timer = { version = "3.0.2", features = ["wasm-bindgen"] } +gloo-timers = { version = "0.2.1", features = ["futures"] } wasm-bindgen-futures = { version = "0.4.10", optional = true } -futures-channel = { version = "0.3.4", optional = true } +futures-channel = { version = "0.3.4", optional = true, default-features = false, features = ["alloc"] } [target.'cfg(target_arch = "wasm32")'.dev-dependencies] wasm-bindgen-test = "0.3.10" @@ -109,11 +105,3 @@ rand_xorshift = "0.2.0" [[test]] name = "stream" required-features = ["unstable"] - -[[example]] -name = "tcp-ipv4-and-6-echo" -required-features = ["unstable"] - -[[example]] -name = "surf-web" -required-features = ["surf"] diff --git a/src/utils.rs b/src/utils.rs index 528a7074e..10eec6533 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -77,12 +77,14 @@ mod timer { use std::pin::Pin; use std::task::Poll; + use gloo_timers::future::TimeoutFuture; + #[derive(Debug)] - pub(crate) struct Timer(futures_timer::Delay); + pub(crate) struct Timer(TimeoutFuture); impl Timer { pub(crate) fn after(dur: std::time::Duration) -> Self { - Timer(futures_timer::Delay::new(dur)) + Timer(TimeoutFuture::new(dur.as_millis() as u32)) } } From fdfc736d80ba3acf3edaeebb8b88f1653ca7dbdd Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Mon, 14 Sep 2020 16:07:24 +0200 Subject: [PATCH 09/13] more fixes for features --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 170a3c2d9..b3f448705 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ default = [ "log", "num_cpus", "pin-project-lite", + "gloo-timers", ] docs = ["attributes", "unstable", "default"] unstable = [ @@ -74,7 +75,6 @@ pin-project-lite = { version = "0.1.4", optional = true } pin-utils = { version = "0.1.0-alpha.4", optional = true } slab = { version = "0.4.2", optional = true } - [target.'cfg(not(target_os = "unknown"))'.dependencies] async-executor = { version = "1.0.0", optional = true } async-io = { version = "1.0.1", optional = true } @@ -82,7 +82,7 @@ blocking = { version = "1.0.0", optional = true } futures-lite = { version = "1.0.0", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] -gloo-timers = { version = "0.2.1", features = ["futures"] } +gloo-timers = { version = "0.2.1", features = ["futures"], optional = true } wasm-bindgen-futures = { version = "0.4.10", optional = true } futures-channel = { version = "0.3.4", optional = true, default-features = false, features = ["alloc"] } From 63ef3606e5f69c39d4cccc4146aba6c7a7ffe537 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Mon, 14 Sep 2020 16:08:25 +0200 Subject: [PATCH 10/13] fixup cargo --- Cargo.toml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index b3f448705..24dee52b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -105,3 +105,11 @@ rand_xorshift = "0.2.0" [[test]] name = "stream" required-features = ["unstable"] + +[[example]] +name = "tcp-ipv4-and-6-echo" +required-features = ["unstable"] + +[[example]] +name = "surf-web" +required-features = ["surf"] \ No newline at end of file From 2c20af17e2320c5de4917371da4ccb8139a1b060 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Mon, 14 Sep 2020 16:09:37 +0200 Subject: [PATCH 11/13] cleanup --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 24dee52b3..52fc90311 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,7 +84,7 @@ futures-lite = { version = "1.0.0", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] gloo-timers = { version = "0.2.1", features = ["futures"], optional = true } wasm-bindgen-futures = { version = "0.4.10", optional = true } -futures-channel = { version = "0.3.4", optional = true, default-features = false, features = ["alloc"] } +futures-channel = { version = "0.3.4", optional = true } [target.'cfg(target_arch = "wasm32")'.dev-dependencies] wasm-bindgen-test = "0.3.10" @@ -112,4 +112,4 @@ required-features = ["unstable"] [[example]] name = "surf-web" -required-features = ["surf"] \ No newline at end of file +required-features = ["surf"] From fc58dc3c0c94b5fb19955200a89a026e31e5f375 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Mon, 14 Sep 2020 16:17:04 +0200 Subject: [PATCH 12/13] fix unstable only builds --- Cargo.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 52fc90311..6f6cfe4bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ default = [ docs = ["attributes", "unstable", "default"] unstable = [ "std", + "async-io" ] attributes = ["async-attributes"] std = [ @@ -75,6 +76,9 @@ pin-project-lite = { version = "0.1.4", optional = true } pin-utils = { version = "0.1.0-alpha.4", optional = true } slab = { version = "0.4.2", optional = true } +# Devdepencency, but they are not allowed to be optional :/ +surf = { version = "1.0.3", optional = true } + [target.'cfg(not(target_os = "unknown"))'.dependencies] async-executor = { version = "1.0.0", optional = true } async-io = { version = "1.0.1", optional = true } From 030e9e583b22f3d191edfbd7edee32f0730caad4 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Mon, 14 Sep 2020 16:19:48 +0200 Subject: [PATCH 13/13] commit the changes.. --- src/utils.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 10eec6533..d80524446 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -59,7 +59,10 @@ pub(crate) trait Context { fn context(self, message: impl Fn() -> String) -> Self; } -#[cfg(all(not(target_os = "unknown"), feature = "default"))] +#[cfg(all( + not(target_os = "unknown"), + any(feature = "default", feature = "unstable") +))] mod timer { pub type Timer = async_io::Timer; } @@ -69,10 +72,7 @@ pub(crate) fn timer_after(dur: std::time::Duration) -> timer::Timer { Timer::after(dur) } -#[cfg(any( - all(target_arch = "wasm32", feature = "default"), - all(feature = "unstable", not(feature = "default")) -))] +#[cfg(any(all(target_arch = "wasm32", feature = "default"),))] mod timer { use std::pin::Pin; use std::task::Poll;