🙋 Use Rust WASM bindgen
See original GitHub issueChoose 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 |
Issue Analytics
- State:
- Created 6 years ago
- Reactions:13
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Introduction - The `wasm-bindgen` Guide
Introduction. This book is about wasm-bindgen , a Rust library and CLI tool that facilitate high-level interactions between wasm modules and JavaScript.
Read more >The `wasm-bindgen` Guide - Rust and WebAssembly
Introduction. This book is about wasm-bindgen , a Rust library and CLI tool that facilitate high-level interactions between wasm modules and JavaScript.
Read more >Examples - The `wasm-bindgen` Guide
These examples all assume familiarity with wasm-bindgen , wasm-pack , and building a Rust and WebAssembly project. If you're unfamiliar with these check...
Read more >Deployment - The `wasm-bindgen` Guide
Deploying Rust and WebAssembly ; web, Directly loadable in a web browser ; nodejs, Loadable via require as a Node.js module ; deno,...
Read more >Without a Bundler - The `wasm-bindgen` Guide
This example shows how the --target web flag can be used load code in a browser directly. For this deployment strategy bundlers like...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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:
wasm-bindgensection (naming TBD)wasm-bindgensection is found, then thewasm-bindgentool 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)Ideally in the long run the “Rust project” aspect can be replaced with “any native project compiling to wasm” too!
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 notifications@github.com notifications@github.com: