supranational / blst

Multilingual BLS12-381 signature library
Apache License 2.0
454 stars 171 forks source link

Error building blst Wasm in Rust #188

Closed MarvinQuevedo closed 10 months ago

MarvinQuevedo commented 10 months ago

Hi, I have a library that I need to build in wasm, but when I try to build, they use your library, exist a possibility of give support for It? o I am doing some bad?

wasm-pack build --target web [INFO]: šŸŽÆ Checking for the Wasm target... info: downloading component 'rust-std' for 'wasm32-unknown-unknown' info: retrying download for 'https://static.rust-lang.org/dist/2023-08-28/rust-std-nightly-wasm32-unknown-unknown.tar.xz' 17.5 MiB / 17.5 MiB (100 %) 2.8 MiB/s in 7s ETA: 0s info: installing component 'rust-std' for 'wasm32-unknown-unknown' 17.5 MiB / 17.5 MiB (100 %) 5.8 MiB/s in 3s ETA: 0s [INFO]: šŸŒ€ Compiling to Wasm... Blocking waiting for file lock on package cache Blocking waiting for file lock on package cache Blocking waiting for file lock on build directory Compiling cfg-if v1.0.0 Compiling wasm-bindgen-shared v0.2.87 Compiling bumpalo v3.13.0 Compiling serde v1.0.188 Compiling log v0.4.20 Compiling ryu v1.0.15 Compiling serde_json v1.0.105 Compiling zeroize v1.6.0 Compiling itoa v1.0.9 Compiling wasm-bindgen v0.2.87 Compiling typenum v1.16.0 Compiling generic-array v0.14.7 Compiling subtle v2.4.1 Compiling const-oid v0.9.5 Compiling radium v0.7.0 Compiling num-traits v0.2.15 Compiling tap v1.0.1 Compiling wyz v0.5.1 Compiling funty v2.0.0 Compiling wasm-bindgen-backend v0.2.87 Compiling base64ct v1.6.0 Compiling pem-rfc7468 v0.7.0 Compiling num-integer v0.1.45 Compiling bitvec v1.0.1 Compiling wasm-bindgen-macro-support v0.2.87 Compiling der v0.7.8 Compiling block-buffer v0.10.4 Compiling crypto-common v0.1.6 Compiling digest v0.10.7 Compiling base16ct v0.2.0 Compiling hmac v0.12.1 Compiling num-bigint v0.4.3 Compiling scopeguard v1.2.0 Compiling sha2 v0.10.2 Compiling digest v0.9.0 Compiling libc v0.2.147 Compiling once_cell v1.18.0 Compiling crossbeam-utils v0.8.16 Compiling wasm-bindgen-macro v0.2.87 Compiling rfc6979 v0.4.0 Compiling lazy_static v1.4.0 Compiling spki v0.7.2 Compiling memoffset v0.9.0 Compiling pkcs8 v0.10.2 Compiling block-buffer v0.9.0 Compiling hex v0.4.3 Compiling opaque-debug v0.3.0 Compiling sha2 v0.9.9 Compiling crossbeam-epoch v0.9.15 Compiling sec1 v0.7.3 Compiling thiserror v1.0.47 Compiling num_cpus v1.16.0 Compiling simd-adler32 v0.3.7 Compiling lock_api v0.4.10 Compiling crossbeam-deque v0.8.3 Compiling crossbeam-channel v0.5.8 Compiling rayon-core v1.11.0 Compiling adler v1.0.2 Compiling crc32fast v1.3.2 Compiling miniz_oxide v0.7.1 Compiling num-rational v0.4.1 Compiling smallvec v1.11.0 Compiling futures-core v0.3.28 Compiling anyhow v1.0.75 Compiling js-sys v0.3.64 Compiling num-iter v0.1.43 Compiling proc-macro2 v1.0.66 Compiling either v1.9.0 Compiling unicode-ident v1.0.11 Compiling memchr v2.6.1 Compiling ppv-lite86 v0.2.17 Compiling equivalent v1.0.1 Compiling byteorder v1.4.3 Compiling hashbrown v0.14.0 Compiling tinyvec_macros v0.1.1 Compiling tinyvec v1.6.0 Compiling aho-corasick v1.0.5 Compiling parking_lot_core v0.9.8 Compiling rayon v1.7.0 Compiling indexmap v2.0.0 Compiling pin-project v1.1.3 Compiling blst v0.3.11 Compiling flate2 v1.0.27 The following warnings were emitted during compilation:

warning: error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"' warning: 1 error generated.

error: failed to run custom build command for blst v0.3.11

Caused by: process didn't exit successfully: /Users/marvin/Projects2/flutter_chia_rust_utils/chia_rust_utils/target/release/build/blst-9572946ca1f3eb4d/build-script-build (exit status: 1) --- stdout cargo:rerun-if-env-changed=BLST_TEST_NO_STD Using blst source directory /Users/marvin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/blst-0.3.11/blst cargo:rerun-if-changed=/Users/marvin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/blst-0.3.11/blst/src TARGET = Some("wasm32-unknown-unknown") HOST = Some("aarch64-apple-darwin") cargo:rerun-if-env-changed=CC_wasm32-unknown-unknown CC_wasm32-unknown-unknown = None cargo:rerun-if-env-changed=CC_wasm32_unknown_unknown CC_wasm32_unknown_unknown = None cargo:rerun-if-env-changed=TARGET_CC TARGET_CC = None cargo:rerun-if-env-changed=CC CC = None cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS CRATE_CC_NO_DEFAULTS = None DEBUG = Some("false") cargo:rerun-if-env-changed=CFLAGS_wasm32-unknown-unknown CFLAGS_wasm32-unknown-unknown = None cargo:rerun-if-env-changed=CFLAGS_wasm32_unknown_unknown CFLAGS_wasm32_unknown_unknown = None cargo:rerun-if-env-changed=TARGET_CFLAGS TARGET_CFLAGS = None cargo:rerun-if-env-changed=CFLAGS CFLAGS = None cargo:rerun-if-env-changed=CC_wasm32-unknown-unknown CC_wasm32-unknown-unknown = None cargo:rerun-if-env-changed=CC_wasm32_unknown_unknown CC_wasm32_unknown_unknown = None cargo:rerun-if-env-changed=TARGET_CC TARGET_CC = None cargo:rerun-if-env-changed=CC CC = None cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS CRATE_CC_NO_DEFAULTS = None cargo:rerun-if-env-changed=CFLAGS_wasm32-unknown-unknown CFLAGS_wasm32-unknown-unknown = None cargo:rerun-if-env-changed=CFLAGS_wasm32_unknown_unknown CFLAGS_wasm32_unknown_unknown = None cargo:rerun-if-env-changed=TARGET_CFLAGS TARGET_CFLAGS = None cargo:rerun-if-env-changed=CFLAGS CFLAGS = None cargo:rerun-if-env-changed=CC_wasm32-unknown-unknown CC_wasm32-unknown-unknown = None cargo:rerun-if-env-changed=CC_wasm32_unknown_unknown CC_wasm32_unknown_unknown = None cargo:rerun-if-env-changed=TARGET_CC TARGET_CC = None cargo:rerun-if-env-changed=CC CC = None cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS CRATE_CC_NO_DEFAULTS = None cargo:rerun-if-env-changed=CFLAGS_wasm32-unknown-unknown CFLAGS_wasm32-unknown-unknown = None cargo:rerun-if-env-changed=CFLAGS_wasm32_unknown_unknown CFLAGS_wasm32_unknown_unknown = None cargo:rerun-if-env-changed=TARGET_CFLAGS TARGET_CFLAGS = None cargo:rerun-if-env-changed=CFLAGS CFLAGS = None cargo:rerun-if-env-changed=CC_wasm32-unknown-unknown CC_wasm32-unknown-unknown = None cargo:rerun-if-env-changed=CC_wasm32_unknown_unknown CC_wasm32_unknown_unknown = None cargo:rerun-if-env-changed=TARGET_CC TARGET_CC = None cargo:rerun-if-env-changed=CC CC = None cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS CRATE_CC_NO_DEFAULTS = None cargo:rerun-if-env-changed=CFLAGS_wasm32-unknown-unknown CFLAGS_wasm32-unknown-unknown = None cargo:rerun-if-env-changed=CFLAGS_wasm32_unknown_unknown CFLAGS_wasm32_unknown_unknown = None cargo:rerun-if-env-changed=TARGET_CFLAGS TARGET_CFLAGS = None cargo:rerun-if-env-changed=CFLAGS CFLAGS = None cargo:rerun-if-env-changed=CC_wasm32-unknown-unknown CC_wasm32-unknown-unknown = None cargo:rerun-if-env-changed=CC_wasm32_unknown_unknown CC_wasm32_unknown_unknown = None cargo:rerun-if-env-changed=TARGET_CC TARGET_CC = None cargo:rerun-if-env-changed=CC CC = None cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS CRATE_CC_NO_DEFAULTS = None cargo:rerun-if-env-changed=CFLAGS_wasm32-unknown-unknown CFLAGS_wasm32-unknown-unknown = None cargo:rerun-if-env-changed=CFLAGS_wasm32_unknown_unknown CFLAGS_wasm32_unknown_unknown = None cargo:rerun-if-env-changed=TARGET_CFLAGS TARGET_CFLAGS = None cargo:rerun-if-env-changed=CFLAGS CFLAGS = None running: "clang" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-Wall" "-Wextra" "-ffreestanding" "-DBLST_NO_ASM" "-DSCRATCH_LIMIT=(45 * 1024)" "-o" "/Users/marvin/Projects2/flutter_chia_rust_utils/chia_rust_utils/target/wasm32-unknown-unknown/release/build/blst-c52b2f4dfb687635/out/619b7de3c0f78f5f-server.o" "-c" "/Users/marvin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/blst-0.3.11/blst/src/server.c" cargo:warning=error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-unknown"'

cargo:warning=1 error generated.

exit status: 1

--- stderr

error occurred: Command "clang" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "--target=wasm32-unknown-unknown" "-Wall" "-Wextra" "-ffreestanding" "-DBLST_NO_ASM" "-DSCRATCH_LIMIT=(45 * 1024)" "-o" "/Users/marvin/Projects2/flutter_chia_rust_utils/chia_rust_utils/target/wasm32-unknown-unknown/release/build/blst-c52b2f4dfb687635/out/619b7de3c0f78f5f-server.o" "-c" "/Users/marvin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/blst-0.3.11/blst/src/server.c" with args "clang" did not execute successfully (status code exit status: 1).

warning: build failed, waiting for other jobs to finish... Error: Compiling your crate to WebAssembly failed Caused by: Compiling your crate to WebAssembly failed Caused by: failed to execute cargo build: exited with exit status: 101 full command: cd "/Users/marvin/Projects2/flutter_chia_rust_utils/chia_rust_utils" && "cargo" "build" "--lib" "--release" "--target" "wasm32-unknown-unknown"

dot-asm commented 10 months ago

Quoting rust/README.md: "To compile for WebAssembly, your clang has to recognize --target=wasm32. ..." The error message suggests that yours doesn't. The error message also gives a vibe that you're running on MacOS, and it's known that MacOS default compiler doesn't support wasm. Either way, it looks like you need to get one that does. Emscripten should work (consult README.md), but if it doesn't and you in fact are running on MacOS, then I personally don't know what are the other options out there. But I know that you can quickly check any particular compiler with clang --target=wasm32 -c -xc /dev/null...

MarvinQuevedo commented 10 months ago

Thanks!, I just compile in linux using a docker image :)