-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
JS glue: Please provide a way to initialize with an already loaded WebAssembly.Module
#2972
Comments
I completely agree that it would be nicer if this just worked out the box, but it sounds like this is more of an issue with Cloudflare rather than wasm-bindgen, right? |
It's a constrained and security-focused runtime, so I suppose it's reasonable for them to prevent fetching wasm and instantiating modules on the fly. Instead, they are essentially uploaded (and checked) at deploy time. They are, however, provided at runtime as a web-standard |
The glue depends on the target. Which target do you use? With |
Hi @johnspurlock, I believe I have a fix for you in #3510. |
Thanks! As long as I can hand in my |
@johnspurlock With my PR, you'd only need to:
|
As pointed out before in #2972 (comment), the wasm-bindgen/crates/cli-support/src/js/mod.rs Lines 871 to 873 in e13d898
I've been extensively using Cloudflare Workers lately with the Web target, this has worked well for me: #[wasm_bindgen]
pub fn fetch() -> Result<Response, JsValue> {
Response::new_with_opt_str(Some("Hello, World!"))
} import wasm from './test_bg.wasm'
import init, * as exports from './test.js';
await init(wasm);
export default exports; So I believe this has already been solved by #1384. |
Motivation
Cloudflare Workers has a wacky way of importing wasm modules.
import module from "./hello.wasm";
...is the only allowed way to bring in wasm (in module-based workers).
module
is then aWebAssembly.Module
, not its exports like the upcoming standard proposal.Currently this means any wasm-bindgen generated JS cannot be initialized properly out of the box. They need to be manually edited with something like a
setModule
function, which is then picked up and used ininstantiateModule
.Once this is done, the wasm lib usually works fine on Cloudflare (modulo some other intentionally missing classes that need to be stubbed like
FinalizationRegistry
)Proposed Solution
It would be great if a future version of the JS glue code could accept an
WebAssembly.Module
already in hand, for environments like this.Alternatives
Tweaking wasm-bindgen generated JS by hand
Thanks!
- John
The text was updated successfully, but these errors were encountered: