-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Ability to set crate-type depending on target #4881
Copy link
Copy link
Closed as not planned
Labels
A-crate-typesArea: crate-type declaration (lib, staticlib, dylib, cdylib, etc.)Area: crate-type declaration (lib, staticlib, dylib, cdylib, etc.)C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Metadata
Metadata
Assignees
Labels
A-crate-typesArea: crate-type declaration (lib, staticlib, dylib, cdylib, etc.)Area: crate-type declaration (lib, staticlib, dylib, cdylib, etc.)C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Type
Fields
Give feedbackNo fields configured for issues without a type.
This is an issue that currently blocks me from porting a library to WASM:
I have a library called proj5, which I use in a backend server (in a regular Rust program). I wanted to port the library to wasm (the
wasm32-unknown-unknowntarget) that is now available on nightly and found it to be impossible to do it while still being able to use it in the backend:The only way to get a WASM binary is by setting the
crate-typeto"cdylib"in the Cargo.toml file. However, if I do this, I can't use the crate in my regular rust program anymore! And if I leave it out, there is not WASM output.So currently a crate can be compiled either for WASM or for use in a regular Rust program, not both (controlled by the target). I tried the following so far:
This doesn't work, the argument goes unused:
I also tried:
Same thing, same error message. The crate builds, but doesn't produce a WASM binary.
.cargo/config) does not seem to have any effect. I tried:This just gives a cryptic error, and sets the crate-type twice:
No line number, no column number, nothing. Not sure where it failed - the error message could be heavily improved upon.
I also tried it with
crate_type,-- --crate-type,--crate-type dylib. None of which work. I expected--crate-type=dylibto work, because it is documented this way, however I suspect that the documentation is incorrect or out of date.So the last thing I tried was to override the crate type via
cfg_attr:This is simply ignored by cargo. I still get a
.rlibfile, not a.wasmfile.So right now I'm out of options. Why is is so hard to build a library for both regular Rust use and WASM? Right now I can only choose either-or.
There is a workaround in that I make a second crate (as
cdylib), which just exposes the first one (therlib), but I don't think this is the way to go. This is important for feature-gating crates so that they can be compiled to WASM without any workarounds.