From da1badf13b529a336d849cd73d4675fab17eec87 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 23 Jun 2021 17:02:40 +0530 Subject: feature flag unix specific stuff --- crates/stdx/Cargo.toml | 2 ++ crates/stdx/src/lib.rs | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/stdx/Cargo.toml b/crates/stdx/Cargo.toml index f78c5da7c..a6727ed2f 100644 --- a/crates/stdx/Cargo.toml +++ b/crates/stdx/Cargo.toml @@ -20,5 +20,7 @@ miow = "0.3.6" winapi = "0.3.9" [features] +default = [] +unix_stuff = [] # Uncomment to enable for the whole crate graph # default = [ "backtrace" ] diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index 2963484fa..027830134 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs @@ -2,6 +2,7 @@ use std::{cmp::Ordering, ops, time::Instant}; mod macros; +#[cfg(feature = "unix_stuff")] pub mod process; pub mod panic_context; @@ -110,9 +111,12 @@ pub fn defer(f: F) -> impl Drop { D(Some(f)) } -#[cfg_attr(not(target_arch = "wasm32"), repr(transparent))] + +#[cfg(feature = "unix_stuff")] +#[repr(transparent)] pub struct JodChild(pub std::process::Child); +#[cfg(feature = "unix_stuff")] impl ops::Deref for JodChild { type Target = std::process::Child; fn deref(&self) -> &std::process::Child { @@ -120,12 +124,14 @@ impl ops::Deref for JodChild { } } +#[cfg(feature = "unix_stuff")] impl ops::DerefMut for JodChild { fn deref_mut(&mut self) -> &mut std::process::Child { &mut self.0 } } +#[cfg(feature = "unix_stuff")] impl Drop for JodChild { fn drop(&mut self) { let _ = self.0.kill(); @@ -133,12 +139,10 @@ impl Drop for JodChild { } } +#[cfg(feature = "unix_stuff")] impl JodChild { pub fn into_inner(self) -> std::process::Child { - if cfg!(target_arch = "wasm32") { - panic!("no processes on wasm"); - } - // SAFETY: repr transparent, except on WASM + // SAFETY: repr transparent unsafe { std::mem::transmute::(self) } } } -- cgit v1.2.3