Skip to content

Commit

Permalink
Support compiling on wasm targets (Supersede #1068) (#1160)
Browse files Browse the repository at this point in the history
* 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 <Jiahao_XU@outlook.com>

* Add CI check for wasm

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Fix CI

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

* Fix clippy warning on wasm

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>

---------

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Co-authored-by: Josiah Savary <hello@jsavary.com>
  • Loading branch information
NobodyXu and jozanza authored Jul 14, 2024
1 parent 4255e9a commit 184d212
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,23 @@ jobs:
- run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --release
- run: cargo test -Z build-std=std ${{ matrix.no_run }} --workspace --target ${{ matrix.target }} --features parallel

check-wasm:
name: Test wasm
runs-on: ubuntu-latest
strategy:
matrix:
target: [wasm32-unknown-unknown]
steps:
- uses: actions/checkout@v4
- name: Install Rust (rustup)
run: |
rustup target add ${{ matrix.target }}
shell: bash
- uses: Swatinem/rust-cache@v2
- run: cargo test --no-run --target ${{ matrix.target }}
- run: cargo test --no-run --target ${{ matrix.target }} --release
- run: cargo test --no-run --target ${{ matrix.target }} --features parallel

cuda:
name: Test CUDA support
runs-on: ubuntu-20.04
Expand Down
2 changes: 2 additions & 0 deletions src/command_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ impl StderrForwarder {
self.bytes_available_failed = true;
MIN_BUFFER_CAPACITY
}
#[cfg(target_family = "wasm")]
Err(_) => panic!("bytes_available should always succeed on wasm"),
Ok(bytes_available) => MIN_BUFFER_CAPACITY.max(bytes_available),
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/parallel/stderr.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#![cfg_attr(target_family = "wasm", allow(unused))]
/// Helpers functions for [ChildStderr].
use std::{convert::TryInto, process::ChildStderr};

use crate::{Error, ErrorKind};

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

#[cfg(unix)]
Expand Down
4 changes: 3 additions & 1 deletion src/tempfile.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(target_family = "wasm", allow(unused))]

use std::{
collections::hash_map::RandomState,
fs::{remove_file, File, OpenOptions},
Expand All @@ -6,7 +8,7 @@ use std::{
path::{Path, PathBuf},
};

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

fn rand() -> u64 {
Expand Down

0 comments on commit 184d212

Please sign in to comment.