-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't build for wasm target #827
Comments
I think the only wasm target we currently support is wasm32-wasi, although I could be mistaken. @gwenn or @TjeuKayim (who added support for wasm32-wasi) might know. |
Compiling Rust that depends on C stdlib to WebAssembly is not possible with |
I have the same pb with |
Try to install wasi-sdk and set linker environment variables as explained at https://doc.rust-lang.org/nightly/nightly-rustc/rustc_target/spec/wasm32_wasi/index.html. Enable these feature in [dependencies.rusqlite]
features = ["bundled", "wasm32-wasi-vfs"] This is an example for Ubuntu to compile a project depending on rusqlite to WebAssembly: sudo apt install libtinfo5
wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-11/wasi-sdk_11.0_amd64_ubuntu20.04.deb
sudo dpkg -i wasi-sdk_11.0_amd64_ubuntu20.04.deb
rm wasi-sdk_11.0_amd64_ubuntu20.04.deb
export CC_wasm32_wasi=/opt/wasi-sdk/bin/clang
export CARGO_TARGET_WASM32_WASI_LINKER=/opt/wasi-sdk/bin/clang
RUSTFLAGS="-C target-feature=-crt-static" cargo build --lib --target "wasm32-wasi" |
Thanks. I downloaded the sdk and set the env variables but it still complains about not finding clang... ok, this and Emscripten seem a bit complicated for what I had in mind, so I'm out, until/if it becomes "easy". |
Thanks too ! now I can finish the compilation.
|
The error |
with v1.49.0-nightly :
with v1.45.2
|
I'd recommend to use Rust v1.45.2 until the regression is fixed. Currently, it is a hassle to compile rusqlite to WebAssembly, but it is doable. I've created two web applications with it, and they ran faster than I expected. SQLite is not really optimized for binary size though, so the WASM file is around 2MB. |
Thx, the compilation works for me with Rust v1.45.2. |
Nice, you got it compiled. Importing/exporting functions between Rust and JS is possible with WASI, just like the |
I want to test rusqlite with nodejs by passing a filename to rust. |
Hi! I've also managed to compile the
Any thoughts on this? |
What runtime did you use? The |
Actually I guess the |
Try this tutorial to run your app in a browser: https://docs.wasmer.io/integrations/js/wasi/browser/examples/hello-world |
Thanks! Do you think I need to use |
No, you don't need |
Just to make sure I understand it correctly. It sounds like I can't use the Also manually writing the glue code seems a lot of work. It'd be great we have some examples. |
@TjeuKayim After setting the wasi-sdk configuration, it still prompts that stdio.h file cannot be found |
Hi @passchaos , Can you provide some more details? Like what features you use in |
|
That seems fine. Are you using a similar |
@passchaos Also make sure you used |
@TjeuKayim @sefeng211 I tried to use different versions of wasi-sdk, but it did't work in the way mentioned above. |
So, did you succeed in compiling rusqlite with hard coding the wasi-sdk path in |
Yes, but just set the header file path |
Hey, what's the update on this? I'd like to push to get this done as it would help out on a project to have WASM bindings for sqlite. I'd be happy to help in any way |
I'm also struggling with this one. I either get the OP's error "rust-lld: error: unable to find library -lsqlite3" when building my crate, or if I enabled the "bundled" feature, or try to build rusqlite directly using
This is a bit weird, since I only see warnings, and I don't see the |
For a more specific way to replicate this, I tried to build |
the `holo_hash` crate depends on `rusqlite` which cannot build on wasm: rusqlite/rusqlite#827 therefore I cannot create an `AgentPubKey` and thus cannot initiate a call. I wonder if I can rip the types out and rely on Serde deriving things identically for identical structs... (while waiting for an actual, long-term-viable fix).
I get a different error when trying to build on Fedora 35. If I just run (Cargo.toml) rusqlite = {version = "0.26.3", features=["bundled-full", "wasm32-wasi-vfs"]}
However if I follow the instructions above for Fedora (slightly modified) # Install wasi-sdk 12 to local directory
$ export WASI_VERSION=12
$ export WASI_VERSION_FULL=${WASI_VERSION}.0
$ wget "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VERSION}/wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz"
$ tar xvf wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz Trying to compile with the instructions above export CC_wasm32_wasi=`pwd`/wasi-sdk-12.0/bin/clang
export CARGO_TARGET_WASM32_WASI_LINKER=`pwd`/wasi-sdk-12.0/bin/clang
RUSTFLAGS="-C target-feature=-crt-static" cargo build --lib --target "wasm32-wasi" Gives me the exact same error However if I use the export WASI_SDK_PATH=`pwd`/wasi-sdk-12.0
CC="${WASI_SDK_PATH}/bin/clang --sysroot=${WASI_SDK_PATH}/share/wasi-sysroot"
export CC_wasm32_wasi=${CC}
export CARGO_TARGET_WASM32_WASI_LINKER=${CC}
RUSTFLAGS="-C target-feature=-crt-static" cargo build --lib --target "wasm32-wasi"
warning: sqlite3/sqlite3.c:27213:10: fatal error: 'pthread.h' file not found
warning: #include <pthread.h>
warning: ^~~~~~~~~~~
warning: 1 error generated.
error: failed to run custom build command for `libsqlite3-sys v0.23.2`
Caused by:
process didn't exit successfully: `/home/geewee/programming/edge-api/target/debug/build/libsqlite3-sys-b798e717760d70e2/build-script-build` (exit status: 1)
--- stdout
cargo:rerun-if-changed=sqlite3/sqlite3.c
cargo:rerun-if-changed=sqlite3/wasm32-wasi-vfs.c
cargo:rerun-if-env-changed=SQLITE_MAX_VARIABLE_NUMBER
cargo:rerun-if-env-changed=SQLITE_MAX_EXPR_DEPTH
cargo:rerun-if-env-changed=LIBSQLITE3_FLAGS
TARGET = Some("wasm32-wasi")
OPT_LEVEL = Some("0")
HOST = Some("x86_64-unknown-linux-gnu")
CC_wasm32-wasi = None
CC_wasm32_wasi = Some("/home/geewee/programming/edge-api/edge-api/wasi-sdk-12.0/bin/clang --sysroot=/home/geewee/programming/edge-api/edge-api/wasi-sdk-12.0/share/wasi-sysroot")
CFLAGS_wasm32-wasi = None
CFLAGS_wasm32_wasi = None
TARGET_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("true")
running: "/home/geewee/programming/edge-api/edge-api/wasi-sdk-12.0/bin/clang" "--sysroot=/home/geewee/programming/edge-api/edge-api/wasi-sdk-12.0/share/wasi-sysroot" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-wasi" "-DSQLITE_CORE" "-DSQLITE_DEFAULT_FOREIGN_KEYS=1" "-DSQLITE_ENABLE_API_ARMOR" "-DSQLITE_ENABLE_COLUMN_METADATA" "-DSQLITE_ENABLE_DBSTAT_VTAB" "-DSQLITE_ENABLE_FTS3" "-DSQLITE_ENABLE_FTS3_PARENTHESIS" "-DSQLITE_ENABLE_FTS5" "-DSQLITE_ENABLE_JSON1" "-DSQLITE_ENABLE_LOAD_EXTENSION=1" "-DSQLITE_ENABLE_MEMORY_MANAGEMENT" "-DSQLITE_ENABLE_RTREE" "-DSQLITE_ENABLE_STAT2" "-DSQLITE_ENABLE_STAT4" "-DSQLITE_SOUNDEX" "-DSQLITE_THREADSAFE=1" "-DSQLITE_USE_URI" "-DHAVE_USLEEP=1" "-D_POSIX_THREAD_SAFE_FUNCTIONS" "-DHAVE_ISNAN" "-DHAVE_LOCALTIME_R" "-DSQLITE_ENABLE_UNLOCK_NOTIFY" "-o" "/home/geewee/programming/edge-api/target/wasm32-wasi/debug/build/libsqlite3-sys-a108609a6c19d418/out/sqlite3/sqlite3.o" "-c" "sqlite3/sqlite3.c"
cargo:warning=sqlite3/sqlite3.c:27213:10: fatal error: 'pthread.h' file not found
cargo:warning=#include <pthread.h>
cargo:warning= ^~~~~~~~~~~
cargo:warning=1 error generated.
exit status: 1
--- stderr
error occurred: Command "/home/geewee/programming/edge-api/edge-api/wasi-sdk-12.0/bin/clang" "--sysroot=/home/geewee/programming/edge-api/edge-api/wasi-sdk-12.0/share/wasi-sysroot" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "--target=wasm32-wasi" "-DSQLITE_CORE" "-DSQLITE_DEFAULT_FOREIGN_KEYS=1" "-DSQLITE_ENABLE_API_ARMOR" "-DSQLITE_ENABLE_COLUMN_METADATA" "-DSQLITE_ENABLE_DBSTAT_VTAB" "-DSQLITE_ENABLE_FTS3" "-DSQLITE_ENABLE_FTS3_PARENTHESIS" "-DSQLITE_ENABLE_FTS5" "-DSQLITE_ENABLE_JSON1" "-DSQLITE_ENABLE_LOAD_EXTENSION=1" "-DSQLITE_ENABLE_MEMORY_MANAGEMENT" "-DSQLITE_ENABLE_RTREE" "-DSQLITE_ENABLE_STAT2" "-DSQLITE_ENABLE_STAT4" "-DSQLITE_SOUNDEX" "-DSQLITE_THREADSAFE=1" "-DSQLITE_USE_URI" "-DHAVE_USLEEP=1" "-D_POSIX_THREAD_SAFE_FUNCTIONS" "-DHAVE_ISNAN" "-DHAVE_LOCALTIME_R" "-DSQLITE_ENABLE_UNLOCK_NOTIFY" "-o" "/home/geewee/programming/edge-api/target/wasm32-wasi/debug/build/libsqlite3-sys-a108609a6c19d418/out/sqlite3/sqlite3.o" "-c" "sqlite3/sqlite3.c" with args "clang" did not execute successfully (status code exit status: 1). I have tried with These issues seem relevant Did anyone stumble into something similar? |
@GeeWee I got the same error. (M1 Mac, tried I started trying to compile the This is the command I was running: ${WASI_SDK_PATH}/bin/clang \
--sysroot=${WASI_SDK_PATH}/share/wasi-sysroot \
-O0 \
-ffunction-sections \
-fdata-sections \
-fPIC \
-g \
-fno-omit-frame-pointer \
--target=wasm32-wasi \
-DSQLITE_CORE \
-D_WASI_EMULATED_MMAN \
-DSQLITE_MAX_MMAP_SIZE=0 \
-DSQLITE_DEFAULT_FOREIGN_KEYS=1 \
-DSQLITE_ENABLE_API_ARMOR \
-DSQLITE_ENABLE_COLUMN_METADATA \
-DSQLITE_ENABLE_DBSTAT_VTAB \
-DSQLITE_ENABLE_FTS3 \
-DSQLITE_ENABLE_FTS3_PARENTHESIS \
-DSQLITE_ENABLE_FTS5 \
-DSQLITE_ENABLE_JSON1 \
-DSQLITE_ENABLE_LOAD_EXTENSION=1 \
-DSQLITE_ENABLE_MEMORY_MANAGEMENT \
-DSQLITE_ENABLE_RTREE \
-DSQLITE_ENABLE_STAT2 \
-DSQLITE_ENABLE_STAT4 \
-DSQLITE_SOUNDEX \
-DSQLITE_THREADSAFE=0 \
-DSQLITE_USE_URI \
-DHAVE_USLEEP=1 \
-D_POSIX_THREAD_SAFE_FUNCTIONS \
-DHAVE_ISNAN \
-DHAVE_LOCALTIME_R \
-o \
$(pwd)/sqlite3.o \
-c sqlite-amalgamation-3370200/sqlite3.c (I included the I'll report back if I manage to fix something. |
Managed to work ! With
> env CC_wasm32_wasi="/wasi-sdk-14.0/bin/clang" CARGO_TARGET_WASM32_WASI_LINKER=/wasi-sdk-14.0/bin/clang RUSTFLAGS="-C target-feature=-crt-static" cargo build --lib --target wasm32-wasi --features bundled,wasm32-wasi-vfs --release
Compiling vcpkg v0.2.15
Compiling cc v1.0.72
Compiling pkg-config v0.3.24
Compiling libsqlite3-sys v0.23.2 (/rusqlite/libsqlite3-sys)
Finished release [optimized] target(s) in 1m 13s just compile, no test ;-) |
Yeah, with the changes in #1116 it works (I'm the author of that PR). I tried building a wasm32-wasi executable with bundled SQLite, and it worked when running it with wasmtime. (just copied the example in the README, nothing fancy). I also had to set up the #!/usr/bin/env bash
# set WASI_SDK_PATH to the correct location in your system
export WASI_SYSROOT="${WASI_SDK_PATH}/share/wasi-sysroot"
export CC="${WASI_SDK_PATH}/bin/clang --sysroot=${WASI_SYSROOT}"
export AR="${WASI_SDK_PATH}/bin/llvm-ar"
export CC_wasm32_wasi="${CC}"
export CARGO_TARGET_WASM32_WASI_LINKER="${WASI_SDK_PATH}/bin/clang"
export LIBSQLITE3_FLAGS="\
-DSQLITE_OS_OTHER \
-USQLITE_TEMP_STORE \
-DSQLITE_TEMP_STORE=3 \
-USQLITE_THREADSAFE \
-DSQLITE_THREADSAFE=0 \
-DSQLITE_OMIT_LOCALTIME \
-DSQLITE_OMIT_LOAD_EXTENSION \
-DLONGDOUBLE_TYPE=double"
cargo build --release --target "wasm32-wasi"
Note: [package]
name = "play"
version = "0.1.0"
edition = "2021"
[dependencies]
rusqlite = { path = "../rusqlite/compile-wasm32-wasi", version = "0.26.3", features = [
"bundled",
"wasm32-wasi-vfs",
] } Finally, run with: wasmtime target/wasm32-wasi/release/play.wasm
# Output:
# Found person Person { id: 1, name: "Steven", data: None } |
EDIT: ahhh I realized I needed to run This worked for me on the latest versions of nightly rust / cargo and the latest wasi-sdk. (Outdated) I realize it's been 6 months, but I was trying this method @polyrand and got this error when running your script: // snip snip many more similar errors up here
error[E0531]: cannot find tuple struct or tuple variant `Some` in this scope
--> /home/john/.cargo/registry/src/github.com-1ecc6299db9ec823/fallible-iterator-0.2.0/src/lib.rs:2598:20
|
2598 | (None, Some(b)) => Some(b),
| ^^^^ not found in this scope
error[E0425]: cannot find function, tuple struct or tuple variant `Some` in this scope
--> /home/john/.cargo/registry/src/github.com-1ecc6299db9ec823/fallible-iterator-0.2.0/src/lib.rs:2598:32
|
2598 | (None, Some(b)) => Some(b),
| ^^^^ not found in this scope
Some errors have detailed explanations: E0405, E0412, E0416, E0425, E0432, E0433, E0463, E0531.
error: could not compile `fallible-iterator` due to 820 previous errors Any clues by any chance? Using rustup -V: |
May be fixed by #1321 |
I don't think #1321 fixes this. I still can't build for It looks like And cross-linking between the two targets is apparently also broken: rustwasm/wasm-bindgen#3454 So it looks like the only way to get the two crates into the same project would be for |
cargo build --lib --target "wasm32-unknown-unknown"
With
rusqlite = {version = "0.24.1", features = ["bundled"]}
:with
rusqlite = {version = "0.24.1"}
:It also happens with 0.23.1.
The text was updated successfully, but these errors were encountered: