Hi, I have a project where I use my own test suite harness (think compile-test but less clever). I'd like to run these tests under miri but from what I can see, cargo-miri assumes that binaries are known by cargo (either via
Cargo.toml or by existing in
src/bin/. Instead, we just have a large dir of independent source files, a bit like the
test/ dir in rustc. Is it possible to setup and compile things for miri using
rustc so that my own test harness (and not cargo-miri) can compile each target independently and dispatch it to
cargo-miri run? Thanks!
You can use the
miri binary instead. I believe it is a drop in replacement for the
Thanks Bjorn! :thumbs_up:
indeed. :) using this "driver" directly is not very well documented and the flags are less stable, but it should work. if you have any questions, feel free to ask here or open an issue.
Thanks @RalfJ, I'm having a little difficulty using the driver because the file I want to test depends on a crate. Is there a way to use
cargo miri to build the crate with the relevant miri flags, and then divert to the driver to actually run the file? Maybe even I could use
cargo rustc with the same toolchain as the driver and pass in the relevant flags as arguments?
Is there a way to use cargo miri to build the crate with the relevant miri flags, and then divert to the driver to actually run the file?
well that's exactly what
cargo miri does...^^
you could do
cargo miri -vv to make it show you all the flags for calling the driver the right way
it'll show something like
Running `/home/r/.cargo/bin/cargo-miri rustc --crate-name cargo_miri_test --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C debuginfo=2 cargo-miri-marker-begin cargo-miri-marker-end -C metadata=2eab38112672c0a9 -C extra-filename=-2eab38112672c0a9 --out-dir /home/r/src/rust/miri/test-cargo-miri/target/debug/deps -C incremental=/home/r/src/rust/miri/test-cargo-miri/target/debug/incremental -L dependency=/home/r/src/rust/miri/test-cargo-miri/target/debug/deps --extern byteorder=/home/r/src/rust/miri/test-cargo-miri/target/debug/deps/libbyteorder-6f03af6f96c10631.rlib`
@RalfJ Ah I understand. Unfortunately I have quite a lot of crates that would need manually compiling with the driver this way that it's not really feasible. Is there a flag I can pass to
cargo-miri that would let me build the artefacts for miri but not run them? That way I could just pre-build them and link them all on the command line at once with the driver.
Hm, no... probably the best you can do is add a hack here to just skip the binary you do not want to run
also there's no "linking" so I dont entirely follow your question
I also finally figured out the debug flag I actually wanted to recommend:
cargo miri run -- -v
the number of dependencies doesnt matter, this will just build all of them and then run the first binary (and fail, you said), but it'll print the invocation so you can make it run the 2nd binary instead
@RalfJ The penny has dropped -- I see what you mean now. Thanks for the help!