-
Notifications
You must be signed in to change notification settings - Fork 409
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
link to how to wasmify external crates more prominently #196
Comments
@yoshuawuyts sorry this has sat with no reply for so long. i think i sort of understand what you want to do- is a general way of stating what you want something that would help me understand better is if you could explain what happens if you try to use |
I think I have 2 questions here: 1.The first question I have is "what is the right directory structure for a project that wants to target Rust, C and WASM?" I feel the C and Rust targets are well understood. It's still a bit unclear to me how to structure a project to also target WASM. I think your suggestion of just trying out wasm-bindgen on my project's core repo is the right approach. Maybe that's just the answer? Afaik as long as I'm not targeting WASM, the 2.What is the right approach to bind another crate to WASM? E.g. create a crate that exposes all methods from the following template: extern crate rand;
use rand::*; I think if I had to reformulate this to a question, it would be: "How can I take an external crate, and bind all of its methods to WASM?" |
|
In regards to 2 - I kind of wonder if we could formulate an answer by hacking https://github.com/chancancode/rust-delegate into automatically adding the right I was thinking it might be fantastic to be able to do something along the lines of this: #[macro_use]
extern crate wasm_bindgen_macro;
extern crate fibonnacci;
use fibonnacci::Fibo;
// Inserts `extern crate Fibo {}` here with all methods exported to WASM.
wasm_bindgen!(Fibo); My macro foo isn't quite up to speed; but my gut tells me this should be possible, right? |
You would need the compiler's internals to understand what exists in the type in terms of functions etc., so I feel like it would be possible with a plugin for sure, but it miiiight be possible with proc-macro. I feel less certain about the latter. |
@yoshuawuyts is this similar to the question you recently asked in the rust wasm wg meeting? |
I created an example that does this [0] but I'm running into a |
Okay, so I've been trying out wasm-pack for a bit, and I'm wondering how to
package up crates. Let's start off by sketching two real-world scenarios
Scenarios
Workspaces
In this scenario we have 3 different workspaces
I would want to have one workspace for the core library, one for the WASM
version, and one for the C bindings. This is useful because not all versions
might have the same overlap in features, versions and other platform-specific
details. This is the main situation I'm in right now.
Wrapping third-party crates
Another scenario I've seen is where someone tries to wrap up an existing crate
from crates.io for usage in JavaScript. Take for example Dropbox's Brotli
implementation:
I reckon a scenario like the above will not be too uncommon. There's probably
plenty of Rust libraries that would be great to have working in the browser, and
probably the fastest way to get there is to be able to have people generate
bindings.
Question
Well yeah, guess that intro took a bit longer than expected. But anyway, I'm a
bit confused on how to solve the scenario above. All examples I've seen so far
kind of expect the core implementation and WASM source to live in the same repo.
But that's clashing a bit with what I'm trying to do. So my question is: how can
wasm-pack work for both scenarios above?
Thanks so much!
The text was updated successfully, but these errors were encountered: