-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[WIP] Support to rust/wasm #312
Conversation
Awesome start, really excited about this! I'll give some more feedback in a bit! 🎉 |
Awesome to find some one is already working on this. So fast! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start! Left some suggestions inline.
src/assets/RustAsset.js
Outdated
const JSAsset = require('./JSAsset'); | ||
const localRequire = require('../utils/localRequire'); | ||
|
||
const rustTarget = `wasm32-unknown-emscripten`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think maybe we'll want to use wasm32-unknown-unknown, which doesn't require emscripten. Maybe checkout rustify which does something similar for browserify, and wasm-experiments to see how it all works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right now I'm using wargo and for now, wargo just uses wasm32-unknown-emscripten
but sure, I'm going to take a look at rustify
src/assets/RustAsset.js
Outdated
this.dependencies.clear(); | ||
const {name, encoding, options} = this; | ||
const release = process.env.NODE_ENV === 'production'; | ||
const cmd = `wargo build ${release ? ' --release' : ''}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you mean cargo
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, wargo is a library that setup your environment and makes easy to compile rust into wasm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this PR verify that wargo is installed and accessible or fail violently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right now it's failing violently, 😄 but I was working on an api more friendly to use wargo directly instead of using wargo through child_process.
However, I was thinking about to stop using wargo since wargo is using wasm32-unknown-emscripten
and I think wasm32-unknown-unknown
is a better option...
src/assets/RustAsset.js
Outdated
|
||
const rustTarget = `wasm32-unknown-emscripten`; | ||
|
||
class RustAsset extends JSAsset { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should probably make a WASMAsset
class to load precompiled .wasm
files, and use it as a base class for this one. That way the runtime can be shared across multiple wasm languages.
src/assets/RustAsset.js
Outdated
async parse(code) { | ||
this.invalidateBundle(); | ||
this.invalidate(); | ||
this.dependencies.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh my bad, this was me trying to fix the rebuild as mentioned in the description, I'll remove it, thanks
src/assets/RustAsset.js
Outdated
ENVIRONMENT: 'WEB' | ||
}; | ||
|
||
if (options.fromHtml) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it different when loaded from HTML?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the difference is that with this approach you can use rust as a standalone executable, without javascript.
I got the idea from this article
Hey, I can set aside some time over the holidays to help finish the PR if you'd like. If you want a hand, ping me in parcel's Slack. |
Sure thing @shawwn thanks! |
get rid of wargo use wasm32-unknown-unknown
Hey @devongovett, I made some changes So, I got rid of wargo, and now I'm using what is next?
Do you have something else in mind? also, I made a demo cc: @shawwn |
🎉 Awesome work @albizures! Your list sounds good. I think you can use About validating the existence of Also, we should probably support using Let's also start thinking about what we want the API for importing wasm modules to be. I think there should be a small runtime built into Parcel to load and instantiate wasm modules. Basically we should take care of the There are two cases to think about. Synchronous import, wasm is either inlined into JS or somehow loaded prior to the JS running: import {add} from './add.rs';
console.log(add(2, 3)); Asynchronous import, wasm is placed in a separate file and loaded on demand: let {add} = await import('./add.rs');
console.log(add(2, 3)); Sorry for the long comment. All of this definitely doesn't need to happen in this PR, just getting the ideas flowing! 😄 |
Going to merge this into the |
oh great, thanks 🎉 and I agree with you with all of your points. I'll let you know any news |
Hi, this PR is not complete yet, currently, I'm struggling with two things:
Any ideas?
Thanks in advance
related: #34