From c61fee6d55c011e6f5eec29788101667ee62631c Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Tue, 22 Jun 2021 21:51:57 +0200 Subject: Fix compilation on WASM Fixes #9214. Fixes #9210. --- .github/workflows/ci.yaml | 8 +++++++- crates/stdx/src/lib.rs | 7 +++++-- crates/stdx/src/process.rs | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 63518e67f..222676d5e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -66,6 +66,9 @@ jobs: env: targets: "powerpc-unknown-linux-gnu x86_64-unknown-linux-musl" + # The rust-analyzer binary is not expected to compile on WASM, but the IDE + # crate should + targets_ide: "wasm32-unknown-unknown" steps: - name: Checkout repository @@ -79,7 +82,7 @@ jobs: override: true - name: Install Rust targets - run: rustup target add ${{ env.targets }} + run: rustup target add ${{ env.targets }} ${{ env.targets_ide }} - name: Cache Dependencies uses: Swatinem/rust-cache@ce325b60658c1b38465c06cc965b79baf32c1e72 @@ -89,6 +92,9 @@ jobs: for target in ${{ env.targets }}; do cargo check --target=$target --all-targets done + for target in ${{ env.targets_ide }}; do + cargo check -p ide --target=$target --all-targets + done typescript: name: TypeScript diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index 18d5fadb9..2963484fa 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs @@ -110,7 +110,7 @@ pub fn defer(f: F) -> impl Drop { D(Some(f)) } -#[repr(transparent)] +#[cfg_attr(not(target_arch = "wasm32"), repr(transparent))] pub struct JodChild(pub std::process::Child); impl ops::Deref for JodChild { @@ -135,7 +135,10 @@ impl Drop for JodChild { impl JodChild { pub fn into_inner(self) -> std::process::Child { - // SAFETY: repr transparent + if cfg!(target_arch = "wasm32") { + panic!("no processes on wasm"); + } + // SAFETY: repr transparent, except on WASM unsafe { std::mem::transmute::(self) } } } diff --git a/crates/stdx/src/process.rs b/crates/stdx/src/process.rs index 692a2ab3d..b290ba2f0 100644 --- a/crates/stdx/src/process.rs +++ b/crates/stdx/src/process.rs @@ -236,3 +236,19 @@ mod imp { slice::from_raw_parts_mut(v.as_mut_ptr().add(v.len()), v.capacity() - v.len()) } } + +#[cfg(target_arch = "wasm32")] +mod imp { + use std::{ + io, + process::{ChildStderr, ChildStdout}, + }; + + pub(crate) fn read2( + _out_pipe: ChildStdout, + _err_pipe: ChildStderr, + _data: &mut dyn FnMut(bool, &mut Vec, bool), + ) -> io::Result<()> { + panic!("no processes on wasm") + } +} -- cgit v1.2.3