How to compile integration test without compiling binaries

I'm in a weird situation where I want to run the integration tests in one target (host) but the binaries of the crate should only be built for a different target (wasm32-unknown-unknown). Compiling the binaries for any non-WASM target leads to a failure. Therefore, when I try to run the integration tests, the build fails because the binaries fail to compile.

Is there a way to make the binaries not compile when building or running the integration tests?

You can target specific integrations tests, such as tests/, by using --test foo in your cargo test command.

There is also --tests which maybe is useful too :slightly_smiling_face:

EDIT: it looks like --tests does not change much the behavior, and --test foo will still try to compile the binaries just in case the integration tests need them.

The only exception to the latter which I could find in the documentation is:

Binaries are automatically built when the test is built, unless the binary has required features that are not enabled.

So I guess your approach could be to have a wasm feature which is required by the binaries? Users would thus have to use cargo r --features wasm when trying to run the binaries.

Another approach, which usually scales better, is when the examples / binaries of a Cargo package become a bit too limited, to just have extra packages to handle them with more fine-grained control.

For instance:

cargo new wasm-binaries --bin
cd wasm-binaries
cargo add "your-package" --path ..
  • You would then have the code of your binaries under wasm-binaries/src/...,
  • and would have to add -p wasm-binaries to run them.
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.