Open
Description
Problem
In a package with a single bin and a lib, cargo run
builds lib.rs
before building main.rs
while cargo run --bin <name_of_the_package>
builds only main.rs
.
Steps
- I have a package with a
lib.rs
that I use for target WASM and a binarymain.rs
that I use to run a CLI. Some dependencies are only useful for the lib, some other dependencies are only useful for the bin. - I use this to distinguish where I want them:
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "^0.2"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
structopt = "0.3"
- When I do
cargo run --bin <name_of_the_package>
it builds and run successfully the CLI. - When I do
cargo run
it tries to build lib.rs which fails because the dependencies are not available.
$ cargo run
Compiling basic v0.1.0 (/home/cecile/repos/wasm-run/examples/basic)
error[E0433]: failed to resolve: use of undeclared crate or module `wasm_bindgen`
--> src/lib.rs:1:5
|
1 | use wasm_bindgen::prelude::*;
| ^^^^^^^^^^^^ use of undeclared crate or module `wasm_bindgen`
What I expect: running cargo run --bin <name_of_the_package>
does exactly the same than cargo run
if there is only one bin in the package.
I wouldn't mind too much if it was just the dependencies but this is slowing down a lot the build process as it compiles the lib in WASM for no good reason.
Possible Solution(s)
...
Notes
cargo 1.50.0 (f04e7fab7 2021-02-04)