diff --git a/veilid-core/Cargo.toml b/veilid-core/Cargo.toml index 397df411..d0a218f2 100644 --- a/veilid-core/Cargo.toml +++ b/veilid-core/Cargo.toml @@ -149,7 +149,7 @@ sanitize-filename = "0.5.0" # Dependencies for native builds only # Linux, Windows, Mac, iOS, Android -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dependencies] # Tools config = { version = "0.13.4", default-features = false, features = ["yaml"] } @@ -186,7 +186,7 @@ rustls = "0.21.12" rustls-pemfile = "1.0.4" # Dependencies for WASM builds only -[target.'cfg(target_arch = "wasm32")'.dependencies] +[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies] veilid-tools = { version = "0.4.1", path = "../veilid-tools", default-features = false, features = [ "rt-wasm-bindgen", @@ -221,7 +221,7 @@ tracing-wasm = "0.2.1" keyvaluedb-web = "0.1.2" ### Configuration for WASM32 'web-sys' crate -[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys] +[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies.web-sys] version = "0.3.69" features = [ 'Document', @@ -259,12 +259,12 @@ tracing-oslog = { version = "0.1.2", optional = true } ### DEV DEPENDENCIES -[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] +[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dev-dependencies] simplelog = { version = "0.12.2", features = ["test"] } serial_test = "2.0.0" tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } -[target.'cfg(target_arch = "wasm32")'.dev-dependencies] +[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies] serial_test = { version = "2.0.0", default-features = false, features = [ "async", ] } diff --git a/veilid-core/src/crypto/types/byte_array_types.rs b/veilid-core/src/crypto/types/byte_array_types.rs index b2096a82..9d5666da 100644 --- a/veilid-core/src/crypto/types/byte_array_types.rs +++ b/veilid-core/src/crypto/types/byte_array_types.rs @@ -78,7 +78,7 @@ where macro_rules! byte_array_type { ($name:ident, $size:expr, $encoded_size:expr) => { #[derive(Clone, Copy, Hash, PartialOrd, Ord, PartialEq, Eq)] - #[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(into_wasm_abi))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(into_wasm_abi))] pub struct $name { pub bytes: [u8; $size], } @@ -280,17 +280,17 @@ macro_rules! byte_array_type { byte_array_type!(CryptoKey, CRYPTO_KEY_LENGTH, CRYPTO_KEY_LENGTH_ENCODED); -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type PublicKey = CryptoKey; -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type SecretKey = CryptoKey; -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type HashDigest = CryptoKey; -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type SharedSecret = CryptoKey; -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type RouteId = CryptoKey; -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type CryptoKeyDistance = CryptoKey; byte_array_type!(Signature, SIGNATURE_LENGTH, SIGNATURE_LENGTH_ENCODED); diff --git a/veilid-core/src/crypto/types/keypair.rs b/veilid-core/src/crypto/types/keypair.rs index 4fafd4ea..8bdb6c9d 100644 --- a/veilid-core/src/crypto/types/keypair.rs +++ b/veilid-core/src/crypto/types/keypair.rs @@ -2,7 +2,7 @@ use super::*; #[derive(Clone, Copy, Default, PartialOrd, Ord, PartialEq, Eq, Hash)] #[cfg_attr( - target_arch = "wasm32", + all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(from_wasm_abi, into_wasm_abi) )] diff --git a/veilid-core/src/crypto/types/mod.rs b/veilid-core/src/crypto/types/mod.rs index e3f24a81..536df17b 100644 --- a/veilid-core/src/crypto/types/mod.rs +++ b/veilid-core/src/crypto/types/mod.rs @@ -6,7 +6,7 @@ use core::fmt; use core::hash::Hash; /// Cryptography version fourcc code -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type CryptoKind = FourCC; /// Sort best crypto kinds first @@ -52,24 +52,24 @@ pub use crypto_typed::*; pub use crypto_typed_group::*; pub use keypair::*; -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type TypedKey = CryptoTyped; -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type TypedSecret = CryptoTyped; -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type TypedKeyPair = CryptoTyped; -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type TypedSignature = CryptoTyped; -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type TypedSharedSecret = CryptoTyped; -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type TypedKeyGroup = CryptoTypedGroup; -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type TypedSecretGroup = CryptoTypedGroup; -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type TypedKeyPairGroup = CryptoTypedGroup; -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type TypedSignatureGroup = CryptoTypedGroup; -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type TypedSharedSecretGroup = CryptoTypedGroup; diff --git a/veilid-core/src/intf/mod.rs b/veilid-core/src/intf/mod.rs index af238bee..226fad1d 100644 --- a/veilid-core/src/intf/mod.rs +++ b/veilid-core/src/intf/mod.rs @@ -1,12 +1,12 @@ use super::*; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", target_os = "unknown"))] mod wasm; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", target_os = "unknown"))] pub use wasm::*; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] mod native; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] pub use native::*; pub static KNOWN_PROTECTED_STORE_KEYS: [&str; 2] = ["device_encryption_key", "_test_key"]; diff --git a/veilid-core/src/lib.rs b/veilid-core/src/lib.rs index ed2211e4..f25ae046 100644 --- a/veilid-core/src/lib.rs +++ b/veilid-core/src/lib.rs @@ -28,7 +28,7 @@ #![recursion_limit = "256"] cfg_if::cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { #[cfg(any(feature = "rt-async-std", feature = "rt-tokio"))] compile_error!("features \"rt-async-std\" and \"rt-tokio\" can not be specified for WASM"); } else { diff --git a/veilid-core/src/network_manager/connection_manager.rs b/veilid-core/src/network_manager/connection_manager.rs index e385cc2f..2591f17f 100644 --- a/veilid-core/src/network_manager/connection_manager.rs +++ b/veilid-core/src/network_manager/connection_manager.rs @@ -574,7 +574,7 @@ impl ConnectionManager { // Called by low-level network when any connection-oriented protocol connection appears // either from incoming connections. - #[cfg_attr(target_arch = "wasm32", expect(dead_code))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))] pub(super) async fn on_accepted_protocol_network_connection( &self, protocol_connection: ProtocolNetworkConnection, diff --git a/veilid-core/src/network_manager/mod.rs b/veilid-core/src/network_manager/mod.rs index 86ef95da..fe3c4478 100644 --- a/veilid-core/src/network_manager/mod.rs +++ b/veilid-core/src/network_manager/mod.rs @@ -1,8 +1,8 @@ use crate::*; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] mod native; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", target_os = "unknown"))] mod wasm; mod address_check; @@ -36,16 +36,16 @@ use connection_handle::*; use crypto::*; use futures_util::stream::FuturesUnordered; use hashlink::LruCache; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] use native::*; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] pub use native::{MAX_CAPABILITIES, PUBLIC_INTERNET_CAPABILITIES}; use routing_table::*; use rpc_processor::*; use storage_manager::*; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", target_os = "unknown"))] use wasm::*; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", target_os = "unknown"))] pub use wasm::{/* LOCAL_NETWORK_CAPABILITIES, */ MAX_CAPABILITIES, PUBLIC_INTERNET_CAPABILITIES,}; //////////////////////////////////////////////////////////////////////////////////////// @@ -119,7 +119,7 @@ enum SendDataToExistingFlowResult { #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum StartupDisposition { Success, - #[cfg_attr(target_arch = "wasm32", expect(dead_code))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))] BindRetry, } diff --git a/veilid-core/src/network_manager/network_connection.rs b/veilid-core/src/network_manager/network_connection.rs index 674f087d..82078818 100644 --- a/veilid-core/src/network_manager/network_connection.rs +++ b/veilid-core/src/network_manager/network_connection.rs @@ -4,7 +4,7 @@ use std::{io, sync::Arc}; use stop_token::prelude::*; cfg_if::cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { // No accept support for WASM } else { diff --git a/veilid-core/src/network_manager/types/address.rs b/veilid-core/src/network_manager/types/address.rs index 487dc515..0091f08e 100644 --- a/veilid-core/src/network_manager/types/address.rs +++ b/veilid-core/src/network_manager/types/address.rs @@ -20,7 +20,7 @@ impl Address { SocketAddr::V6(v6) => Address::IPV6(*v6.ip()), } } - #[cfg_attr(target_arch = "wasm32", expect(dead_code))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))] pub fn from_ip_addr(addr: IpAddr) -> Address { match addr { IpAddr::V4(v4) => Address::IPV4(v4), diff --git a/veilid-core/src/network_manager/types/dial_info/mod.rs b/veilid-core/src/network_manager/types/dial_info/mod.rs index 80b5d488..a1361e3d 100644 --- a/veilid-core/src/network_manager/types/dial_info/mod.rs +++ b/veilid-core/src/network_manager/types/dial_info/mod.rs @@ -268,7 +268,7 @@ impl DialInfo { Self::WSS(di) => di.socket_address.port(), } } - #[cfg_attr(target_arch = "wasm32", expect(dead_code))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))] pub fn set_port(&mut self, port: u16) { match self { Self::UDP(di) => di.socket_address.set_port(port), @@ -366,7 +366,7 @@ impl DialInfo { // This will not be used on signed dialinfo, only for bootstrapping, so we don't need to worry about // the '0.0.0.0' address being propagated across the routing table cfg_if::cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { vec![SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0,0,0,0)), port)] } else { match split_url.host { diff --git a/veilid-core/src/network_manager/wasm/.cargo/config.toml b/veilid-core/src/network_manager/wasm/.cargo/config.toml index f4e8c002..1edd5dff 100644 --- a/veilid-core/src/network_manager/wasm/.cargo/config.toml +++ b/veilid-core/src/network_manager/wasm/.cargo/config.toml @@ -1,2 +1,2 @@ [build] -target = "wasm32-unknown-unknown" +all(target_arch = "wasm32", target_os = "unknown") diff --git a/veilid-core/src/network_manager/wasm/protocol/ws.rs b/veilid-core/src/network_manager/wasm/protocol/ws.rs index 88a5ee8e..6d68acde 100644 --- a/veilid-core/src/network_manager/wasm/protocol/ws.rs +++ b/veilid-core/src/network_manager/wasm/protocol/ws.rs @@ -9,29 +9,6 @@ struct WebsocketNetworkConnectionInner { ws_stream: CloneStream, } -fn to_io(err: WsErr) -> io::Error { - match err { - WsErr::InvalidWsState { supplied: _ } => { - io::Error::new(io::ErrorKind::InvalidInput, err.to_string()) - } - WsErr::ConnectionNotOpen => io::Error::new(io::ErrorKind::NotConnected, err.to_string()), - WsErr::InvalidUrl { supplied: _ } => { - io::Error::new(io::ErrorKind::InvalidInput, err.to_string()) - } - WsErr::InvalidCloseCode { supplied: _ } => { - io::Error::new(io::ErrorKind::InvalidInput, err.to_string()) - } - WsErr::ReasonStringToLong => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()), - WsErr::ConnectionFailed { event: _ } => { - io::Error::new(io::ErrorKind::ConnectionRefused, err.to_string()) - } - WsErr::InvalidEncoding => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()), - WsErr::CantDecodeBlob => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()), - WsErr::UnknownDataType => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()), - _ => io::Error::new(io::ErrorKind::Other, err.to_string()), - } -} - #[derive(Clone)] pub struct WebsocketNetworkConnection { flow: Flow, @@ -65,7 +42,7 @@ impl WebsocketNetworkConnection { )] pub async fn close(&self) -> io::Result> { #[allow(unused_variables)] - let x = self.inner.ws_meta.close().await.map_err(to_io); + let x = self.inner.ws_meta.close().await.map_err(ws_err_to_io_error); #[cfg(feature = "verbose-tracing")] log_net!(debug "close result: {:?}", x); Ok(NetworkResult::value(())) @@ -83,7 +60,7 @@ impl WebsocketNetworkConnection { .send(WsMessage::Binary(message)), ) .await - .map_err(to_io) + .map_err(ws_err_to_io_error) .into_network_result()?; #[cfg(feature = "verbose-tracing")] @@ -140,7 +117,9 @@ impl WebsocketProtocolHandler { } let fut = SendWrapper::new(timeout(timeout_ms, async move { - WsMeta::connect(request, None).await.map_err(to_io) + WsMeta::connect(request, None) + .await + .map_err(ws_err_to_io_error) })); let (wsmeta, wsio) = network_result_try!(network_result_try!(fut diff --git a/veilid-core/src/routing_table/mod.rs b/veilid-core/src/routing_table/mod.rs index 5fe68495..503ab842 100644 --- a/veilid-core/src/routing_table/mod.rs +++ b/veilid-core/src/routing_table/mod.rs @@ -612,7 +612,7 @@ impl RoutingTable { } /// Return the domain's currently registered network class - #[cfg_attr(target_arch = "wasm32", expect(dead_code))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))] pub fn get_network_class(&self, routing_domain: RoutingDomain) -> Option { self.inner.read().get_network_class(routing_domain) } @@ -817,7 +817,7 @@ impl RoutingTable { } /// Makes a filter that finds nodes with a matching inbound dialinfo - #[cfg_attr(target_arch = "wasm32", expect(dead_code))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))] pub fn make_inbound_dial_info_entry_filter<'a>( routing_domain: RoutingDomain, dial_info_filter: DialInfoFilter, diff --git a/veilid-core/src/routing_table/routing_table_inner/routing_domains/editor.rs b/veilid-core/src/routing_table/routing_table_inner/routing_domains/editor.rs index 1544d2f9..3372ad74 100644 --- a/veilid-core/src/routing_table/routing_table_inner/routing_domains/editor.rs +++ b/veilid-core/src/routing_table/routing_table_inner/routing_domains/editor.rs @@ -7,7 +7,7 @@ pub trait RoutingDomainEditorCommonTrait { protocol_type: Option, ) -> &mut Self; fn set_relay_node(&mut self, relay_node: Option) -> &mut Self; - #[cfg_attr(target_arch = "wasm32", expect(dead_code))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))] fn add_dial_info(&mut self, dial_info: DialInfo, class: DialInfoClass) -> &mut Self; fn setup_network( &mut self, @@ -83,7 +83,7 @@ pub(super) enum RoutingDomainChangeCommon { AddDialInfo { dial_info_detail: DialInfoDetail, }, - // #[cfg_attr(target_arch = "wasm32", expect(dead_code))] + // #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))] // RemoveDialInfoDetail { // dial_info_detail: DialInfoDetail, // }, diff --git a/veilid-core/src/routing_table/routing_table_inner/routing_domains/local_network/editor.rs b/veilid-core/src/routing_table/routing_table_inner/routing_domains/local_network/editor.rs index 38b69ab0..f752df8f 100644 --- a/veilid-core/src/routing_table/routing_table_inner/routing_domains/local_network/editor.rs +++ b/veilid-core/src/routing_table/routing_table_inner/routing_domains/local_network/editor.rs @@ -1,4 +1,4 @@ -#![cfg_attr(target_arch = "wasm32", expect(dead_code))] +#![cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))] use super::*; diff --git a/veilid-core/src/routing_table/routing_table_inner/routing_domains/mod.rs b/veilid-core/src/routing_table/routing_table_inner/routing_domains/mod.rs index cabf87cd..51e281eb 100644 --- a/veilid-core/src/routing_table/routing_table_inner/routing_domains/mod.rs +++ b/veilid-core/src/routing_table/routing_table_inner/routing_domains/mod.rs @@ -143,7 +143,7 @@ impl RoutingDomainDetailCommon { pub fn network_class(&self) -> Option { cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { Some(NetworkClass::WebApp) } else { if self.address_types.is_empty() { diff --git a/veilid-core/src/rpc_processor/error.rs b/veilid-core/src/rpc_processor/error.rs index c2030fa7..25fac16d 100644 --- a/veilid-core/src/rpc_processor/error.rs +++ b/veilid-core/src/rpc_processor/error.rs @@ -52,7 +52,7 @@ impl RPCError { pub fn map_network(message: M) -> impl FnOnce(X) -> Self { move |x| Self::Network(format!("{}: {}", message.to_string(), x.to_string())) } - #[cfg_attr(target_arch = "wasm32", expect(dead_code))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), expect(dead_code))] pub fn try_again(x: X) -> Self { Self::TryAgain(x.to_string()) } diff --git a/veilid-core/src/table_store/mod.rs b/veilid-core/src/table_store/mod.rs index eb016890..de2a57d3 100644 --- a/veilid-core/src/table_store/mod.rs +++ b/veilid-core/src/table_store/mod.rs @@ -5,13 +5,13 @@ pub use table_db::*; pub mod tests; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", target_os = "unknown"))] mod wasm; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", target_os = "unknown"))] use wasm::*; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] mod native; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] use native::*; use keyvaluedb::*; @@ -20,14 +20,14 @@ const ALL_TABLE_NAMES: &[u8] = b"all_table_names"; /// Description of column #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct ColumnInfo { pub key_count: AlignedU64, } /// IO Stats for table #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct IOStatsInfo { /// Number of transaction. pub transactions: AlignedU64, @@ -51,7 +51,7 @@ pub struct IOStatsInfo { /// Description of table #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct TableInfo { /// Internal table name pub table_name: String, diff --git a/veilid-core/src/table_store/table_db.rs b/veilid-core/src/table_store/table_db.rs index f26e68db..739630d8 100644 --- a/veilid-core/src/table_store/table_db.rs +++ b/veilid-core/src/table_store/table_db.rs @@ -1,7 +1,7 @@ use crate::*; cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { use keyvaluedb_web::*; use keyvaluedb::*; } else { diff --git a/veilid-core/src/tests/common/test_veilid_config.rs b/veilid-core/src/tests/common/test_veilid_config.rs index e6f9dff3..5ee1a1a3 100644 --- a/veilid-core/src/tests/common/test_veilid_config.rs +++ b/veilid-core/src/tests/common/test_veilid_config.rs @@ -1,7 +1,7 @@ use crate::*; cfg_if! { - if #[cfg(not(target_arch = "wasm32"))] { + if #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] { use std::fs::File; use std::io::prelude::*; use std::path::PathBuf; @@ -61,7 +61,7 @@ wFAbkZY9eS/x6P7qrpd7dUA= cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { pub fn get_table_store_path() -> String { String::new() } @@ -207,9 +207,9 @@ pub fn config_callback(key: String) -> ConfigCallbackReturn { "network.routing_table.node_id" => Ok(Box::new(TypedKeyGroup::new())), "network.routing_table.node_id_secret" => Ok(Box::new(TypedSecretGroup::new())), // "network.routing_table.bootstrap" => Ok(Box::new(Vec::::new())), - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] "network.routing_table.bootstrap" => Ok(Box::new(vec!["bootstrap.veilid.net".to_string()])), - #[cfg(target_arch = "wasm32")] + #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] "network.routing_table.bootstrap" => Ok(Box::new(vec![ "ws://bootstrap.veilid.net:5150/ws".to_string(), ])), @@ -349,12 +349,12 @@ pub async fn test_config() { assert_eq!(inner.network.rpc.default_route_hop_count, 1u8); assert_eq!(inner.network.routing_table.node_id.len(), 0); assert_eq!(inner.network.routing_table.node_id_secret.len(), 0); - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] assert_eq!( inner.network.routing_table.bootstrap, vec!["bootstrap.veilid.net"], ); - #[cfg(target_arch = "wasm32")] + #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] assert_eq!( inner.network.routing_table.bootstrap, vec!["ws://bootstrap.veilid.net:5150/ws"], diff --git a/veilid-core/src/tests/mod.rs b/veilid-core/src/tests/mod.rs index e82fa3cc..f507a62d 100644 --- a/veilid-core/src/tests/mod.rs +++ b/veilid-core/src/tests/mod.rs @@ -3,7 +3,7 @@ mod android; pub mod common; #[cfg(all(target_os = "ios", feature = "veilid_core_ios_tests"))] mod ios; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] mod native; #[allow(unused_imports)] diff --git a/veilid-core/src/tests/native/mod.rs b/veilid-core/src/tests/native/mod.rs index da3b577a..84d96ebf 100644 --- a/veilid-core/src/tests/native/mod.rs +++ b/veilid-core/src/tests/native/mod.rs @@ -1,5 +1,5 @@ //! Test suite for Native -#![cfg(not(target_arch = "wasm32"))] +#![cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] use crate::tests::*; use crate::*; diff --git a/veilid-core/src/veilid_api/error.rs b/veilid-core/src/veilid_api/error.rs index bbe4cf17..b4150cd1 100644 --- a/veilid-core/src/veilid_api/error.rs +++ b/veilid-core/src/veilid_api/error.rs @@ -107,7 +107,7 @@ macro_rules! apibail_already_initialized { #[derive( ThisError, Clone, Debug, PartialOrd, PartialEq, Eq, Ord, Serialize, Deserialize, JsonSchema, )] -#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(into_wasm_abi))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(into_wasm_abi))] #[serde(tag = "kind")] pub enum VeilidAPIError { #[error("Not initialized")] diff --git a/veilid-core/src/veilid_api/types/aligned_u64.rs b/veilid-core/src/veilid_api/types/aligned_u64.rs index b70a56e3..a84d544d 100644 --- a/veilid-core/src/veilid_api/types/aligned_u64.rs +++ b/veilid-core/src/veilid_api/types/aligned_u64.rs @@ -21,13 +21,13 @@ macro_rules! aligned_u64_type { Deserialize, JsonSchema, )] - #[cfg_attr(target_arch = "wasm32", derive(Tsify))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] #[repr(C, align(8))] #[serde(transparent)] pub struct $name( #[serde(with = "as_human_string")] #[schemars(with = "String")] - #[cfg_attr(target_arch = "wasm32", tsify(type = "string"))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(type = "string"))] u64, ); diff --git a/veilid-core/src/veilid_api/types/app_message_call.rs b/veilid-core/src/veilid_api/types/app_message_call.rs index a3c09bae..80aa2f57 100644 --- a/veilid-core/src/veilid_api/types/app_message_call.rs +++ b/veilid-core/src/veilid_api/types/app_message_call.rs @@ -2,22 +2,22 @@ use super::*; /// Direct statement blob passed to hosting application for processing. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidAppMessage { #[serde(with = "as_human_opt_string")] #[schemars(with = "Option")] - #[cfg_attr(target_arch = "wasm32", tsify(optional, type = "string"))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional, type = "string"))] sender: Option, #[serde(with = "as_human_opt_string")] #[schemars(with = "Option")] - #[cfg_attr(target_arch = "wasm32", tsify(optional, type = "string"))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional, type = "string"))] route_id: Option, - #[cfg_attr(not(target_arch = "wasm32"), serde(with = "as_human_base64"))] + #[cfg_attr(not(all(target_arch = "wasm32", target_os = "unknown")), serde(with = "as_human_base64"))] #[schemars(with = "String")] #[cfg_attr( - target_arch = "wasm32", + all(target_arch = "wasm32", target_os = "unknown"), serde(with = "serde_bytes"), tsify(type = "Uint8Array") )] @@ -51,22 +51,22 @@ impl VeilidAppMessage { /// Direct question blob passed to hosting application for processing to send an eventual AppReply. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidAppCall { #[serde(with = "as_human_opt_string")] #[schemars(with = "Option")] - #[cfg_attr(target_arch = "wasm32", tsify(optional))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))] sender: Option, #[serde(with = "as_human_opt_string")] #[schemars(with = "Option")] - #[cfg_attr(target_arch = "wasm32", tsify(optional, type = "string"))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional, type = "string"))] route_id: Option, - #[cfg_attr(not(target_arch = "wasm32"), serde(with = "as_human_base64"))] + #[cfg_attr(not(all(target_arch = "wasm32", target_os = "unknown")), serde(with = "as_human_base64"))] #[schemars(with = "String")] #[cfg_attr( - target_arch = "wasm32", + all(target_arch = "wasm32", target_os = "unknown"), serde(with = "serde_bytes"), tsify(type = "Uint8Array") )] diff --git a/veilid-core/src/veilid_api/types/dht/dht_record_descriptor.rs b/veilid-core/src/veilid_api/types/dht/dht_record_descriptor.rs index 9d619652..d4422279 100644 --- a/veilid-core/src/veilid_api/types/dht/dht_record_descriptor.rs +++ b/veilid-core/src/veilid_api/types/dht/dht_record_descriptor.rs @@ -3,7 +3,7 @@ use super::*; /// DHT Record Descriptor #[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] #[cfg_attr( - target_arch = "wasm32", + all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(from_wasm_abi, into_wasm_abi) )] @@ -17,7 +17,7 @@ pub struct DHTRecordDescriptor { /// If this key is being created: Some(the secret key of the owner) /// If this key is just being opened: None #[schemars(with = "Option")] - #[cfg_attr(target_arch = "wasm32", tsify(optional))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))] owner_secret: Option, /// The schema in use associated with the key schema: DHTSchema, diff --git a/veilid-core/src/veilid_api/types/dht/dht_record_report.rs b/veilid-core/src/veilid_api/types/dht/dht_record_report.rs index f1fce660..4bf81b99 100644 --- a/veilid-core/src/veilid_api/types/dht/dht_record_report.rs +++ b/veilid-core/src/veilid_api/types/dht/dht_record_report.rs @@ -3,7 +3,7 @@ use super::*; /// DHT Record Report #[derive(Default, Clone, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] #[cfg_attr( - target_arch = "wasm32", + all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(from_wasm_abi, into_wasm_abi) )] @@ -67,7 +67,7 @@ impl fmt::Debug for DHTRecordReport { Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema, )] #[cfg_attr( - target_arch = "wasm32", + all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(from_wasm_abi, into_wasm_abi, namespace) )] diff --git a/veilid-core/src/veilid_api/types/dht/mod.rs b/veilid-core/src/veilid_api/types/dht/mod.rs index 693a1c68..8a55b0ac 100644 --- a/veilid-core/src/veilid_api/types/dht/mod.rs +++ b/veilid-core/src/veilid_api/types/dht/mod.rs @@ -13,10 +13,10 @@ pub use value_data::*; pub use value_subkey_range_set::*; /// Value subkey -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type ValueSubkey = u32; /// Value sequence number -#[cfg_attr(target_arch = "wasm32", declare)] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)] pub type ValueSeqNum = u32; pub(crate) fn debug_seqs(seqs: &[ValueSeqNum]) -> String { diff --git a/veilid-core/src/veilid_api/types/dht/schema/dflt.rs b/veilid-core/src/veilid_api/types/dht/schema/dflt.rs index efb5bce2..9c241e45 100644 --- a/veilid-core/src/veilid_api/types/dht/schema/dflt.rs +++ b/veilid-core/src/veilid_api/types/dht/schema/dflt.rs @@ -3,7 +3,7 @@ use crate::storage_manager::{MAX_RECORD_DATA_SIZE, MAX_SUBKEY_SIZE}; /// Default DHT Schema (DFLT) #[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(from_wasm_abi))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(from_wasm_abi))] pub struct DHTSchemaDFLT { /// Owner subkey count o_cnt: u16, diff --git a/veilid-core/src/veilid_api/types/dht/schema/mod.rs b/veilid-core/src/veilid_api/types/dht/schema/mod.rs index e384e49f..f60397c0 100644 --- a/veilid-core/src/veilid_api/types/dht/schema/mod.rs +++ b/veilid-core/src/veilid_api/types/dht/schema/mod.rs @@ -9,7 +9,11 @@ pub use smpl::*; /// Enum over all the supported DHT Schemas #[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize, JsonSchema)] #[serde(tag = "kind")] -#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(from_wasm_abi))] +#[cfg_attr( + all(target_arch = "wasm32", target_os = "unknown"), + derive(Tsify), + tsify(from_wasm_abi) +)] pub enum DHTSchema { DFLT(DHTSchemaDFLT), SMPL(DHTSchemaSMPL), diff --git a/veilid-core/src/veilid_api/types/dht/schema/smpl.rs b/veilid-core/src/veilid_api/types/dht/schema/smpl.rs index 4bca6422..03d6b96c 100644 --- a/veilid-core/src/veilid_api/types/dht/schema/smpl.rs +++ b/veilid-core/src/veilid_api/types/dht/schema/smpl.rs @@ -3,7 +3,11 @@ use crate::storage_manager::{MAX_RECORD_DATA_SIZE, MAX_SUBKEY_SIZE}; /// Simple DHT Schema (SMPL) Member #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(from_wasm_abi))] +#[cfg_attr( + all(target_arch = "wasm32", target_os = "unknown"), + derive(Tsify), + tsify(from_wasm_abi) +)] pub struct DHTSchemaSMPLMember { /// Member key #[schemars(with = "String")] @@ -14,7 +18,11 @@ pub struct DHTSchemaSMPLMember { /// Simple DHT Schema (SMPL) #[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(from_wasm_abi))] +#[cfg_attr( + all(target_arch = "wasm32", target_os = "unknown"), + derive(Tsify), + tsify(from_wasm_abi) +)] pub struct DHTSchemaSMPL { /// Owner subkey count o_cnt: u16, diff --git a/veilid-core/src/veilid_api/types/dht/value_data.rs b/veilid-core/src/veilid_api/types/dht/value_data.rs index 2e4dca5a..1c8c7975 100644 --- a/veilid-core/src/veilid_api/types/dht/value_data.rs +++ b/veilid-core/src/veilid_api/types/dht/value_data.rs @@ -2,16 +2,16 @@ use super::*; use veilid_api::VeilidAPIResult; #[derive(Clone, Default, PartialOrd, PartialEq, Eq, Ord, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(into_wasm_abi))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(into_wasm_abi))] pub struct ValueData { /// An increasing sequence number to time-order the DHT record changes seq: ValueSeqNum, /// The contents of a DHT Record - #[cfg_attr(not(target_arch = "wasm32"), serde(with = "as_human_base64"))] + #[cfg_attr(not(all(target_arch = "wasm32", target_os = "unknown")), serde(with = "as_human_base64"))] #[schemars(with = "String")] #[cfg_attr( - target_arch = "wasm32", + all(target_arch = "wasm32", target_os = "unknown"), serde(with = "serde_bytes"), tsify(type = "Uint8Array") )] diff --git a/veilid-core/src/veilid_api/types/dht/value_subkey_range_set.rs b/veilid-core/src/veilid_api/types/dht/value_subkey_range_set.rs index 7f3b3150..23458a2c 100644 --- a/veilid-core/src/veilid_api/types/dht/value_subkey_range_set.rs +++ b/veilid-core/src/veilid_api/types/dht/value_subkey_range_set.rs @@ -6,7 +6,7 @@ use range_set_blaze::*; Clone, Default, Hash, PartialOrd, PartialEq, Eq, Ord, Serialize, Deserialize, JsonSchema, )] #[cfg_attr( - target_arch = "wasm32", + all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(from_wasm_abi, into_wasm_abi) )] diff --git a/veilid-core/src/veilid_api/types/safety.rs b/veilid-core/src/veilid_api/types/safety.rs index 5f23f146..39ed7533 100644 --- a/veilid-core/src/veilid_api/types/safety.rs +++ b/veilid-core/src/veilid_api/types/safety.rs @@ -5,7 +5,7 @@ use super::*; Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema, )] #[cfg_attr( - target_arch = "wasm32", + all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(from_wasm_abi, into_wasm_abi, namespace) )] @@ -27,7 +27,7 @@ impl Default for Sequencing { Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema, )] #[cfg_attr( - target_arch = "wasm32", + all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(from_wasm_abi, into_wasm_abi, namespace) )] @@ -48,7 +48,7 @@ impl Default for Stability { Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema, )] #[cfg_attr( - target_arch = "wasm32", + all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(from_wasm_abi, into_wasm_abi, namespace) )] @@ -79,11 +79,11 @@ impl Default for SafetySelection { #[derive( Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema, )] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct SafetySpec { /// Preferred safety route set id if it still exists. #[schemars(with = "Option")] - #[cfg_attr(target_arch = "wasm32", tsify(optional, type = "string"))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional, type = "string"))] pub preferred_route: Option, /// Must be greater than 0. pub hop_count: usize, diff --git a/veilid-core/src/veilid_api/types/stats.rs b/veilid-core/src/veilid_api/types/stats.rs index ca856de4..5ec81501 100644 --- a/veilid-core/src/veilid_api/types/stats.rs +++ b/veilid-core/src/veilid_api/types/stats.rs @@ -2,7 +2,7 @@ use super::*; /// Measurement of communications latency to this node over all RPC questions #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct LatencyStats { /// fastest latency in the ROLLING_LATENCIES_SIZE last latencies pub fastest: TimestampDuration, @@ -25,7 +25,7 @@ impl fmt::Display for LatencyStats { /// Measurement of how much data has transferred to or from this node over a time span #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct TransferStats { /// total amount transferred ever pub total: ByteCount, @@ -50,7 +50,7 @@ impl fmt::Display for TransferStats { /// Transfer statistics from a node to our own (down) and #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct TransferStatsDownUp { pub down: TransferStats, pub up: TransferStats, @@ -66,7 +66,7 @@ impl fmt::Display for TransferStatsDownUp { /// Measurement of what states the node has been in over a time span #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct StateStats { /// total amount of time measured pub span: TimestampDuration, @@ -97,7 +97,7 @@ impl fmt::Display for StateStats { /// Measurement of what state reasons the node has been in over a time span #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct StateReasonStats { /// time spent dead due to being unable to send pub can_not_send: TimestampDuration, @@ -139,7 +139,7 @@ impl fmt::Display for StateReasonStats { /// Measurement of round-trip RPC question/answer performance #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct AnswerStats { /// total amount of time measured pub span: TimestampDuration, @@ -192,7 +192,7 @@ impl fmt::Display for AnswerStats { /// Statistics for RPC operations performed on a node #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct RPCStats { /// number of rpcs that have been sent in the total entry time range pub messages_sent: u32, @@ -263,7 +263,7 @@ impl fmt::Display for RPCStats { /// Statistics for a peer in the routing table #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct PeerStats { /// when the peer was added to the routing table pub time_added: Timestamp, diff --git a/veilid-core/src/veilid_api/types/veilid_log.rs b/veilid-core/src/veilid_api/types/veilid_log.rs index 8b195fc3..6e3744f1 100644 --- a/veilid-core/src/veilid_api/types/veilid_log.rs +++ b/veilid-core/src/veilid_api/types/veilid_log.rs @@ -4,7 +4,7 @@ use super::*; #[derive( Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Copy, Serialize, Deserialize, JsonSchema, )] -#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(namespace))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(namespace))] pub enum VeilidLogLevel { Error = 1, Warn = 2, @@ -81,10 +81,10 @@ impl fmt::Display for VeilidLogLevel { } /// A VeilidCore log message with optional backtrace. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidLog { pub log_level: VeilidLogLevel, pub message: String, - #[cfg_attr(target_arch = "wasm32", tsify(optional))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))] pub backtrace: Option, } diff --git a/veilid-core/src/veilid_api/types/veilid_state.rs b/veilid-core/src/veilid_api/types/veilid_state.rs index 5a9daad3..19d992d6 100644 --- a/veilid-core/src/veilid_api/types/veilid_state.rs +++ b/veilid-core/src/veilid_api/types/veilid_state.rs @@ -3,7 +3,7 @@ use super::*; /// Attachment abstraction for network 'signal strength'. #[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize, JsonSchema)] #[cfg_attr( - target_arch = "wasm32", + all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(namespace, from_wasm_abi, into_wasm_abi) )] @@ -77,7 +77,7 @@ impl TryFrom<&str> for AttachmentState { /// Describe the attachment state of the Veilid node #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidStateAttachment { /// The overall quality of the routing table if attached, or the current state the attachment state machine. pub state: AttachmentState, @@ -94,11 +94,11 @@ pub struct VeilidStateAttachment { /// Describe a recently accessed peer #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct PeerTableData { /// The node ids used by this peer #[schemars(with = "Vec")] - #[cfg_attr(target_arch = "wasm32", tsify(type = "string[]"))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(type = "string[]"))] pub node_ids: Vec, /// The peer's human readable address. pub peer_address: String, @@ -108,7 +108,7 @@ pub struct PeerTableData { /// Describe the current network state of the Veilid node #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidStateNetwork { /// If the network has been started or not. pub started: bool, @@ -123,7 +123,7 @@ pub struct VeilidStateNetwork { /// Describe a private route change that has happened #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidRouteChange { /// If a private route that was allocated has died, it is listed here. #[schemars(with = "Vec")] @@ -138,7 +138,7 @@ pub struct VeilidRouteChange { /// add the ability to change the configuration or have it changed by the Veilid node /// itself during runtime. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidStateConfig { /// If the Veilid node configuration has changed the full new config will be here. pub config: VeilidConfigInner, @@ -146,7 +146,7 @@ pub struct VeilidStateConfig { /// Describe when DHT records have subkey values changed #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidValueChange { /// The DHT Record key that changed #[schemars(with = "String")] @@ -167,7 +167,7 @@ pub struct VeilidValueChange { /// An update from the veilid-core to the host application describing a change /// to the internal state of the Veilid node. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(into_wasm_abi))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(into_wasm_abi))] #[serde(tag = "kind")] pub enum VeilidUpdate { Log(Box), @@ -184,7 +184,7 @@ from_impl_to_jsvalue!(VeilidUpdate); /// A queriable state of the internals of veilid-core. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(into_wasm_abi))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(into_wasm_abi))] pub struct VeilidState { pub attachment: Box, pub network: Box, diff --git a/veilid-core/src/veilid_config.rs b/veilid-core/src/veilid_config.rs index 9eecae67..8677e13f 100644 --- a/veilid-core/src/veilid_config.rs +++ b/veilid-core/src/veilid_config.rs @@ -1,7 +1,7 @@ use crate::*; cfg_if::cfg_if! { - if #[cfg(not(target_arch = "wasm32"))] { + if #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] { use sysinfo::System; use lazy_static::*; use directories::ProjectDirs; @@ -31,12 +31,12 @@ pub type ConfigCallback = Arc ConfigCallbackReturn + Send + Sy /// ``` /// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigHTTPS { pub enabled: bool, pub listen_address: String, pub path: String, - #[cfg_attr(target_arch = "wasm32", tsify(optional))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))] pub url: Option, // Fixed URL is not optional for TLS-based protocols and is dynamically validated } @@ -62,12 +62,12 @@ impl Default for VeilidConfigHTTPS { /// ``` /// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigHTTP { pub enabled: bool, pub listen_address: String, pub path: String, - #[cfg_attr(target_arch = "wasm32", tsify(optional))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))] pub url: Option, } @@ -89,7 +89,7 @@ impl Default for VeilidConfigHTTP { /// To be implemented... /// #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigApplication { pub https: VeilidConfigHTTPS, pub http: VeilidConfigHTTP, @@ -106,19 +106,19 @@ pub struct VeilidConfigApplication { /// ``` /// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigUDP { pub enabled: bool, pub socket_pool_size: u32, pub listen_address: String, - #[cfg_attr(target_arch = "wasm32", tsify(optional))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))] pub public_address: Option, } impl Default for VeilidConfigUDP { fn default() -> Self { cfg_if::cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { let enabled = false; } else { let enabled = true; @@ -144,20 +144,20 @@ impl Default for VeilidConfigUDP { /// public_address: '' /// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigTCP { pub connect: bool, pub listen: bool, pub max_connections: u32, pub listen_address: String, - #[cfg_attr(target_arch = "wasm32", tsify(optional))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))] pub public_address: Option, } impl Default for VeilidConfigTCP { fn default() -> Self { cfg_if::cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { let connect = false; let listen = false; } else { @@ -187,7 +187,7 @@ impl Default for VeilidConfigTCP { /// url: 'ws://localhost:5150/ws' /// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigWS { pub connect: bool, @@ -195,14 +195,14 @@ pub struct VeilidConfigWS { pub max_connections: u32, pub listen_address: String, pub path: String, - #[cfg_attr(target_arch = "wasm32", tsify(optional))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))] pub url: Option, } impl Default for VeilidConfigWS { fn default() -> Self { cfg_if::cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { let connect = true; let listen = false; } else { @@ -233,7 +233,7 @@ impl Default for VeilidConfigWS { /// url: '' /// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigWSS { pub connect: bool, @@ -241,7 +241,7 @@ pub struct VeilidConfigWSS { pub max_connections: u32, pub listen_address: String, pub path: String, - #[cfg_attr(target_arch = "wasm32", tsify(optional))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))] pub url: Option, // Fixed URL is not optional for TLS-based protocols and is dynamically validated } @@ -266,7 +266,7 @@ impl Default for VeilidConfigWSS { /// sort out which protocol is used for each peer connection. /// #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigProtocol { pub udp: VeilidConfigUDP, @@ -284,7 +284,7 @@ pub struct VeilidConfigProtocol { /// connection_initial_timeout_ms: 2000 /// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigTLS { pub certificate_path: String, pub private_key_path: String, @@ -301,7 +301,7 @@ impl Default for VeilidConfigTLS { } } -#[cfg_attr(target_arch = "wasm32", allow(unused_variables))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), allow(unused_variables))] pub fn get_default_ssl_directory( program_name: &str, organization: &str, @@ -309,7 +309,7 @@ pub fn get_default_ssl_directory( sub_path: &str, ) -> String { cfg_if::cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { "".to_owned() } else { use std::path::PathBuf; @@ -327,7 +327,7 @@ pub fn get_default_ssl_directory( /// If you change the count/fanout/timeout parameters, you may render your node inoperable /// for correct DHT operations. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigDHT { pub max_find_node_count: u32, pub resolve_node_timeout_ms: u32, @@ -356,7 +356,7 @@ pub struct VeilidConfigDHT { impl Default for VeilidConfigDHT { fn default() -> Self { cfg_if::cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { let local_subkey_cache_size = 128; let local_max_subkey_cache_memory_mb = 256; let remote_subkey_cache_size = 64; @@ -411,13 +411,13 @@ impl Default for VeilidConfigDHT { /// Configure RPC. /// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigRPC { pub concurrency: u32, pub queue_size: u32, - #[cfg_attr(target_arch = "wasm32", tsify(optional))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))] pub max_timestamp_behind_ms: Option, - #[cfg_attr(target_arch = "wasm32", tsify(optional))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))] pub max_timestamp_ahead_ms: Option, pub timeout_ms: u32, pub max_route_hop_count: u8, @@ -441,7 +441,7 @@ impl Default for VeilidConfigRPC { /// Configure the network routing table. /// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigRoutingTable { #[schemars(with = "Vec")] pub node_id: TypedKeyGroup, @@ -460,7 +460,7 @@ pub struct VeilidConfigRoutingTable { impl Default for VeilidConfigRoutingTable { fn default() -> Self { cfg_if::cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { let bootstrap = vec!["ws://bootstrap.veilid.net:5150/ws".to_string()]; } else { let bootstrap = vec!["bootstrap.veilid.net".to_string()]; @@ -481,7 +481,7 @@ impl Default for VeilidConfigRoutingTable { } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigNetwork { pub connection_initial_timeout_ms: u32, pub connection_inactivity_timeout_ms: u32, @@ -492,7 +492,7 @@ pub struct VeilidConfigNetwork { pub client_allowlist_timeout_ms: u32, pub reverse_connection_receipt_time_ms: u32, pub hole_punch_receipt_time_ms: u32, - #[cfg_attr(target_arch = "wasm32", tsify(optional))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))] pub network_key_password: Option, pub routing_table: VeilidConfigRoutingTable, pub rpc: VeilidConfigRPC, @@ -532,13 +532,13 @@ impl Default for VeilidConfigNetwork { } #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigTableStore { pub directory: String, pub delete: bool, } -#[cfg_attr(target_arch = "wasm32", allow(unused_variables))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), allow(unused_variables))] fn get_default_store_path( program_name: &str, organization: &str, @@ -546,7 +546,7 @@ fn get_default_store_path( store_type: &str, ) -> String { cfg_if::cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { "".to_owned() } else { use std::path::PathBuf; @@ -561,7 +561,7 @@ fn get_default_store_path( } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigBlockStore { pub directory: String, pub delete: bool, @@ -577,14 +577,14 @@ impl Default for VeilidConfigBlockStore { } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigProtectedStore { pub allow_insecure_fallback: bool, pub always_use_insecure_storage: bool, pub directory: String, pub delete: bool, pub device_encryption_key_password: String, - #[cfg_attr(target_arch = "wasm32", tsify(optional))] + #[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))] pub new_device_encryption_key_password: Option, } @@ -602,14 +602,14 @@ impl Default for VeilidConfigProtectedStore { } #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigCapabilities { pub disable: Vec, } #[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] -#[cfg_attr(target_arch = "wasm32", tsify(namespace, from_wasm_abi))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(namespace, from_wasm_abi))] pub enum VeilidConfigLogLevel { Off, Error, @@ -698,7 +698,7 @@ impl fmt::Display for VeilidConfigLogLevel { /// Top level of the Veilid configuration tree #[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidConfigInner { /// An identifier used to describe the program using veilid-core. /// Used to partition storage locations in places like the ProtectedStore. diff --git a/veilid-core/src/wasm_helpers.rs b/veilid-core/src/wasm_helpers.rs index c2f8994b..952d6c87 100644 --- a/veilid-core/src/wasm_helpers.rs +++ b/veilid-core/src/wasm_helpers.rs @@ -1,5 +1,5 @@ cfg_if::cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { pub use tsify::*; pub use wasm_bindgen::prelude::*; diff --git a/veilid-core/tests/web.rs b/veilid-core/tests/web.rs index eb60ea38..c35a08ef 100644 --- a/veilid-core/tests/web.rs +++ b/veilid-core/tests/web.rs @@ -1,5 +1,5 @@ //! Test suite for the Web and headless browsers. -#![cfg(target_arch = "wasm32")] +#![cfg(all(target_arch = "wasm32", target_os = "unknown"))] #![recursion_limit = "256"] use parking_lot::Once; diff --git a/veilid-flutter/rust/Cargo.toml b/veilid-flutter/rust/Cargo.toml index 5e82c89b..e9d2edcf 100644 --- a/veilid-flutter/rust/Cargo.toml +++ b/veilid-flutter/rust/Cargo.toml @@ -50,7 +50,7 @@ tracing-flame = "0.2.0" # Dependencies for native builds only # Linux, Windows, Mac, iOS, Android -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dependencies] tracing-opentelemetry = "0.21" opentelemetry = { version = "0.20" } opentelemetry-otlp = { version = "0.13" } @@ -68,7 +68,7 @@ libc-print = { version = "0.1.23", optional = true } # Dependencies for WASM builds only -[target.'cfg(target_arch = "wasm32")'.dependencies] +[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies] # Dependencies for Android builds only [target.'cfg(target_os = "android")'.dependencies] diff --git a/veilid-tools/Cargo.toml b/veilid-tools/Cargo.toml index 9a91209c..b43a3fa3 100644 --- a/veilid-tools/Cargo.toml +++ b/veilid-tools/Cargo.toml @@ -75,7 +75,7 @@ flume = { version = "0.11.0", features = ["async"] } # Dependencies for native builds only # Linux, Windows, Mac, iOS, Android -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dependencies] async-io = { version = "1.13.0" } async-std = { version = "1.12.0", features = ["unstable"], optional = true } chrono = "0.4.38" @@ -93,7 +93,7 @@ tokio-util = { version = "0.7.11", features = ["compat"], optional = true } tokio-stream = { version = "0.1.15", features = ["net"], optional = true } # Dependencies for WASM builds only -[target.'cfg(target_arch = "wasm32")'.dependencies] +[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies] wasm-bindgen = "0.2.92" js-sys = "0.3.70" wasm-bindgen-futures = "0.4.42" @@ -133,11 +133,11 @@ ifstructs = "0.1.1" ### DEV DEPENDENCIES -[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] +[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dev-dependencies] simplelog = { version = "0.12.2", features = ["test"] } serial_test = "2.0.0" -[target.'cfg(target_arch = "wasm32")'.dev-dependencies] +[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dev-dependencies] serial_test = { version = "2.0.0", default-features = false, features = [ "async", ] } diff --git a/veilid-tools/src/interval.rs b/veilid-tools/src/interval.rs index 2ea5974f..1873bb1e 100644 --- a/veilid-tools/src/interval.rs +++ b/veilid-tools/src/interval.rs @@ -1,7 +1,7 @@ use super::*; cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { pub fn interval(name: &str, freq_ms: u32, callback: F) -> SendPinBoxFuture<()> where diff --git a/veilid-tools/src/lib.rs b/veilid-tools/src/lib.rs index f97b6ea9..5d2d470e 100644 --- a/veilid-tools/src/lib.rs +++ b/veilid-tools/src/lib.rs @@ -42,13 +42,12 @@ pub mod ipc; pub mod must_join_handle; pub mod must_join_single_future; pub mod mutable_future; -#[cfg(not(target_arch = "wasm32"))] pub mod network_interfaces; pub mod network_result; pub mod random; pub mod single_shot_eventual; pub mod sleep; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] pub mod socket_tools; pub mod spawn; pub mod split_url; @@ -59,7 +58,7 @@ pub mod timeout_or; pub mod timestamp; pub mod tools; pub mod virtual_network; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", target_os = "unknown"))] pub mod wasm; pub type PinBox = Pin>; @@ -129,7 +128,7 @@ pub use async_lock::RwLockReadGuard as AsyncRwLockReadGuard; pub use async_lock::RwLockWriteGuard as AsyncRwLockWriteGuard; cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { #[doc(no_inline)] pub use async_lock::Mutex as AsyncMutex; #[doc(no_inline)] @@ -222,7 +221,6 @@ pub use must_join_single_future::*; #[doc(inline)] pub use mutable_future::*; #[doc(inline)] -#[cfg(not(target_arch = "wasm32"))] pub use network_interfaces::*; #[doc(inline)] pub use network_result::*; @@ -233,7 +231,7 @@ pub use single_shot_eventual::*; #[doc(inline)] pub use sleep::*; #[doc(inline)] -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] pub use socket_tools::*; #[doc(inline)] pub use spawn::*; @@ -252,7 +250,7 @@ pub use timestamp::*; #[doc(inline)] pub use tools::*; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", target_os = "unknown"))] pub use wasm::*; // Tests must be public for wasm-pack tests diff --git a/veilid-tools/src/must_join_handle.rs b/veilid-tools/src/must_join_handle.rs index 20128550..0abeb399 100644 --- a/veilid-tools/src/must_join_handle.rs +++ b/veilid-tools/src/must_join_handle.rs @@ -22,7 +22,7 @@ impl MustJoinHandle { self.join_handle = None; } else if #[cfg(feature="rt-tokio")] { self.join_handle = None; - } else if #[cfg(target_arch = "wasm32")] { + } else if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { if let Some(jh) = self.join_handle.take() { jh.detach(); } @@ -48,7 +48,7 @@ impl MustJoinHandle { let _ = jh.await; self.completed = true; } - } else if #[cfg(target_arch = "wasm32")] { + } else if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { drop(self.join_handle.take()); self.completed = true; } else { @@ -94,7 +94,7 @@ impl Future for MustJoinHandle { } } } - } else if #[cfg(target_arch = "wasm32")] { + } else if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { Poll::Ready(t) } else { compile_error!("needs executor implementation"); diff --git a/veilid-tools/src/network_interfaces/mod.rs b/veilid-tools/src/network_interfaces/mod.rs index 759d08d1..e6d27f0c 100644 --- a/veilid-tools/src/network_interfaces/mod.rs +++ b/veilid-tools/src/network_interfaces/mod.rs @@ -19,6 +19,9 @@ cfg_if::cfg_if! { mod openbsd; mod sockaddr_tools; use self::openbsd::PlatformSupportOpenBSD as PlatformSupport; + } else if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { + mod wasm; + use self::wasm::PlatformSupportWasm as PlatformSupport; } else { compile_error!("No network interfaces support for this platform!"); } diff --git a/veilid-tools/src/network_interfaces/wasm.rs b/veilid-tools/src/network_interfaces/wasm.rs new file mode 100644 index 00000000..c2a3ec43 --- /dev/null +++ b/veilid-tools/src/network_interfaces/wasm.rs @@ -0,0 +1,18 @@ +use super::*; +use std::io; + +pub struct PlatformSupportWasm {} + +impl PlatformSupportWasm { + pub fn new() -> Self { + PlatformSupportWasm {} + } + + pub async fn get_interfaces( + &mut self, + interfaces: &mut BTreeMap, + ) -> io::Result<()> { + interfaces.clear(); + Ok(()) + } +} diff --git a/veilid-tools/src/network_result.rs b/veilid-tools/src/network_result.rs index 277e91f3..e1cfdedb 100644 --- a/veilid-tools/src/network_result.rs +++ b/veilid-tools/src/network_result.rs @@ -25,7 +25,7 @@ pub trait IoNetworkResultExt { } fn io_error_kind_from_error(e: io::Error) -> io::Result> { - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] if let Some(os_err) = e.raw_os_error() { if os_err == libc::EHOSTUNREACH || os_err == libc::ENETUNREACH { return Ok(NetworkResult::NoConnection(e)); diff --git a/veilid-tools/src/sleep.rs b/veilid-tools/src/sleep.rs index 31c458c5..5527c24f 100644 --- a/veilid-tools/src/sleep.rs +++ b/veilid-tools/src/sleep.rs @@ -2,7 +2,7 @@ use super::*; use std::time::Duration; cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { use async_executors::{Bindgen, Timer}; pub async fn sleep(millis: u32) { diff --git a/veilid-tools/src/spawn.rs b/veilid-tools/src/spawn.rs index 5cb9fdfb..7105d0b4 100644 --- a/veilid-tools/src/spawn.rs +++ b/veilid-tools/src/spawn.rs @@ -1,7 +1,7 @@ use super::*; cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { use async_executors::{Bindgen, LocalSpawnHandleExt, SpawnHandleExt}; pub fn spawn(_name: &str, future: impl Future + Send + 'static) -> MustJoinHandle diff --git a/veilid-tools/src/tests/common/test_host_interface.rs b/veilid-tools/src/tests/common/test_host_interface.rs index 014af920..aa9d1dba 100644 --- a/veilid-tools/src/tests/common/test_host_interface.rs +++ b/veilid-tools/src/tests/common/test_host_interface.rs @@ -1,7 +1,7 @@ use crate::*; cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { use js_sys::*; } else { use std::time::{Duration, SystemTime}; @@ -293,7 +293,7 @@ pub async fn test_timeout() { pub async fn test_sleep() { info!("testing sleep"); cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { let t1 = Date::now(); sleep(1000).await; @@ -548,7 +548,7 @@ pub async fn test_all() { test_get_random_u64().await; test_get_random_u32().await; test_sleep().await; - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] test_must_join_single_future().await; test_eventual().await; test_eventual_value().await; diff --git a/veilid-tools/src/tests/mod.rs b/veilid-tools/src/tests/mod.rs index e0b727a3..4c6244ea 100644 --- a/veilid-tools/src/tests/mod.rs +++ b/veilid-tools/src/tests/mod.rs @@ -3,7 +3,7 @@ mod android; pub mod common; #[cfg(all(target_os = "ios", feature = "veilid_tools_ios_tests"))] mod ios; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] mod native; #[allow(unused_imports)] diff --git a/veilid-tools/src/tests/native/mod.rs b/veilid-tools/src/tests/native/mod.rs index 28452a85..c45a67e4 100644 --- a/veilid-tools/src/tests/native/mod.rs +++ b/veilid-tools/src/tests/native/mod.rs @@ -1,5 +1,5 @@ //! Test suite for Native -#![cfg(not(target_arch = "wasm32"))] +#![cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] mod test_assembly_buffer; mod test_async_peek_stream; diff --git a/veilid-tools/src/tests/native/test_network_interfaces.rs b/veilid-tools/src/tests/native/test_network_interfaces.rs index 4ba1844b..7cdc0ccc 100644 --- a/veilid-tools/src/tests/native/test_network_interfaces.rs +++ b/veilid-tools/src/tests/native/test_network_interfaces.rs @@ -1,7 +1,7 @@ use crate::*; cfg_if! { - if #[cfg(not(target_arch = "wasm32"))] { + if #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] { use network_interfaces::NetworkInterfaces; pub async fn test_network_interfaces() { @@ -24,6 +24,6 @@ cfg_if! { } pub async fn test_all() { - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] test_network_interfaces().await; } diff --git a/veilid-tools/src/timeout.rs b/veilid-tools/src/timeout.rs index 514bb727..89d35fb5 100644 --- a/veilid-tools/src/timeout.rs +++ b/veilid-tools/src/timeout.rs @@ -1,7 +1,7 @@ use super::*; cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { use futures_util::future::{select, Either}; pub async fn timeout(dur_ms: u32, f: F) -> Result diff --git a/veilid-tools/src/timestamp.rs b/veilid-tools/src/timestamp.rs index 61d978d5..0913a1db 100644 --- a/veilid-tools/src/timestamp.rs +++ b/veilid-tools/src/timestamp.rs @@ -1,7 +1,7 @@ use super::*; cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { use js_sys::Date; pub fn get_timestamp() -> u64 { diff --git a/veilid-tools/src/tools.rs b/veilid-tools/src/tools.rs index 492782b4..29c858d0 100644 --- a/veilid-tools/src/tools.rs +++ b/veilid-tools/src/tools.rs @@ -115,7 +115,7 @@ pub fn system_boxed<'a, Out>( ////////////////////////////////////////////////////////////////////////////////////////////////////////////// cfg_if! { - if #[cfg(not(target_arch = "wasm32"))] { + if #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] { pub fn get_concurrency() -> u32 { std::thread::available_parallelism() .map(|x| x.get()) @@ -259,7 +259,7 @@ pub fn compatible_unspecified_socket_addr(socket_addr: &SocketAddr) -> SocketAdd } cfg_if! { - if #[cfg(not(target_arch = "wasm32"))] { + if #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] { use std::net::UdpSocket; static IPV6_IS_SUPPORTED: Mutex> = Mutex::new(None); @@ -308,7 +308,7 @@ pub fn listen_address_to_socket_addrs(listen_address: &str) -> Result bool { cfg_if! { if #[cfg(debug_assertions)] { cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { let rbenv = get_wasm_global_string_value("RUST_BACKTRACE").unwrap_or_default(); } else diff --git a/veilid-tools/src/virtual_network/router_client.rs b/veilid-tools/src/virtual_network/router_client.rs index f9f51b34..d6691639 100644 --- a/veilid-tools/src/virtual_network/router_client.rs +++ b/veilid-tools/src/virtual_network/router_client.rs @@ -189,7 +189,7 @@ impl RouterClient { ////////////////////////////////////////////////////////////////////////// // Public interface - #[cfg(not(target_arch = "wasm32"))] + #[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))] pub async fn router_connect_tcp(host: H) -> io::Result { let addrs = host.to_socket_addrs()?.collect::>(); @@ -241,11 +241,52 @@ impl RouterClient { )) } - #[cfg(target_arch = "wasm32")] - pub async fn router_connect_ws>(host: H) -> io::Result { - let host = host.as_ref(); + #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] + pub async fn router_connect_ws>(request: R) -> io::Result { + let request = request.as_ref(); - Ok(RouterClient {}) + // Connect to RouterServer + let wsio_reader; + let wsio_writer; + cfg_if! { + if #[cfg(feature="rt-wasm-bindgen")] { + use ws_stream_wasm::*; + let (_wsmeta, wsio) = WsMeta::connect(request, None) + .await.map_err(ws_err_to_io_error)?; + use futures_util::io::AsyncReadExt; + (wsio_reader, wsio_writer) = wsio.into_io().split(); + } else { + compile_error!("must choose an executor"); + } + } + + // Create channels + let (client_sender, server_receiver) = flume::unbounded::(); + + // Create stopper + let stop_source = StopSource::new(); + + // Create router operation waiter + let router_op_waiter = RouterOpWaiter::new(); + + // Spawn a client connection handler + let jh_handler = spawn( + "RouterClient server processor", + Self::run_server_processor( + wsio_reader, + wsio_writer, + server_receiver, + router_op_waiter.clone(), + stop_source.token(), + ), + ); + + Ok(Self::new( + client_sender, + router_op_waiter, + jh_handler, + stop_source, + )) } pub async fn disconnect(self) { diff --git a/veilid-tools/src/wasm.rs b/veilid-tools/src/wasm.rs index 108e4f0c..5d854931 100644 --- a/veilid-tools/src/wasm.rs +++ b/veilid-tools/src/wasm.rs @@ -1,7 +1,9 @@ use super::*; use core::sync::atomic::{AtomicI8, AtomicU32, Ordering}; use js_sys::{global, Reflect}; +use std::io; use wasm_bindgen::prelude::*; +use ws_stream_wasm::WsErr; #[wasm_bindgen] extern "C" { @@ -89,3 +91,26 @@ pub fn get_concurrency() -> u32 { res } + +pub fn ws_err_to_io_error(err: WsErr) -> io::Error { + match err { + WsErr::InvalidWsState { supplied: _ } => { + io::Error::new(io::ErrorKind::InvalidInput, err.to_string()) + } + WsErr::ConnectionNotOpen => io::Error::new(io::ErrorKind::NotConnected, err.to_string()), + WsErr::InvalidUrl { supplied: _ } => { + io::Error::new(io::ErrorKind::InvalidInput, err.to_string()) + } + WsErr::InvalidCloseCode { supplied: _ } => { + io::Error::new(io::ErrorKind::InvalidInput, err.to_string()) + } + WsErr::ReasonStringToLong => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()), + WsErr::ConnectionFailed { event: _ } => { + io::Error::new(io::ErrorKind::ConnectionRefused, err.to_string()) + } + WsErr::InvalidEncoding => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()), + WsErr::CantDecodeBlob => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()), + WsErr::UnknownDataType => io::Error::new(io::ErrorKind::InvalidInput, err.to_string()), + _ => io::Error::new(io::ErrorKind::Other, err.to_string()), + } +} diff --git a/veilid-tools/tests/web.rs b/veilid-tools/tests/web.rs index 96ce61f6..8d4a68ea 100644 --- a/veilid-tools/tests/web.rs +++ b/veilid-tools/tests/web.rs @@ -1,5 +1,5 @@ //! Test suite for the Web and headless browsers. -#![cfg(target_arch = "wasm32")] +#![cfg(all(target_arch = "wasm32", target_os = "unknown"))] use cfg_if::*; use parking_lot::Once; diff --git a/veilid-wasm/src/lib.rs b/veilid-wasm/src/lib.rs index 85d2ffb9..5c83a7a3 100644 --- a/veilid-wasm/src/lib.rs +++ b/veilid-wasm/src/lib.rs @@ -2,7 +2,7 @@ #![deny(clippy::all)] #![allow(clippy::comparison_chain, clippy::upper_case_acronyms)] #![deny(unused_must_use)] -#![cfg(target_arch = "wasm32")] +#![cfg(all(target_arch = "wasm32", target_os = "unknown"))] #![no_std] /// Veilid WASM Bindings for Flutter/Dart, as well as Native Javascript @@ -142,7 +142,7 @@ where // WASM-specific #[derive(Debug, Deserialize, Serialize)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidWASMConfigLoggingPerformance { pub enabled: bool, pub level: veilid_core::VeilidConfigLogLevel, @@ -152,7 +152,7 @@ pub struct VeilidWASMConfigLoggingPerformance { } #[derive(Debug, Deserialize, Serialize)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidWASMConfigLoggingAPI { pub enabled: bool, pub level: veilid_core::VeilidConfigLogLevel, @@ -160,28 +160,35 @@ pub struct VeilidWASMConfigLoggingAPI { } #[derive(Debug, Deserialize, Serialize)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] pub struct VeilidWASMConfigLogging { pub performance: VeilidWASMConfigLoggingPerformance, pub api: VeilidWASMConfigLoggingAPI, } #[derive(Debug, Deserialize, Serialize)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify), tsify(from_wasm_abi))] +#[cfg_attr( + all(target_arch = "wasm32", target_os = "unknown"), + derive(Tsify), + tsify(from_wasm_abi) +)] pub struct VeilidWASMConfig { pub logging: VeilidWASMConfigLogging, } #[derive(Debug, Deserialize, Serialize)] #[cfg_attr( - target_arch = "wasm32", + all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify), tsify(from_wasm_abi, into_wasm_abi) )] pub struct VeilidRouteBlob { pub route_id: veilid_core::RouteId, #[serde(with = "veilid_core::as_human_base64")] - #[cfg_attr(target_arch = "wasm32", tsify(type = "string"))] + #[cfg_attr( + all(target_arch = "wasm32", target_os = "unknown"), + tsify(type = "string") + )] pub blob: Vec, } from_impl_to_jsvalue!(VeilidRouteBlob); @@ -1587,7 +1594,7 @@ pub fn veilid_version_string() -> String { } #[derive(Serialize)] -#[cfg_attr(target_arch = "wasm32", derive(Tsify))] +#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), derive(Tsify))] #[tsify(into_wasm_abi)] pub struct VeilidVersion { pub major: u32, diff --git a/veilid-wasm/src/wasm_helpers.rs b/veilid-wasm/src/wasm_helpers.rs index 6fe034a5..df3e91fa 100644 --- a/veilid-wasm/src/wasm_helpers.rs +++ b/veilid-wasm/src/wasm_helpers.rs @@ -1,7 +1,7 @@ use super::*; cfg_if::cfg_if! { - if #[cfg(target_arch = "wasm32")] { + if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { pub use wasm_bindgen::prelude::*; macro_rules! from_impl_to_jsvalue {