Skip to content

Commit 1e3af2d

Browse files
feat(rust): async-spawn - build under no_std + alloc (#1600)
* async-spawn: build under no_std + alloc * ci: guard the no_std contract for async + async-spawn with wasm32v1-none * fmt: reorder imports in spawn.rs to satisfy rustfmt
1 parent 2e00369 commit 1e3af2d

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

.github/workflows/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ jobs:
199199
run: rustup target add wasm32-unknown-unknown
200200
- name: Install wasm32-wasip1 target
201201
run: rustup target add wasm32-wasip1
202+
- name: Install wasm32v1-none target
203+
run: rustup target add wasm32v1-none
202204

203205
# Verify the output of the `./ci/rebuild-libwit-bindgen-cabi.sh` script is
204206
# up-to-date.
@@ -227,6 +229,10 @@ jobs:
227229
- run: cargo build --target wasm32-wasip1 -p wit-bindgen --no-default-features --features inter-task-wakeup
228230
- run: cargo build --target wasm32-wasip1 -p wit-bindgen --no-default-features --features futures-stream
229231

232+
# wasm32v1-none has no std, so a stray std::* usage fails to link here.
233+
- run: cargo build --target wasm32v1-none -p wit-bindgen --no-default-features --features async
234+
- run: cargo build --target wasm32v1-none -p wit-bindgen --no-default-features --features async-spawn
235+
230236
# Verity that documentation can be generated for the rust bindings crate.
231237
- run: rustup update nightly --no-self-update
232238
- run: cargo +nightly doc -p wit-bindgen --no-deps

crates/guest-rust/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ all-features = true
2727
[dependencies]
2828
wit-bindgen-rust-macro = { path = "./macro", optional = true, default-features = false, version = "0.57.1" }
2929
bitflags = { workspace = true, optional = true }
30-
futures = { version = "0.3.30", optional = true }
30+
futures = { version = "0.3.30", optional = true, default-features = false, features = ["alloc"] }
3131

3232
# When built as part of libstd
3333
core = { version = "1.0", optional = true, package = "rustc-std-workspace-core" }
@@ -40,7 +40,7 @@ realloc = []
4040
std = []
4141
async = []
4242
bitflags = ["dep:bitflags"]
43-
async-spawn = ['async', 'dep:futures', 'std']
43+
async-spawn = ['async', 'dep:futures']
4444
futures-stream = ['async', 'dep:futures']
4545
macro-string = ["wit-bindgen-rust-macro?/macro-string"]
4646

crates/guest-rust/src/rt/async_support/spawn.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
#![allow(static_mut_refs)]
55

66
use crate::rt::async_support::BoxFuture;
7+
use alloc::boxed::Box;
8+
use alloc::vec::Vec;
9+
use core::future::Future;
10+
use core::task::{Context, Poll};
711
use futures::stream::{FuturesUnordered, StreamExt};
8-
use std::boxed::Box;
9-
use std::future::Future;
10-
use std::task::{Context, Poll};
11-
use std::vec::Vec;
1212

1313
/// Any newly-deferred work queued by calls to the `spawn` function while
1414
/// polling the current task.

0 commit comments

Comments
 (0)