obsidian-api
obsidian-api copied to clipboard
`wasm` bindings
I have thoroughly been enjoying this project! I wanted to know if it would perhaps be possible to add wasm bindings to the API's? In my use case, it would be for Rust with WebAssembly, which, in my opinion, has the best wasm interop story at the moment.
I'm pretty sure you can use web assembly right now, you just need to figure out a compilation pipeline such that it bundles your wasm file as a base64 blob inside your plugin and load it directly with the WebAssembly.compile/WebAssembly.instantiate API.
I also have no idea what you mean by wasm bindings. The WebAssembly API is available directly in the browser engine.
Getting wasm to load is pretty straight forward. I meant providing API bindings, such as you do for typescript with .d.ts but for wasm.
Currently in order to use the API with wasm, you have to manually re-declare all of the public typescript functions. Or at least, the ones one plans on using.
Perhaps this might give a bit of insight.
I am also willing to contribute these bindings if you're open to it, although if they are going to be changing very often, I'd rather wait until their a bit more stable.
Maybe something like this would help? https://github.com/trashhalo/obsidian-rust-plugin
If I understand correctly, you want me to generate the rust wasm_bindgen file with the .d.ts definitions in rust form?
I would assume there's some kind of automated conversion library somewhere out there if that's what you need 🤔 ...
Maybe something like this would help? https://github.com/trashhalo/obsidian-rust-plugin Yes! If you check out
src/obsidian.rs, you'll see a couple simple binding declarations, but we need to manually re-declare all the functions we plan on using every time we want to create a new plugin.
If I understand correctly, you want me to generate the rust wasm_bindgen file with the .d.ts definitions in rust form?
Yes, correct!
I would assume there's some kind of automated conversion library somewhere out there if that's what you need 🤔
Well, as far as I know, kind of...but not necessarily for typescript. The thing about TypeScript, is that it is an incomplete description of types. For example, functions in js/ts can throw errors, and ts does not encode this in it's type signatures.
There are standards, such as WebIDL which allows a more complete depiction of type signatures. If you were, for example, to provide WebIDL descriptions, then these could be used to automatically generate bindings, and not just for Rust, but pretty much any language that speaks thee C ABI (pretty much all of them).
I don't think we have bandwidth to provide this at the moment but we can keep this issue open for further discussion.
Suggestion: instead of the Obsidian team maintaining the interop files for all the WASM targeting languages plugin devs may want, how about open-source community supported repos, one per language? That could be a single source of truth shared across multiple plugins, and plug-in devs submit PRs to add new APIs as they need them.