-
Notifications
You must be signed in to change notification settings - Fork 413
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
Using --crate-type
for smoother multi-target compilation
#1297
Comments
As a note, the wasm-pack alternative "Trunk" has already somehow solved this problem in a way that doesn't involve any Cargo.toml changes at all. You might want to look into how they did it (--crate-type or something else?) |
|
@workingjubilee Thank you so much for this detailed issue. I need to think a bit on how to approach this, but I'm currently open for all alternatives, and open for all different discussions and POCs.
Thanks, will take a look at Trunk. |
Hi all! I tried implementing the current idea of using
Looks like our flag will override the https://doc.rust-lang.org/cargo/commands/cargo-rustc.html#compilation-options |
I have a use case for this also described here: #1336 Is there a work around, do i need to fork wasm-pack? maybe a guide on how to do what wasm-pack does manually? |
@TomzBench All wasm-pack is doing under the hood is compiling your crate with a target of So if you just wanted to compile the *.wasm, you could use the following command:
It will output a .wasm in the (this is in a workspace) |
Hi @tronicboy1 It must be doing more than that! It's a pretty big repo with lots of code in there! 😅 It creates a package.json, ts files..etc 🤗 |
My apologies, of course you are correct! My only intention was to suggest that you may be able to get away with just compiling the WASM directly and writing your own *.d.ts file as a workaround? Unfortunately I get the feeling this repository isn't actively maintained anymore. |
This issue is inspired by:
I will try to summarize somewhat.
Feature description
Currently,
wasm-pack build
passes arguments tocargo build
, relying on that and Cargo.toml to be sufficient configuration. This can have problems when people want to build an application for e.g. both Web and Windows targets, as described by mcclure.The proposed solution from a Cargo maintainer is this:
This is unrealistic for users of wasm-pack, as they don't directly control how wasm-pack invokes cargo. Specifically,
wasm-pack build
meanscargo build
, with some argument passthrough, not "eithercargo build
orcargo rustc
plus potentially some additional arguments". The proposed feature is to follow this suggestion internally in wasm-pack, adopting a design which deemphasizeslib.crate-type = ["cdylib", "rlib"]
and relies onwasm-pack build
setting--crate-type
would allow this to happen more "automatically".Tradeoffs
Alternatives
Possible variants that still address this include adding a
wasm-pack rustc
command, so people can add--crate-type
themselves, or adding more configuration options towasm-pack build
. But these would become odd to add to support what would likely be desired as the dominantwasm-pack build
workflow, as then everyone must add configuration going forward. Still, maybe it's the best for maintainability of wasm-pack, even if it leaves the problem "unsolved".Additional Notes
It's likely any preferred change, whether it is in wasm-pack or cargo, may prove disruptive (albeit in a "one-time" manner). I have spoken with T-cargo maintainers further on the Rust Zulip about the technical and social difficulties of educating programmers on updating for things like this. The team happens to have access to a very large megaphone (posts to the Rust blog), and is interested in making that available to help here, regardless of what technical solution is adopted. This would make it more likely Absolutely Everyone who spends any time in the Rust Programmer Anglosphere hears about it.
The text was updated successfully, but these errors were encountered: