I've been working on something where I'd like to make small wasm tests (written in Rust) to verify that the runtime implementation I've done with wasmtime is behaving correctly (pretty much these little tests would trap if the runtime didn't behave right). Ideally I'd have a way to get some packages built to a wasm target and then do something with libtest-mimic.
I can't use wasm-pack since this is not actually running on web
However I can't seem to find a real nice way to do this. On the surface the unstable artifact-dependencies
from cargo would sound like it would work, but the fact that I need to manually insert env lookups into the buildscript isn't nice.
Invoking cargo from a buildscript isn't desirable (since I'd need to avoid having cargo call the workspace which is being invoked, therefore deadlocking)
I believe it can be achieved by using CARGO_TARGET_<triple>_RUNNER and pointing to your compiled application based on wasmtime. You just need to ensure that your application accepts the wasm file that will be executed as argument. If you are using the component model, you can have the same approach but need to install cargo-component
rom this branch i am working on and run cargo component test
.
Eduardo Rodrigues said:
I believe it can be achieved by using CARGO_TARGET_<triple>_RUNNER and pointing to your compiled application based on wasmtime. You just need to ensure that your application accepts the wasm file that will be executed as argument. If you are using the component model, you can have the same approach but need to install
cargo-component
rom this branch i am working on and runcargo component test
.
that looks interesting with the target runner option.
From the pull request I saw it looks quite close to what I want (since I am using the component model) although it seems to generate some empty main functions
My current hack isn't great as I use an xtask crate to invoke cargo twice internally
Although the appeal of not needing all my xtask stuff and instead just throw an empty main in is appealing
@Eduardo Rodrigues thank you for the pointer on target.<triple>.runner
, it's definitely nicer than my xtask stuff.
i509VCB has marked this topic as resolved.
Last updated: Nov 22 2024 at 17:03 UTC