rusqlite: Can't build for wasm target
cargo build --lib --target "wasm32-unknown-unknown"
With rusqlite = {version = "0.24.1", features = ["bundled"]}:
cargo:warning=sqlite3/sqlite3.c:14012:10: fatal error: 'stdio.h' file not found
with rusqlite = {version = "0.24.1"}:
rust-lld: error: unable to find library -lsqlite3
It also happens with 0.23.1.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 12
- Comments: 46 (14 by maintainers)
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
ARenv var. The script I used is something like:Cargo.tomlfile:Note:
../rusqlite/compile-wasm32-wasiis a path to the branch used for #1116.Finally, run with:
Add this line to cargo.toml:
seems like it just works™ except that it also compiles
js-syson non-wasm targets…UPDATE: Now, it seems there is a newer PR: #1643, untested, updated:
@GeeWee I got the same error. (M1 Mac, tried
wasi-sdk10, 12 and 14).I started trying to compile the
sqlite3.camalgamation separately, running theclangcommand in the error message you posted (which I also got). By using theDSQLITE_THREADSAFE=0flag, thepthread.herror went away, but I got several new errors I couldn’t fix. In any case, disabling thread safety may not work, sincerusqlitedoesn’t seem to allow it: https://github.com/rusqlite/rusqlite/blob/master/tests/deny_single_threaded_sqlite_config.rs (Found it from #746).This is the command I was running:
(I included the
D_WASI_EMULATED_MMANflag following an error message fromclang).I’ll report back if I manage to fix something.
Compiling Rust that depends on C stdlib to WebAssembly is not possible with
wasm32-unknown-unknown. So you need to use WASI or Emscripten to compile SQLite and link it to rusqlite. https://github.com/rustwasm/team/issues/291#issuecomment-645482430what about adding a feature “web” which wraps sqlite-wasm-rs in stead of the default bundled SQlite?
EDIT: nvm there is a PR and some people are already using that branch, works like a charm!
@opeolluwa You should look at this web site,the sqlite3 that compile need the C-library,however ,so you must use emscripten to compile。 https://sqlite.org/wasm/doc/trunk/emscripten.md (I finally give up this sqlite3 (>﹏<))
I don’t think #1321 fixes this. I still can’t build for
wasm32-unknown-unknown, becausesqlite3.cwantsstdio.h, which is not available on a target without a real libc.It looks like
wasm32-unknown-unknownsupport is required if you want to userusqlitein the same project aswasm-bindgen, which isn’t planning to ship a version that can build forwasm32-wasi: https://github.com/rustwasm/wasm-bindgen/issues/3421And cross-linking between the two targets is apparently also broken: https://github.com/rustwasm/wasm-bindgen/issues/3454
So it looks like the only way to get the two crates into the same project would be for
rusqliteto be able to build onwasm32-unknown-unknown, with no libc and no VFS, and then have the user provide a VFS.Managed to work !
With
wasi-sdk 14.0, idea from #1116just compile, no test 😉
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”.