Skip to content

Support compiling on wasm targets (Supersede #1068) #1160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -130,6 +130,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