question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

🙋 Use Rust WASM bindgen

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:13
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
alexcrichtoncommented, Feb 9, 2018

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!

2reactions
catsigmacommented, Sep 14, 2018

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:

@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 .

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found