Stream: general

Topic: ✔ Testing wasm target crates in a workspace


view this post on Zulip i509VCB (Oct 03 2023 at 01:50):

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)

view this post on Zulip Eduardo Rodrigues (Oct 03 2023 at 07:43):

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.

This will take a similar approach as used by cargo-wasi (source code here) in order to expose the following cargo commands: run, test and bench. The following steps will be done per action: run: ...

view this post on Zulip i509VCB (Oct 03 2023 at 19:55):

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 run cargo 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

view this post on Zulip i509VCB (Oct 03 2023 at 19:58):

My current hack isn't great as I use an xtask crate to invoke cargo twice internally

view this post on Zulip i509VCB (Oct 03 2023 at 20:00):

Although the appeal of not needing all my xtask stuff and instead just throw an empty main in is appealing

view this post on Zulip i509VCB (Oct 03 2023 at 20:05):

@Eduardo Rodrigues thank you for the pointer on target.<triple>.runner, it's definitely nicer than my xtask stuff.

view this post on Zulip Notification Bot (Oct 03 2023 at 20:05):

i509VCB has marked this topic as resolved.


Last updated: Nov 22 2024 at 17:03 UTC