rust-webpack-template
rust-webpack-template copied to clipboard
Add rlib to crate-type in Cargo.toml
I've been learning wasm by game of life tutorial recently. The difference from the tutorial is that I use rust-webpack-template (this repo) instead of wasm-pack-template (https://github.com/rustwasm/wasm-pack-template).
When I entered the Testing life section, I got a problem; I couldn't import things from src/lib.rs in tests/app.rs. For example, say src/lib.rs has the following content:
pub fn foo() -> i32 {
42
}
and tests/app.rs tries to import foo like this:
use my_wasm_project::foo;
#[test]
...
then use my_wasm_project::foo; flags an error that says "unresolved import my_wasm_project".
I was confused at first, and I tried to look into it, I found this comment in a cargo's issue. Then adding rlib to Cargo.toml, it all works fine.
Moreover, Cargo.toml in wasm-pack-template actually specifies rlib. ref: https://github.com/rustwasm/wasm-pack-template/blob/master/Cargo.toml#L8
I'd be happy to have this PR merged. Thank you :)
Second this, I actually was going to do the same pr. We also have in the template tutorial, under the Cargo.toml subchapter, the explanation:
We also specify crate-type = ["rlib"] to ensure that our library can be unit tested with wasm-pack test (which we'll see later). Without this we wouldn't be able to test our library because the cdylib crate type is incompatible with wasm-pack's style of unit tests.