Parcel: ๐Ÿ™‹ Use Rust WASM bindgen

Created on 9 Feb 2018  ยท  8Comments  ยท  Source: parcel-bundler/parcel

Choose one: ๐Ÿ™‹ feature request

๐Ÿค” Expected Behavior

Running the following code should work

// rust.rs
#[no_mangle]
fn get_string() -> String {
    String::new("string")
}
import { get_string } from "./rust.rs";

assert(get_string() === "string");

๐Ÿ˜ฏ Current Behavior

Currently, with that Rust code, you will get undefined when called from JS causing the asserting to fail.

๐Ÿ’ Possible Solution

Admittedly, I'm probably not someone who's anywhere near authorized enough to open this issue, but my intention here is to get some discussion started on it at least. Maybe some more experienced rustaceans can chime in with some actual useful information regarding this.

From the little research I did (mind you, I didn't actually test this), there is a project called wasm-bindgen by @alexcrichton that can be used to fix this behavior. Maybe that could somehow be integrated into parcel.

๐ŸŒ Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.5.1
| Node | 9.3.0
| npm/Yarn | npm 5.5.1
| Operating System | Fedora 27

Help Wanted Feature

Most helpful comment

Hello! At least on the Rust side of things my current plan at least is to advertise https://github.com/alexcrichton/wasm-bindgen for this use case (as you've pointed out). It's not quite ready for prime time but I think it's something Parcel may want to have knowledge of! In its final state it'd probably look something like:

  • When a Rust project/file is included, it's compiled to wasm
  • When a Rust wasm file is included, it's searched for the custom wasm-bindgen section (naming TBD)
  • If the wasm-bindgen section is found, then the wasm-bindgen tool is executed on the wasm file, generating a JS and a wasm file. (the JS file replaces the original wasm file, and the new wasm file generated is imported by the JS file)
  • The inclusion of the Rust project then continues as usual

Ideally in the long run the "Rust project" aspect can be replaced with "any native project compiling to wasm" too!

All 8 comments

Hello! At least on the Rust side of things my current plan at least is to advertise https://github.com/alexcrichton/wasm-bindgen for this use case (as you've pointed out). It's not quite ready for prime time but I think it's something Parcel may want to have knowledge of! In its final state it'd probably look something like:

  • When a Rust project/file is included, it's compiled to wasm
  • When a Rust wasm file is included, it's searched for the custom wasm-bindgen section (naming TBD)
  • If the wasm-bindgen section is found, then the wasm-bindgen tool is executed on the wasm file, generating a JS and a wasm file. (the JS file replaces the original wasm file, and the new wasm file generated is imported by the JS file)
  • The inclusion of the Rust project then continues as usual

Ideally in the long run the "Rust project" aspect can be replaced with "any native project compiling to wasm" too!

Hi! Can we expect any progress on this feature in near future? )
I would really love to use wasm-bindgen with parcel

If I try to build this project with parcel, it panics at __wasm_bindgen_unstable section, which is expected behaviour for now, I suppose.

Maybe, if you have other priorities at the moment, I could try to do it myself. I'd love to help, but I'm not sure I have enough skills for this task. ) How difficult is to implement its support?

I've made a plugin to solve this issue.
https://www.npmjs.com/package/parcel-plugin-wasmbindgen

It works for me.

(Currently the package name is parcel-plugin-wasm.rs)

@catsigma, haven't checked it yet, but this sounds very nice! May I ask you to publish your plugin on github as well, so we could contribute to your work?

Sure, lโ€™ll establish a github repo for it later today.

Friday, September 14, 2018, 18:56 +0800 from [email protected] notifications@github.com:

@catsigma , haven't checked it yet, but this sounds very nice! May I ask you to publish your plugin on github as well, so we could contribute to your work?
โ€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub , or mute the thread .

@catsigma would be cool if you could try gets wasm bindings working inside parcel core. We could def use someone to improve rust support/stability inside parcel

Sent with GitHawk

Iโ€™ve checked the related parts of source codes. It may take huge change to support wasm module by default. So I think a plugin supporting wasm-bind gen exclusively is better.

Friday, September 14, 2018, 23:13 +0800 from [email protected] notifications@github.com:

@catsigma would be cool if you could try gets wasm bindings working inside parcel core. We could def use someone to improve rust support/stability inside parcel
Sent with GitHawk
โ€”
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub , or mute the thread .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

medhatdawoud picture medhatdawoud  ยท  3Comments

davidnagli picture davidnagli  ยท  3Comments

algebraic-brain picture algebraic-brain  ยท  3Comments

urbanhop picture urbanhop  ยท  3Comments

mnn picture mnn  ยท  3Comments