Unfortunately, the default_runner is always used, even when running cargo test. Is there maybe a workaround for this? A different cfg that could be used?
I don't think there is. In a wrapper around the runner maybe you could check if the wasm file exists in the test directory of the build dir and then dispatch to the right runner?
Thanks for the suggestion, this sounds like an ok tradeoff for now. I just can't find a test sub-directory in the build one. When I run cargo test the .wasm file is generated in the deps folder: target/wasm32-wasi/debug/deps/name-hash.wasm.
I'm just worried when the runner is used outside of the cargo structure that relaying on such a common name as deps may create an issue. I think I will combine it with detecting a cargo set environment variable, like $CARGO_MANIFEST_DIR to harden a bit the detection.
Are there any other cargo commands that generate their builds inside of the deps directory, like test? cargo run? cargo run --example? cargo xxx? Just to check if I'm missing an obvious case where this approach would fail?
EDIT: Sadly, cargo bench uses the same build directory. So you also need to check for a --bench flag.
EDIT2: Running cargo test --example <name> can't be covered with this approach, because it will end up in the examples build directory.