Different target per crate in a multi crate project

I’m writing an app that is comprised of two crates: the first crate is a standard binary which uses webview to load a yew project which is compiled as asm.js. The first binary crate uses an index.hml file and the compiled asm.js file.

How can I create a single workspace project and specify that the first crate should be compiled with cargo build and the second with cargo web build --target asmjs-unknown-emscripten? Currently, cargo builds both crates in the same way, causing the build of the second crate to fail.

Try the following:

target = "asmjs-unknown-emscripten"

In your asmjs crate’s Cargo.toml.

Cargo will ignore the [build] key, unfortunately. The same incantation will work in .cargo/config, but Cargo appears to only respect the one it finds in the directory where it gets run (or above that in the hierarchy), and won’t look inside crates in a workspace to find other configuration.

(I’ve been dealing with the same issue as @jon_black and I find the current situation very frustrating.)

What I currently do is:

  1. Use the default-members Cargo.toml key to specify which workspace members get build from raw cargo build.

  2. For the wasm crate, use a shell script to cd into it and run wasm-pack build, which sets the target. (I don’t believe wasm-pack supports emscripten, so you could do the same thing with cargo build --target (yourtarget).)


Where is the build group documented? I couldn’t find it anywhere in the manifest format.

As @cbiffle mentioned, [build] actually only works in config.

1 Like

Ah I understand. I wasn’t aware that the Cargo configuration system was completely separate. Thanks for the link explaining it.

I created an issue for this in the Cargo project: https://github.com/rust-lang/cargo/issues/7004

1 Like
