IntelliJ: build with target_arch="wasm32"

I have a project that builds fine with cargo build --target=wasm32-unknown-unknown , but it refuses to build IntelliJ, because it does not have target_arch="wasm32" set when buildng from within IntelliJ.

Is there a way, in IntelliJ, to tell it to builds with target_arch="wasm32" ?

The XY problem is: I want this project to build under IntelliJ, so when there are build output errors, I can click on them and jump to correct location in IntelliJ.


If you always need to build it for this target you can create a .cargo/config.toml file and in the [build] section set target to wasm32-unknown-unknown. Be aware that cargo look for .cargo/config.toml in the current dir and parent dirs. So if for example your crate is part of a workspace then .cargo/config.toml will be ignored if it is in the crate dir when running cargo from the workspace root as opposed to the crate dir.

Ah, thank you, please correct me if I am wrong:

If I have a workspace with multiple Rust cargo projects, I can only specify .cargo/config at the workspace level -- i.e. there is one config and it is used for ALL cargo projects.

This is a bit inconvenient if I have a workspace with some client side (wasm32) crates and some server side (x86_64) crates.



I just remembered that if you are using nightly you can use the per-package-target unstable cargo feature. This feature allows you to specify forced-target in the [package] section of Cargo.toml.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.