-
Notifications
You must be signed in to change notification settings - Fork 19
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
Support for wasm32-unknown-unknown
via binding with the provided emscripten wasm file
#10
Comments
We should be able to use once_cell to safely make the module static: https://docs.rs/once_cell/latest/once_cell/ |
Awesome!!! |
Nice work, thanks for writing all this down! I’m happy to consider merging something like this in. When the time comes to review, anything we can do to keep the “native” use-case of the crate relatively simple and to minimize ongoing future maintenance will be appreciated. (I want this project to be sustainable!) If appropriate maybe we could have some of it (like the wrappers) in a downstream but in-tree crate? An extra review by someone more familiar with bindgen would also be very welcome! |
So one think I've ran into is that (and I've love to be corrected on this if I'm wrong) it doesn't seem like you can create rust slices from javascript I think the main API to get into parity is the |
I've worked on this a bit more today and have created some commits that let me use |
|
CC @superdump
I've been working on writing bindings for the transcoder wasm that basis_universal provides so that I can parse and transcode basis files in wasm. I've got a repo for this here:
https://github.com/expenses/basis-universal-rs-wasm
It'd be fantastic if we could get support for this into this crate, so that wasm support just works. A couple of notes:
I had to set
EXPORT_ES6=1
in the emscripten link flags:https://github.com/BinomialLLC/basis_universal/blob/b38c3e4a9bf85d2fe13e2a9d5495be90eb927381/webgl/transcoder/CMakeLists.txt#L51
I don't know if I strictly needed to do this, but it made binding with wasm-bindgen via
#[wasm_bindgen(js_name = default)]
a lot easier.The emscripten code loads the module asyncronously, which means you can't directly import the exports in wasm-bindgen because they're only created after initialisation. To work around this I had to use reflection to create the javascript classes: https://github.com/expenses/basis-universal-rs-wasm/blob/8274f56092c930bb0dfbb35b0386235a3c5a9813/src/lib.rs#L36-L38
By default the emscripten code attempts to load the wasm binary from a relative url. Because wasm-bindgen copies the referenced javascript module to a snippet such as
pkg/snippets/basis-universal-wasm-8dd816e8505190b7/basis_universal/webgl/transcoder/build/basis_transcoder.js
but does not copy anything else. this load fails.Luckily the code allows settings a
wasmBinary
key in the object that's passed in, so you can provide your own wasm file: https://github.com/expenses/basis-universal-rs-wasm/blob/master/src/lib.rs#L26-L31. I justinclude_bytes!
the file for ease of use.Because the wrapper API is quite different from the normal API, we're probably going to have to write our own wrapper to bring the APIs to parity.
This will all take a while, but I'll try to create good bindings for the
.basisu
transcoder and work from there.The text was updated successfully, but these errors were encountered: