-
Notifications
You must be signed in to change notification settings - Fork 52
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 bindings don't work when there are dependencies on wasm bindgen #700
Comments
Can you expand on this more? What do you mean by "don't automatically generate bindgen", would that mean not doing anything we are doing now? I'm generally okay with a way to config that "hey there's wasm-bindgen here, do the thing to make wasm-bindgen work" if it's just a matter of configuring an additional import. I don't want to lose functionality we have right now. I'm not in favor of calling wasm-bindgen, but you aren't proposing that. |
Sorry was unable to sit down at a computer for a bit. With
I meant that it might be possible to somehow integrate wasm-bindgen directly into diplomat to identify what binding functions are needed for the library to work. I can't, however, see how we could do it without using the compiled wasm in the first place, as we would somehow have to introspect which dependencies expect some bindgen generated binding functions. And it doesn't feel very um ... diplomatic (for lack of a better word) to process the compiled library for generating binding code. I think what's bothering me more is that it feels like wasm-bindgen and diplomat are doing the same work twice sometimes, like this bindgen generated code for decoding a string: function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
} vs diplomat's getValue() {
switch (this.bufferType) {
case Uint8Array:
return this.#decoder.decode(super.getValue());
case Uint16Array:
return String.fromCharCode.apply(null, super.getValue());
default:
return null;
}
} In a perfect world it would be nice to figure out how to avoid that, but I think this would require way too much coordination with wasm-bindgen. |
In any case, that was a big aside to say that some small changes to the config and some additions to the documentation will get us working with wasm-bindgen dependent libraries. |
This seems like very minor duplication IMO.
Yeah, that seems like it would be much deeper integration than we are looking for. Ways for the init layer to mesh together seem sufficient. |
Problem
I ran into an issue while using diplomat to create js bindings for a library I'm working on. The library has dependencies which themselves seem to depend on wasm bindgen. The generated wasm expects interfaces provided by wasm_bindgen in the form of
I created a minimal reproducible example here: https://github.com/jcrist1/diplomat-dbg/tree/6649bacd8e004f82814510774acde572625be891/wasm_bindgen
Workaround
I found a relatively easy workaround, but did have to spend a lot of time debugging to figure it out. Just needed to run
wasm-bindgen
on the generated wasm, use that for the module, and add a line toimports
indiplomat-wasm.mjs
:Proposals:
wasm-bindgen
seems pretty embedded in a lot of crates that support wasm, and is a big part of the rust wasm ecosystem, so some kind of support would be nice, but it feels like directly integrating with wasm-bindgen doesn't seem like it aligns with diplomat's goals. I came up withdiplomat.config.mjs
, and include their use in the generateddiplomat-wasm.mjs
, but don't automatically generate bindgen (i.e. generating{lib}_bg.js
) (and document using wasm-bindgen)I hope 1. would not be too much, but I would prefer 2. I don't think 3. makes sense as dipomat doesn't seem to do really do anything to the compile step.
The text was updated successfully, but these errors were encountered: