Skip to content

Commit 184d212

Browse files
NobodyXujozanza
andauthored
Support compiling on wasm targets (Supersede #1068) (#1160)
* Don't throw compiler error for wasm targets * Don't throw compiler error for wasm targets * Fix attr syntax error * Add unimplemented path for pipe error match for wasm target * Replace `unimplemented!` with `panic!` Signed-off-by: Jiahao XU <[email protected]> * Add CI check for wasm Signed-off-by: Jiahao XU <[email protected]> * Fix CI Signed-off-by: Jiahao XU <[email protected]> * Fix clippy warning on wasm Signed-off-by: Jiahao XU <[email protected]> --------- Signed-off-by: Jiahao XU <[email protected]> Co-authored-by: Josiah Savary <[email protected]>
1 parent 4255e9a commit 184d212

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

Diff for: .github/workflows/main.yml

+17
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,23 @@ jobs:
171171
- run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release
172172
- run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel
173173

174+
check-wasm:
175+
name: Test wasm
176+
runs-on: ubuntu-latest
177+
strategy:
178+
matrix:
179+
target: [wasm32-unknown-unknown]
180+
steps:
181+
- uses: actions/checkout@v4
182+
- name: Install Rust (rustup)
183+
run: |
184+
rustup target add ${{ matrix.target }}
185+
shell: bash
186+
- uses: Swatinem/rust-cache@v2
187+
- run: cargo test --no-run --target ${{ matrix.target }}
188+
- run: cargo test --no-run --target ${{ matrix.target }} --release
189+
- run: cargo test --no-run --target ${{ matrix.target }} --features parallel
190+
174191
cuda:
175192
name: Test CUDA support
176193
runs-on: ubuntu-20.04

Diff for: src/command_helpers.rs

+2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ impl StderrForwarder {
151151
self.bytes_available_failed = true;
152152
MIN_BUFFER_CAPACITY
153153
}
154+
#[cfg(target_family = "wasm")]
155+
Err(_) => panic!("bytes_available should always succeed on wasm"),
154156
Ok(bytes_available) => MIN_BUFFER_CAPACITY.max(bytes_available),
155157
}
156158
} else {

Diff for: src/parallel/stderr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
#![cfg_attr(target_family = "wasm", allow(unused))]
12
/// Helpers functions for [ChildStderr].
23
use std::{convert::TryInto, process::ChildStderr};
34

45
use crate::{Error, ErrorKind};
56

6-
#[cfg(all(not(unix), not(windows)))]
7+
#[cfg(all(not(unix), not(windows), not(target_family = "wasm")))]
78
compile_error!("Only unix and windows support non-blocking pipes! For other OSes, disable the parallel feature.");
89

910
#[cfg(unix)]

Diff for: src/tempfile.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(target_family = "wasm", allow(unused))]
2+
13
use std::{
24
collections::hash_map::RandomState,
35
fs::{remove_file, File, OpenOptions},
@@ -6,7 +8,7 @@ use std::{
68
path::{Path, PathBuf},
79
};
810

9-
#[cfg(not(any(unix, target_os = "wasi", windows)))]
11+
#[cfg(not(any(unix, target_family = "wasm", windows)))]
1012
compile_error!("Your system is not supported since cc cannot create named tempfile");
1113

1214
fn rand() -> u64 {

0 commit comments

Comments
 (0)