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

WASI support? #507

Closed
GregoryConrad opened this issue Jan 25, 2023 · 9 comments · Fixed by #583
Closed

WASI support? #507

GregoryConrad opened this issue Jan 25, 2023 · 9 comments · Fixed by #583

Comments

@GregoryConrad
Copy link
Contributor

Hi! I was looking to see if redb could compile to wasm32-wasi and came across a handful of issues (with mmap and file locking):

unresolved import `crate::tree_store::page_store::file_lock::LockedFile`
failed to resolve: use of undeclared type `MmapInner`
cannot find type `MmapInner` in this scope

I was wondering if you would be willing to support WASI as a compilation target in redb. I might be able to PR to fix the above compilation issues and test the following functionality:

  1. mmap (which it looks like you may have grabbed from the unmaintained memmap crate?) can probably be fixed by just copying the unix implementation (WASI has a libc that should be the same as unix)
  2. file locking may be exposable from unix like mmap; but I am not sure. Some file locking APIs are not available in WASI libc
@cberner
Copy link
Owner

cberner commented Jan 26, 2023

If it can be added as cleanly as the Windows support, then ya I'm open to merging a PR for wasm support

@GregoryConrad
Copy link
Contributor Author

Great! I'll do some experimenting later to see how plausible it is with the current file locking mechanism.

On a completely different note, does redb support "unlimited" key/value sizes, or is there some hard limit? I didn't see any mention in the README or design.md. I.e., what happens if a key exceeds the page size?

@GregoryConrad
Copy link
Contributor Author

GregoryConrad commented Jan 26, 2023

Alright, some initial findings:

It looks like WASI support will actually be possible sometime in near-ish™️ future, at least using nightly! The errors I'm encountering during compilation come mostly from libc, which are fixable on libc's end. This is because the default libc does not include bindings for mmap and file locking. mmap is already in wasi-libc, and file locking should be coming soon due to the recent spec update here: WebAssembly/wasi-filesystem#2

The only changes necessary should be adding a cargo feature to libc for mmap support and then waiting for file locking support to trickle down through wasi-libc.

@GregoryConrad
Copy link
Contributor Author

See rust-lang/libc#3091

@GregoryConrad
Copy link
Contributor Author

From my comment in #508:

Based on https://github.com/WebAssembly/wasi-libc/blob/main/libc-bottom-half/mman/mman.c, it looks as though redb compiled to WASI would only work in read-only, if at all. Closing this PR as I don't think it makes any sense at the moment.

@GregoryConrad GregoryConrad closed this as not planned Won't fix, can't repro, duplicate, stale Jan 29, 2023
@brianorwhatever
Copy link

wasm support even if read only would be amazing

@GregoryConrad
Copy link
Contributor Author

Since the mmap backend is gone now, this issue can be revisited since that was the blocking issue before. I've done a little experimenting and this is looking somewhat promising, at least when using nightly.

@GregoryConrad
Copy link
Contributor Author

GregoryConrad commented May 27, 2023

For future implementation:

@dpc
Copy link

dpc commented May 7, 2024

What would it take to support indexeddb as a backend for wasm32-unknown-unknown? Am I wrong thinking that indexeddb could serve as a block allocator for redb?

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

Successfully merging a pull request may close this issue.

4 participants