I've been using wasmtime as a test runner by setting in .cargo/config.toml,
Sorry if this is all written down somewhere, I've found it difficult to search for.
runner = "wasmtime run --dir ."
This has generally worked fine until now where I have added a test that reads some stuff in $OUT_DIR and $CARGO_MANIFEST_DIR/../examples.
I was mainly curious if anyone has written a test runner for cargo that works out all the right environment variables for a workspace and adds them as --dir args, afaict don't think cargo supports env var usage in the runners line.
It seems likely this might be something someone has already done though, so I wanted to ask if there was already a wrapper for doing this.
Since .cargo/config.toml is local to a project, or at least can be, could you do that and add the --dir options you'd like?
It is currently committed to the repo, so I can't seem to just set it to an absolute path, or know the right $OUT_DIR, I think ideally, instead of manifest_dir/.. It's best to add the whole workspace, not sure if there is an environment variable for that (I don't think CARGO_WORKSPACE_DIR got beyond discussion?)
ah yeah that I don't think can be done right now
Anyhow I'll probably just look for the top-level cargo.toml from the manifest_dir/.. via negative**
and write a hacky script
well, that almost works but unfortunately it seems like OUT_DIR isn't actually set when running the test runner, thereby indirectly disabling the test :cry:
That itself is a bit weird though because I see the variable set for non-wasi targets... but that like a normal cargo issue...
If I get something working, I'll update this...
But until then I may just end up cfg out this test on wasi.
matt rice said:
That itself is a bit weird though because I see the variable set for non-wasi targets... but that like a normal cargo issue...
oh... it just depends upon whether the crate running the test has a build.rsfile or not whether the runner runs with that environment variable set...
So here is a pretty terrible hack of what I managed to get working with my tests... https://github.com/ratmice/workspace_time_test_runner
Dont try and runner = "cargo run -p workspace_time_test_runner" because that overwrites a bunch of environment variables on the nested cargo invocations (who would try that?)
Anyhow it is probably pretty fragile, and the workspace detection is bad/regretable, but it is a start...
Oh it occurred to me that I can get rid of the worst of the hacks by using cargo metadata workspace_root field
Last updated: Dec 06 2025 at 06:05 UTC