Skip to content
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

Improve wasm32-wasi support #1332

Merged
merged 1 commit into from Nov 25, 2023
Merged

Improve wasm32-wasi support #1332

merged 1 commit into from Nov 25, 2023

Conversation

etehtsea
Copy link
Contributor

@etehtsea etehtsea commented May 25, 2023

Starting from 3.41.0 SQLite has wasm32-wasi support out of the box.

  • Set -DSQLITE_THREADSAFE=0. Fixes:
$ wasmtime target/wasm32-wasi/release/examples/persons.wasm
Error: failed to run main module `target/wasm32-wasi/release/examples/persons.wasm`

Caused by:
    0: failed to instantiate "target/wasm32-wasi/release/examples/persons.wasm"
    1: unknown import: `env::pthread_mutexattr_init` has not been defined
  • Drop -DSQLITE_OS_OTHER. Fixes:
$ wasmtime target/wasm32-wasi/release/examples/persons.wasm
Error: failed to run main module `target/wasm32-wasi/release/examples/persons.wasm`

Caused by:
    0: failed to instantiate "target/wasm32-wasi/release/examples/persons.wasm"
    1: unknown import: `env::sqlite3_os_init` has not been defined

Using of file databases is also working, though --mapdir arg should be provided to wasmtime run.

[Starting from 3.41.0 SQLite has wasm32-wasi support out of the
box.][0]

- Set `-DSQLITE_THREADSAFE=0`. Fixes:

```
$ wasmtime target/wasm32-wasi/release/examples/persons.wasm
Error: failed to run main module `target/wasm32-wasi/release/examples/persons.wasm`

Caused by:
    0: failed to instantiate "target/wasm32-wasi/release/examples/persons.wasm"
    1: unknown import: `env::pthread_mutexattr_init` has not been defined
```

- Drop `-DSQLITE_OS_OTHER`. Fixes:

```
$ wasmtime target/wasm32-wasi/release/examples/persons.wasm
Error: failed to run main module `target/wasm32-wasi/release/examples/persons.wasm`

Caused by:
    0: failed to instantiate "target/wasm32-wasi/release/examples/persons.wasm"
    1: unknown import: `env::sqlite3_os_init` has not been defined
```

- [Add wasi specific build flags][1]
- Add basic example
- Also, add instructions how to run it against wasm32-wasi.

Using of file databases is also working, though `--mapdir` arg
should be provided to `wasmtime run`.

[0]: https://wasmlabs.dev/articles/sqlite-wasi-support/
[1]: https://github.com/vmware-labs/webassembly-language-runtimes/blob/main/libs/sqlite/wasi-patches/wlr-build.sh#L11
@gwenn
Copy link
Collaborator

gwenn commented May 26, 2023

Related to #1289, #1116 ?

@etehtsea
Copy link
Contributor Author

etehtsea commented May 26, 2023

Related to #1289, #1116 ?

My understanding is that these two were superseded by #1321, and though that one fixed compilation against wasm32-wasi, the resulting artifact is still failing in runtime with the errors above.

This PR addresses it. Moreover, wasm32-wasi-vfs is no longer required to make it work (but I'm not sure if it should be dropped or not. I've checked both variants, and this example worked in both cases).

@codecov
Copy link

codecov bot commented May 31, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.26 ⚠️

Comparison is base (24288d9) 80.48% compared to head (5534eb9) 80.22%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1332      +/-   ##
==========================================
- Coverage   80.48%   80.22%   -0.26%     
==========================================
  Files          49       50       +1     
  Lines        9950     9982      +32     
==========================================
  Hits         8008     8008              
- Misses       1942     1974      +32     
Impacted Files Coverage Δ
examples/persons/main.rs 0.00% <0.00%> (ø)
libsqlite3-sys/build.rs 63.84% <0.00%> (-0.83%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@marcua
Copy link

marcua commented Nov 25, 2023

Hello! After testing a bunch of solutions in the various issues/discussions related to rusqlite-on-WASI, this PR seems to contain the combination of tricks that work in my case. I can confirm that not only can it operate on a SQLite DB in memory, but it can also write to and read from a SQLite file on the local (host) filesystem that is then mapped into the wasmtime runtime.

Given that the PR is approved, I'm curious if there is anything I can do to help get it merged into the main branch with the hope of it being available in a future release. I'm grateful to both the maintainers and the submitter, and don't want to stress anyone out if this isn't a priority at the moment. Thank you!

@gwenn
Copy link
Collaborator

gwenn commented Nov 25, 2023

My bad !

@gwenn gwenn merged commit c2fbd16 into rusqlite:master Nov 25, 2023
16 checks passed
@marcua
Copy link

marcua commented Nov 26, 2023

Thank you @gwenn! This is great!

@gwenn
Copy link
Collaborator

gwenn commented Jan 27, 2024

libsqlite3-sys v0.28.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants