Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Ability to set crate-type depending on target #4881
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
The only way to get a WASM binary is by setting the
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.
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
So the last thing I tried was to override the crate type via
This is simply ignored by cargo. I still get a
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
@fschutt I currently have the same issue, my workaround is basically this for WASM and rlib releases:
will build the rlib, and
builds the WASM.
Seems to work well for all lib types.
Noob here, but I came here with the same (I think) problem. and solved it by trying
"rlib" instead of "lib" works too
I had previously been building the wasm client the recommended way, but it seemed to be having trouble once I tried also compiling a server with the same Cargo file. Most likely I "should" be using separate Cargo files and maybe workspaces, but I instead changed the build to follow rust-lang/cargo#4881 , which says to build the library as "rlib" instead of "cdylib", and then build a wasm binary out of it. I also debugged and fixed the Makefile rules: * Changed the hard-coded path to my own directory structure to instead always build the wasm to build/. I can make this a symlink if I want to point to my own directory structure instead. * Changed the servers to use the debug build, but with -O1. For this project I don't need a release build. I added a readme file in preparation for uploading to github.