Skip to content
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

Add rlib to crate-type in Cargo.toml #177

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

magurotuna
Copy link

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 :)

@tempdata73
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants