-
-
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
Parcel 2: Rust transformer #3365
Comments
Would be cool to see Golang transformer as well. It has good support for WebAssembly. Also Go now has modules which makes development easier (and I guess making a transformer will be easier) Related issues: |
@talentlessguy let's keep this issue about Rust. #2903 seems to cover Go well. |
Thanks for the cc @devongovett! The current state of Rust/WASM/ESM is that tooling like From our perspective having Parcel act as a polyfill for the wasm ESM integration spec would cover all our use cases! |
Thanks for the info @alexcrichton. I'll take a look through that spec. |
FWIW #2973 is another issue related to Rust and |
Would it be possible to also make the Rust transformer respect the |
|
In a similar vein to concerns about the default toolchain, would it be possible to allow for the configuration of the optimization level? By default, currently RustAsset will compile using Having the ability to optimize for compile time or output size over runtime speed would be nice. You can currently set the opt-level in Cargo.toml, but it would be nice to be able to have some control over this from Parcel. Might it be possible to only run in release mode (or rustc equivalent) for |
IMO, the default toolchain should be |
I would just like to point out that in Rust, compilation happens at the crate level, not the file level. That also means that all So it doesn't make any sense to import an individual This is something to keep in mind for the new Rust transformer. |
Here is shrinking wasm size when rust build wasm.
|
We have created a Rollup plugin for Rust, it may be useful to look at its implementation to get ideas for the Parcel transformer. |
Hi there. I wrote
Iirc (it's been a while since I worked on this), the way I did this before was to create 3 assets per imported wasm asset. One "bundle-loader" to actually fetch the Does this still seem like a reasonable approach? Where could I look for any docs, or tests, or just like instructive source code for Parcel 2's way of doing things? Anything I should look out for, common gotchas when creating/porting asset types? Anything I missed? |
@mysterycommand Nice work! To be clear, it should ignore all Some small things I noticed:
In general wasm-pack handles almost everything, so the plugin should just be a thin wrapper around wasm-pack, right now it's duplicating a lot of things that wasm-pack does. |
@Pauan thanks for the code review! I'll try to keep all this in mind when I get a chance to work on this … hopefully this weekend. 🙏 |
I agree. @mysterycommand Awesome!
The wasm-pack looks good. It seems perform shrinking Wasm file size automatically when release build. I will keep looking for better way, but probably not find that way. |
Fix my opinion. I was able to get the effects of lto and opt-level=z with wasm-pack. The generally way. [profile.release]
opt-level = "z"
lto = true Then run wasm-pack build. $ wasm-pack build --release Also, you can set lto and opt-level via environment variable(without setting Cargo.toml) as below. $ RUSTFLAGS="-Clto=yes -Copt-level=z" wasm-pack build --release |
I found additional method 'cargo rustc -- [rustc flags]'. cargo rustc --target wasm32-unknown-unknown --release -- -C lto=yes -C opt-level=z This method pros is to keep user environment as clean. |
@mysterycommand
It is probably not.
Yes. Need run wasm-opt and some optimization tools.
I guess there are two situations for users.
*Note: If set lto=true, the build time will be very long. However, I do not recommend to control Cargo.toml from Parcel 2's configuration options. Alternatively, use 'cargo rustc -- [rustc flags]' method. But this method seems too hard because it cannot be used from wasm-pack. ConclusionIn the first release plugin, I think it is better to just run |
I'm really looking forward to seeing this working. In fact, I can use it right now on the project I'm working on. I'll try to give it a go tonight given that I can't sleep anyways 😅 Will give an update as soon as I have something (or nothing). |
Ok so here's my experience with trying to implement this feature: it's almost working (doing the install and all) but am I correct to say that Pacel 2 does not currently support WASM assets? Even if it did, Parcel would probably use its own loader (I found one in |
@mischnic All right then, I guess it's too early to fully implement this. Will push the code to a repo later today and take a look at the issues you mentioned. |
(Compared to the Parcel 1 implementation, #4673 should be applied) |
Any updates on this? I know we've been quiet for a while but I'm taking a stab at https://medium.com/@cwervo/parc3l-combining-three-js-rust-and-webassembly-c1e643ef7681 and I'd love to assist with this issue. |
@cdbattags feel free to implement this, there's some information about how to do it in this issue. If you have any particular questions you can open a draft PR or just ask questions in here |
Hi hello again, thank you for the nudge. I keep having to drop this for work, and when I pick it back up there's always this kind of lengthy "where was I" phase where I track down my various comments and conversations. It looks like the last time I dug in on this I had a sort of rocky idea of what to do, and I've got a small window now so I'm going to see if I can make some progress in the next couple days. |
Hey again, I've got some progress on this here, but I've run into an issue with my initial implementation that I'm not sure how to handle properly. Looking for help/advice on how to inspect the state of the bundle before it throws the |
In the spirit of "make it work, make it good, make it fast" … this works: #4970 (I make no guarantees about it being good or fast at this time). |
What's the current state of this issue? Is it expected that I cannot get Parcel 2 to work with Rust? When trying to replicate a Is that expected and blocked on this bug? |
Hey, hi, sorry I have not had (and do not currently have) the time to keep working on this. If anyone wanted to take it over I'd be glad to see it happen! That error is new to me, but since my initial implementation here a lot has changed. Sorry I can't be of more help right at the moment. |
Huh, must say after having a good experience with the original parcel + rust I was surprised to discover that parcel 2 doesn't seem to support it — especially when parcel itself seems to make use of rust these days. Alas I lack the time/knowledge to get this done myself |
@devongovett would be nice to add the "rust" label on this... took a bit of digging to find it and figure out that Parcel 2 doesn't support Rust (yet) |
Parcel (2) imports the TOML as json/text after auto-installing a toml transformer, instead of including the WASM blob. Then, of course the TOML json does not have the functions you expect to be exported from the actual WASM file. |
Any update on this? This is the only reason I can't use Parcel 2 at the moment. Also it's a shame to not have rust support on a project written in rust IMHO... |
@Roba1993 I gave up on waiting and moved to Vite. My Rust dependency isn't automatically compiled by the plugin I'm using, but it's better than the nothing that Parcel 2 provides. |
Any updates on this? |
Going to close this. I don't have the bandwidth to implement and maintain this. It would be great as a third party plugin if someone wants to build it! |
Create the
@parcel/transformer-rust
package inpackages/transforms/rust
. This package is a Parcel 2 transform plugin for Rust to WASM. It should be based on theRustAsset
from Parcel 1.The
@parcel/transformer-rust
package is responsible for the following things:It is possible that the current approach in Parcel 1 is out of date. Additional research on the current Rust/WASM ecosystem is needed here. Some related issues:
There are also some plugins that have been working on some related stuff:
If someone from the community would like to own this feature in Parcel 2 core, that would be very helpful and appreciated! 😍
cc. @xtuc @linclark @littledan @alexcrichton - what's the current state of WASM + Rust + ESM? What should we be aiming for in Parcel 2?
The text was updated successfully, but these errors were encountered: