Skip to content

Commit be19440

Browse files
committed
make 'spacetime publish' work
otherwise: error[E0432]: unresolved import `crate::sys::IoSourceState` --> /home/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/mio-1.0.3/src/io_source.rs:14:5 | 14 | use crate::sys::IoSourceState; | ^^^^^^^^^^^^^^^^^^^^^^^^^ no `IoSourceState` in `sys` tokio-rs/mio#1850 tokio-rs/mio#1681 tokio-rs/mio#1856 and something like this when openssl is also included: DEBUG: CMAKECONFIGDIR = /home/user/SOURCE/my/quickstart-chat/server/target/wasm32-unknown-unknown/release/build/openssl-sys-756c4c8b4d61ba02/out/openssl-build/install/lib/cmake/OpenSSL => CMAKECONFIGDIR = /home/user/SOURCE/my/quickstart-chat/server/target/wasm32-unknown-unknown/release/build/openssl-sys-756c4c8b4d61ba02/out/openssl-build/install/lib/cmake/OpenSSL, CMAKECONFIGDIR_REL_LIBDIR = cmake/OpenSSL In file included from apps/lib/app_provider.c:10: In file included from apps/include/apps.h:13: include/internal/common.h:14:11: fatal error: 'stdlib.h' file not found 14 | # include <stdlib.h> | ^~~~~~~~~~ In file included from apps/lib/app_libctx.c:9: In file included from apps/include/app_libctx.h:13: In file included from include/openssl/types.h:32: include/openssl/e_os2.h:203:12: fatal error: 'sys/types.h' file not found 203 | # include <sys/types.h> | ^~~~~~~~~~~~~ apps/lib/app_x509.cIn file included from :apps/lib/app_params.c10::1010: :In file included from apps/include/apps.hfatal error: :'string.h' file not found13 : include/internal/common.h:14:11 :10 | fatal error: #'stdlib.h' file not foundi nclude 14< | s#t riinncgl.uhd>e <| s ^~~~~~~~~~t dlib.h> | ^~~~~~~~~~ In file included from apps/lib/app_rand.c:10: In file included from include/internal/e_os.h:16: include/openssl/e_os2.h:203:12: fatal error: 'sys/types.h' file not found 203 | # include <sys/types.h> | ^~~~~~~~~~~~~ In file included from apps/lib/apps.c:21: In file included from include/openssl/engine.h:24: In file included from include/openssl/bn.h:20: include/openssl/e_os2.h:203:12: fatal error: 'sys/types.h' file not found 203 | # include <sys/types.h> | ^~~~~~~~~~~~~ 1 error generated. make[1]: *** [Makefile:4000: apps/lib/libapps-lib-app_libctx.o] Error 1 make[1]: *** Waiting for unfinished jobs.... 1 error generated. 1 error generated. 1 error generated. make[1]: *** [Makefile:4024: apps/lib/libapps-lib-app_rand.o] Error 1 1 error generated. make[1]: *** [Makefile:4016: apps/lib/libapps-lib-app_provider.o] Error 1 make[1]: *** [Makefile:4008: apps/lib/libapps-lib-app_params.o] Error 1 make[1]: *** [Makefile:4032: apps/lib/libapps-lib-app_x509.o] Error 1 1 error generated. make[1]: *** [Makefile:4040: apps/lib/libapps-lib-apps.o] Error 1 make: *** [Makefile:2459: build_libs] Error 2 Error building OpenSSL: 'make' reported failure with exit status: 2 Command failed: cd "/home/user/SOURCE/my/quickstart-chat/server/target/wasm32-unknown-unknown/release/build/openssl-sys-756c4c8b4d61ba02/out/openssl-build/build/src" && MAKEFLAGS="-j --jobserver-fds=8,9 --jobserver-auth=8,9" "make" "build_libs" Error: command ["cargo", "build", "--config=net.git-fetch-with-cli=true", "--target=wasm32-unknown-unknown", "--release", "--message-format=json-render-diagnostics"] exited with code 101
1 parent 57a879b commit be19440

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

crates/lib/Cargo.toml

+7-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,18 @@ serde = { workspace = true, optional = true }
4242
thiserror.workspace = true
4343
blake3.workspace = true
4444
enum-map = { workspace = true, optional = true }
45-
tokio.workspace = true
45+
46+
#XXX: can't bring openssl or mio into this lib due to "publish" failing to compile them in wasm!
47+
#eg. hyper,reqwest,native-tls,tokio all bring either of them.
48+
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
49+
#tokio = { version= "1.44", default-features = false, features = ["rt", "sync", "time"] }
50+
tokio.workspace = true #this "full" tokio causes 'mio' to fail to wasm compile see: https://github.com/tokio-rs/mio/pull/1856
4651
#native-tls = "0.2"
4752
native-tls.workspace=true
48-
clap.workspace = true
4953
hyper.workspace=true
5054
reqwest.workspace=true
5155
openssl.workspace=true
56+
clap.workspace = true
5257

5358
# For the 'proptest' feature.
5459
proptest = { workspace = true, optional = true }

crates/lib/src/lib.rs

+23
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,23 @@ use spacetimedb_sats::{impl_serialize, WithTypespace};
66
use std::any::TypeId;
77
use std::collections::{btree_map, BTreeMap};
88

9+
10+
macro_rules! non_wasm {
11+
($($item:item)*) => {
12+
$(
13+
#[cfg(not(target_arch = "wasm32"))]
14+
$item
15+
)*
16+
};
17+
}
18+
19+
20+
//XXX: we avoid anything 'mio' or 'openssl' which will fail to compile in wasm32; this this lib is
21+
//used on both wasm32 during 'spacetime publish' compilation and non-wasm32 ie. x86_64
22+
//#[cfg(not(target_arch = "wasm32"))]
23+
non_wasm! {
924
use tokio::io::AsyncReadExt;
25+
}
1026

1127

1228
pub mod connection_id;
@@ -390,6 +406,8 @@ pub fn resolved_type_via_v9<T: SpacetimeType>() -> AlgebraicType {
390406
.expect("recursive types not supported")
391407
}
392408

409+
//#[cfg(not(target_arch = "wasm32"))]
410+
non_wasm! {
393411
pub async fn load_root_cert(cert_path: Option<&std::path::Path>) -> anyhow::Result<Option<native_tls::Certificate>> {
394412
if let Some(path) = cert_path {
395413
// Open file asynchronously
@@ -596,6 +614,7 @@ pub fn client_no_trust_system_root_store() -> clap::Arg {
596614
/// Asynchronously reads a file with a maximum size limit of 1 MiB.
597615
/// Files of 1 MiB or larger will fail; files under 1 MiB are allowed.
598616
/// This should avoid unresponsive system(DOS-ing) until OOM kicks in if you do /dev/zero as the path.
617+
//#[cfg(not(target_arch = "wasm32"))]
599618
pub async fn read_file_limited(path: &std::path::Path) -> anyhow::Result<Vec<u8>> {
600619
// if file is >= to this, fails!
601620
const MAX_SIZE: u64 = 1_048_576; // 1 MiB
@@ -839,6 +858,7 @@ Error: Failed sending request to https://127.0.0.1:3000: Server closed the conne
839858
)
840859
841860
*/
861+
//#[cfg(not(target_arch = "wasm32"))]
842862
pub fn map_request_error<E: Into<anyhow::Error>>(
843863
e: E,
844864
url: &String,
@@ -991,3 +1011,6 @@ macro_rules! map_request_error {
9911011
))
9921012
};
9931013
}
1014+
1015+
1016+
} // end of non_wasm! macro call

0 commit comments

Comments
 (0)