miri icon indicating copy to clipboard operation
miri copied to clipboard

Some way to pass Miri flags without MIRIFLAGS?

Open RalfJung opened this issue 3 years ago • 12 comments

@Gankra points out that the recommended way to pass flags to Miri -- MIRIFLAGS=-Zmiri-strict-provenance cargo miri test -- does not work on Windows. Also I have to admit this style of flag passing is somewhat verbose.

Is there a way we can pass flags via the CLI while also still being compatible with all cargo test invocations? One suggestion is to "grab" all flags starting with -Zmiri before cargo even sees then, and populate MIRIFLAGS with that. This could break in some corner cases (like when a feature is called -Zmiri-me and someone calls cargo miri test --feature -Zmiri-me), but that seems very unlikely. This does also assume cargo will never have a -Z flag starting with miri, which sounds like a reasonable assumption. Then we could do cargo miri test -Zmiri-strict-provenance, which works on Windows and looks nicer even on non-Windows.

RalfJung avatar Apr 06 '22 00:04 RalfJung

Is there not a way to pass an additional parameter explicitly to cargo binaries when they're invoked? Or is it mainly just that we want Miri to be able to seamlessly pass args through to cargo test itself so we don't have to manually support them?

From a usability standpoint I think it might be slightly nicer to have an explicit --miri-flags parameter for cargo miri than (essentially) guessing which -Z flags the user is trying to pass to Miri vs other tools.

vexx32 avatar Apr 06 '22 12:04 vexx32

cargo miri test -- foo passes foo to the test binaries, i.e. the interpreted program, not the interpreter. So we cannot use that path.

From a usability standpoint I think it might be slightly nicer to have an explicit --miri-flags parameter for cargo miri than (essentially) guessing which -Z flags the user is trying to pass to Miri vs other tools.

That would make it cargo miri test --miri-flag -Zmiri-strict-provenance which is rather verbose. :/

RalfJung avatar Apr 06 '22 18:04 RalfJung

It's entirely unambiguous and unlikely to cause any kind of collision, and it's about the same (+2-3 chars) as the current de facto of MIRIFLAGS=-Zmiri-strict-provenance cargo miri test, so I'm not sure there's much of a difference -- other than if we go that route it can be done the same way on all platforms. 🤷

vexx32 avatar Apr 06 '22 20:04 vexx32

I was comparing that with cargo miri test -Zmiri-strict-provenance.

RalfJung avatar Apr 06 '22 20:04 RalfJung

It would be best if this was supported by .cargo/config.toml. You can pass flags to rustc with build.rustflags, same for flags for docs with build.rustdocflags. Supporting build.miriflags would be very useful. Most of the time I want to run every miri invocation with -Zmiri-strict-provenance, so just setting it globally for the workspace would be ideal.

V0ldek avatar May 20 '22 20:05 V0ldek

Hm, that makes sense but I have even less of an idea for how to support that without reimplementing all the cargo flags logic.^^

RalfJung avatar May 20 '22 21:05 RalfJung

After digging a bit I think it'd have to be a request for rust-lang/cargo itself :confused:

V0ldek avatar May 20 '22 21:05 V0ldek

We could have a .cargo/miri.toml that we process ourselves

oli-obk avatar May 21 '22 06:05 oli-obk

Most of the time I want to run every miri invocation with -Zmiri-strict-provenance, so just setting it globally for the workspace would be ideal.

Could you open a separate issue for that? I think in this one I would like to track passing flags "ah-hoc" for a particular invocation.

RalfJung avatar Jun 08 '22 02:06 RalfJung

Filed #2347 for .cargo/config.toml, since I want it as well for -Zmiri-disable-isolation.

dtolnay avatar Jul 08 '22 16:07 dtolnay

one option would be the form cargo miri -Zmiri-whatever test, since arguments in that position are interpreted by miri itself, and not cargo (currently this is only used by --help)

lolbinarycat avatar Jun 16 '24 18:06 lolbinarycat

We now also have "--many-seeds", which is passed after "test".

RalfJung avatar Jun 16 '24 19:06 RalfJung