From 047847fcac865b637f456cbc5d98673f1851d5c6 Mon Sep 17 00:00:00 2001 From: Jacob Rothstein Date: Thu, 13 Aug 2020 21:33:37 -0700 Subject: [PATCH 1/9] 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 53429502331926f130dcbe30f63344d6457c895c Mon Sep 17 00:00:00 2001 From: Jacob Rothstein Date: Mon, 24 Aug 2020 08:43:00 -0700 Subject: [PATCH 2/9] 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 8afc6a71d595c7b2e43a7355a591d17e6b6a530a Mon Sep 17 00:00:00 2001 From: Jacob Rothstein Date: Mon, 24 Aug 2020 08:47:08 -0700 Subject: [PATCH 3/9] 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 7d7af99c9730b6ad3e090a1730d2b77a75502340 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Mon, 24 Aug 2020 17:54:41 +0200 Subject: [PATCH 4/9] 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 109c7ad74..7fbe2456d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,7 +86,7 @@ blocking = { version = "0.5.2", optional = true } futures-lite = { version = "0.1.8", 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 04cc2fd09bc0597ccd28641a598fc1a0cdeee060 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Mon, 24 Aug 2020 17:58:02 +0200 Subject: [PATCH 5/9] 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 d0d277d8e33b9db4c3486fbbfaa0ef14405925e7 Mon Sep 17 00:00:00 2001 From: dignifiedquire Date: Mon, 24 Aug 2020 18:04:39 +0200 Subject: [PATCH 6/9] 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 236081c05..d3aed0d50 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 e6a1e16a03f479c13fcaf770380c846846e2ed76 Mon Sep 17 00:00:00 2001 From: Jacob Rothstein Date: Mon, 24 Aug 2020 22:25:58 -0700 Subject: [PATCH 7/9] temporary: test if not using the build cache resolves confusing ci issue --- .github/workflows/ci.yml | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7bdc6aac9..cf213d29e 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: @@ -177,12 +159,6 @@ 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 b108d9fa9f05883c622fda54a5a0093e2491aefd Mon Sep 17 00:00:00 2001 From: Jacob Rothstein Date: Mon, 24 Aug 2020 23:28:39 -0700 Subject: [PATCH 8/9] maybe fix stuff --- .github/workflows/ci.yml | 4 ++-- Cargo.toml | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf213d29e..a96f4981f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -163,13 +163,13 @@ jobs: uses: actions-rs/cargo@v1 with: command: check - args: --target wasm32-unknown-unknown + args: --target wasm32-unknown-unknown --features wasm - name: check unstable uses: actions-rs/cargo@v1 with: command: check - args: --target wasm32-unknown-unknown --tests --all --features unstable + args: --target wasm32-unknown-unknown --tests --all --features unstable,wasm check_fmt_and_docs: name: Checking fmt and docs diff --git a/Cargo.toml b/Cargo.toml index 7fbe2456d..663b883ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,9 +49,12 @@ std = [ "once_cell", "pin-utils", "slab", + "async-mutex", +] +wasm = [ + "futures-timer/wasm-bindgen", "wasm-bindgen-futures", "futures-channel", - "async-mutex", ] alloc = [ "futures-core/alloc", @@ -75,6 +78,8 @@ 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 } +wasm-bindgen-futures = { version = "0.4.10", optional = true } +futures-channel = { version = "0.3.4", optional = true } # Devdepencency, but they are not allowed to be optional :/ surf = { version = "1.0.3", optional = true } @@ -85,13 +90,7 @@ async-io = { version = "0.1.8", optional = true } blocking = { version = "0.5.2", optional = true } futures-lite = { version = "0.1.8", optional = true } -[target.'cfg(target_arch = "wasm32")'.dependencies] -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 } -[target.'cfg(target_arch = "wasm32")'.dev-dependencies] -wasm-bindgen-test = "0.3.10" [dependencies.tokio] version = "0.2" @@ -105,6 +104,7 @@ rand = "0.7.3" tempfile = "3.1.0" futures = "0.3.4" rand_xorshift = "0.2.0" +wasm-bindgen-test = "0.3.10" [[test]] name = "stream" From d29212f5dd9434b57efc17cba2496b50614ce968 Mon Sep 17 00:00:00 2001 From: Jacob Rothstein Date: Thu, 3 Sep 2020 20:22:56 -0700 Subject: [PATCH 9/9] rename wasm feature to wasm-bindgen, which is automatically enabled by wasm-pack --- .github/workflows/ci.yml | 12 ++---------- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a96f4981f..6a9fa0b5e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,14 +41,6 @@ jobs: command: check args: --features unstable --all --bins --examples --tests - - name: check wasm - uses: actions-rs/cargo@v1 - with: - command: check - target: wasm32-unknown-unknown - override: true - args: --features unstable --all --bins --tests - - name: check bench uses: actions-rs/cargo@v1 if: matrix.rust == 'nightly' @@ -163,13 +155,13 @@ jobs: uses: actions-rs/cargo@v1 with: command: check - args: --target wasm32-unknown-unknown --features wasm + args: --target wasm32-unknown-unknown --features wasm-bindgen - name: check unstable uses: actions-rs/cargo@v1 with: command: check - args: --target wasm32-unknown-unknown --tests --all --features unstable,wasm + args: --target wasm32-unknown-unknown --tests --all --features unstable,wasm-bindgen check_fmt_and_docs: name: Checking fmt and docs diff --git a/Cargo.toml b/Cargo.toml index 663b883ca..49163c3c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,7 +51,7 @@ std = [ "slab", "async-mutex", ] -wasm = [ +wasm-bindgen = [ "futures-timer/wasm-bindgen", "wasm-bindgen-futures", "futures-channel",