Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo-miri does not support workspaces #1001

Closed
jamii opened this issue Oct 16, 2019 · 7 comments · Fixed by #1540
Closed

cargo-miri does not support workspaces #1001

jamii opened this issue Oct 16, 2019 · 7 comments · Fixed by #1540
Labels
A-cargo Area: affects the cargo wrapper (cargo miri) C-bug Category: This is a bug.

Comments

@jamii
Copy link

jamii commented Oct 16, 2019

[nix-shell:~/materialize]$ RUST_BACKTRACE=full cargo miri test
thread 'main' panicked at 'could not find matching package', src/libcore/option.rs:1186:5
stack backtrace:
   0:     0x5651a7ff78b4 - backtrace::backtrace::libunwind::trace::h187f113b2abb647f
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/libunwind.rs:88
   1:     0x5651a7ff78b4 - backtrace::backtrace::trace_unsynchronized::h38320d8128cd24b5
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.37/src/backtrace/mod.rs:66
   2:     0x5651a7ff78b4 - std::sys_common::backtrace::_print_fmt::h556c1c2dcb1a6658
                               at src/libstd/sys_common/backtrace.rs:77
   3:     0x5651a7ff78b4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hc8b96dbda96cbdc1
                               at src/libstd/sys_common/backtrace.rs:61
   4:     0x5651a801a64c - core::fmt::write::h5df803e3899d44e6
                               at src/libcore/fmt/mod.rs:1028
   5:     0x5651a7ff4377 - std::io::Write::write_fmt::h68c8001b57139b09
                               at src/libstd/io/mod.rs:1412
   6:     0x5651a7ff9d5e - std::sys_common::backtrace::_print::hd5e7e75fe3073c40
                               at src/libstd/sys_common/backtrace.rs:65
   7:     0x5651a7ff9d5e - std::sys_common::backtrace::print::he7bb8f2987194f75
                               at src/libstd/sys_common/backtrace.rs:50
   8:     0x5651a7ff9d5e - std::panicking::default_hook::{{closure}}::hb1d0eb5b0ef71aca
                               at src/libstd/panicking.rs:189
   9:     0x5651a7ff9a61 - std::panicking::default_hook::h180de3c633f62ee7
                               at src/libstd/panicking.rs:206
  10:     0x5651a7ffa3a5 - std::panicking::rust_panic_with_hook::hdbd08e13a7c982fe
                               at src/libstd/panicking.rs:469
  11:     0x5651a7ff9f42 - std::panicking::continue_panic_fmt::hce8732bd3590e67f
                               at src/libstd/panicking.rs:376
  12:     0x5651a7ff9e36 - rust_begin_unwind
                               at src/libstd/panicking.rs:303
  13:     0x5651a80174da - core::panicking::panic_fmt::h6ae4e581ed6dc186
                               at src/libcore/panicking.rs:84
  14:     0x5651a8017547 - core::option::expect_failed::he6206254f2567eda
                               at src/libcore/option.rs:1186
  15:     0x5651a7fb31e3 - cargo_miri::in_cargo_miri::hcec20312bf94bc59
  16:     0x5651a7faffdc - cargo_miri::main::h27ebf5efc0e679f2
  17:     0x5651a7fb9a63 - std::rt::lang_start::{{closure}}::h86b770088dbcc250
  18:     0x5651a7ff9e23 - std::rt::lang_start_internal::{{closure}}::h7b205f4a42ad477c
                               at src/libstd/rt.rs:48
  19:     0x5651a7ff9e23 - std::panicking::try::do_call::h86e27d03bcc6125d
                               at src/libstd/panicking.rs:288
  20:     0x5651a8000a3a - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:80
  21:     0x5651a7ffa89d - std::panicking::try::hfc76a5c7339ca0f6
                               at src/libstd/panicking.rs:267
  22:     0x5651a7ffa89d - std::panic::catch_unwind::h49899aa9a0080a0f
                               at src/libstd/panic.rs:396
  23:     0x5651a7ffa89d - std::rt::lang_start_internal::hf860c9ff06c64238
                               at src/libstd/rt.rs:47
  24:     0x5651a7fb40d2 - main
  25:     0x7f2ceba08b8e - __libc_start_main
  26:     0x5651a7fabfb9 - <unknown>

[nix-shell:~/materialize]$ cargo miri -V
miri 0.1.0 (2adc39f 2019-10-14)

[nix-shell:~/materialize]$ xargo --version
xargo 0.3.16
cargo 1.40.0-nightly (a429e8cc4 2019-10-04)

[nix-shell:~/materialize]$ rustup show active-toolchain 
nightly-x86_64-unknown-linux-gnu (overridden by '/home/jamie/materialize/rust-toolchain')

Possibly relevant - this project is a cargo workspace which has caused problems for some other tools.

@jamii
Copy link
Author

jamii commented Oct 16, 2019

jamie@machine:~/materialize$ rustc --version
rustc 1.40.0-nightly (237d54ff6 2019-10-15)

@jamii
Copy link
Author

jamii commented Oct 16, 2019

Running inside individual crates does seem to work, so very likely a workspace issue.

@jamii jamii changed the title Miri crashes with 'could not find matching package' Miri crashes with 'could not find matching package' when run in workspace Oct 16, 2019
@RalfJung
Copy link
Member

Yeah I don't think we currently support workspaces. Does cargo test? Looking at https://github.com/rust-random/rand/blob/9221d93f7bcbb68bf886760d710ba269bb8b31b9/utils/ci/script.sh, they need to run the tests separately for each package in the workspace as well.

@RalfJung RalfJung added A-cargo Area: affects the cargo wrapper (cargo miri) A-ux Area: This affects the general user experience C-bug Category: This is a bug. labels Oct 16, 2019
@jamii
Copy link
Author

jamii commented Oct 16, 2019

Yeah I don't think we currently support workspaces

Fair enough. If I had realized it was a workspace issue right away I probably wouldn't have filed an issue.

Does cargo test?

cargo test and cargo bench work. rls started working recently.

@RalfJung
Copy link
Member

Fair enough. If I had realized it was a workspace issue right away I probably wouldn't have filed an issue.

It is certainly a bug to panic here, so thanks for filing!

But beyond that, we'd certainly like to support workspace. cargo miri test should run the same code as cargo test. But really someone should re-write most of that cargo-miri wrapper as it is a bad mess. And I am unlikely to do it anytime soon, so this is a great opportunity to contribute. :)

cargo test and cargo bench work.

And what do they do? Run the tests of all crates in the workspace?

@jamii
Copy link
Author

jamii commented Oct 16, 2019 via email

@RalfJung
Copy link
Member

#1002 should fix the awful error message.

But let's keep this issue open to track workspace support.

@RalfJung RalfJung changed the title Miri crashes with 'could not find matching package' when run in workspace cargo-miri does not support workspaces Oct 16, 2019
@RalfJung RalfJung removed the A-ux Area: This affects the general user experience label Oct 16, 2019
bors added a commit that referenced this issue Sep 12, 2020
Redo cargo-miri logic

This rewrite the cargo-miri logic for running the requested crate(s) following what we outlined in #739: `cargo miri run/test $FLAGS` (almost) literally invokes `cargo run/test $FLAGS` but with some environment variables set so that we can control what happens:
* `RUSTC_WRAPPER` is set so that we get invoked instead of `rustc`. We use that power to mess with the flags being used for the build (things to be interpreted by Miri use a different sysroot), and when we are detecting a binary crate meant to be run by Miri, we grab the info we care about and put it into a JSON file for later use.
* `CARGO_TARGET_$TARGET_RUNNER` is set so what we get invoked when cargo wants to run a binary. At that point we take that JSON info from before and use it to invoke Miri.

Overall this works great! We get all sorts of cargo magic for free, and do not even need `cargo-metadata` any more. There's one annoying point though, which I have not managed to entirely work around yet: this means we are doing a full build, not just a check-build. Given that our sysroot is MIR-only, I was surprised that this even worked, but still -- this means we are doing more work than we should. So I also added some patching of arguments to make sure `--emit` does not contain `link`, and then more patching was required of the `--extern` flags for the binary because those referenced the `.rlib` files but now only `.rmeta` exists, and that is still not fully working because cargo seems to expect those `.rmeta` files and now triggers a rebuild each time as those files are still missing. My current plan is to make our wrapper create some empty dummy files with the right names, but the amount of hacks we are stacking on top of each other here is getting worrysome.^^ `@ehuss` your input would be welcome on this issue.

Due to re-using cargo more literally, this also changes flag parsing to match `cargo`. So `-Zmiri` flags now have to be passed via an environment variable (Cc #1416).

This PR is not ready yet, but the parts that are there I think can be reviewed already. TODO:
* [x] [Fix Windows](#1540 (comment)).
* [x] Figure out how we can do check-only builds without the rebuild problem above. I am also worried about cases where `build.rs` script might detect check-only builds and then do less work; I think some crates in rustc are doing that and if this is a thing in the wider ecosystem we need to find a way to support this as well.
* [x] Currently cargo runs doctests as well, and they are not run in Miri. We should at least figure out a way to not run them at all (resolving #584 is left for a future PR).
* [x] For some time, detect the old way of passing `-Zmiri` flags and warn that this will need updating. For some simple situations we can probably make it still support the old way, but I plan to remove those hacks after a bit. This is just to give people and me time to go around and send PRs to all projects that use Miri on CI, and update their use of the flags.
* [x] Add a test for stdin handling (#1505). This should work now but we should be sure.
* [x] Add a test for cargo env vars (#1515).
* [x] Check if #1516 is resolved.
* [x] Check if #1001 and #1514 are resolved.
* [x] Check if #1312 is resolved (not sure if it is wort adding a test).
* [x] Check if #1512 is resolved (not sure if it is wort adding a test).

Fixes #700.
Fixes #739.
Fixes #1001.
Fixes #1312 (without a test, as we run without cargo's stdin/stdout wrapping now, as the test for stdin confirms).
Fixes #1416.
Fixes #1505.
Fixes #1512 (without a test, as cargo now does all that handling anyway, which various other tests confirm).
Fixes #1514.
Fixes #1516.

Cc `@alecmocatta` who reported many of the bugs above; would be great if you could help with the tests e.g. by providing some small examples I could try.
r? `@oli-obk`
bors added a commit that referenced this issue Sep 12, 2020
Redo cargo-miri logic

This rewrite the cargo-miri logic for running the requested crate(s) following what we outlined in #739: `cargo miri run/test $FLAGS` (almost) literally invokes `cargo run/test $FLAGS` but with some environment variables set so that we can control what happens:
* `RUSTC_WRAPPER` is set so that we get invoked instead of `rustc`. We use that power to mess with the flags being used for the build (things to be interpreted by Miri use a different sysroot), and when we are detecting a binary crate meant to be run by Miri, we grab the info we care about and put it into a JSON file for later use.
* `CARGO_TARGET_$TARGET_RUNNER` is set so what we get invoked when cargo wants to run a binary. At that point we take that JSON info from before and use it to invoke Miri.

Overall this works great! We get all sorts of cargo magic for free, and do not even need `cargo-metadata` any more. There's one annoying point though, which I have not managed to entirely work around yet: this means we are doing a full build, not just a check-build. Given that our sysroot is MIR-only, I was surprised that this even worked, but still -- this means we are doing more work than we should. So I also added some patching of arguments to make sure `--emit` does not contain `link`, and then more patching was required of the `--extern` flags for the binary because those referenced the `.rlib` files but now only `.rmeta` exists, and that is still not fully working because cargo seems to expect those `.rmeta` files and now triggers a rebuild each time as those files are still missing. My current plan is to make our wrapper create some empty dummy files with the right names, but the amount of hacks we are stacking on top of each other here is getting worrysome.^^ `@ehuss` your input would be welcome on this issue.

Due to re-using cargo more literally, this also changes flag parsing to match `cargo`. So `-Zmiri` flags now have to be passed via an environment variable (Cc #1416).

This PR is not ready yet, but the parts that are there I think can be reviewed already. TODO:
* [x] [Fix Windows](#1540 (comment)).
* [x] Figure out how we can do check-only builds without the rebuild problem above. I am also worried about cases where `build.rs` script might detect check-only builds and then do less work; I think some crates in rustc are doing that and if this is a thing in the wider ecosystem we need to find a way to support this as well.
* [x] Currently cargo runs doctests as well, and they are not run in Miri. We should at least figure out a way to not run them at all (resolving #584 is left for a future PR).
* [x] For some time, detect the old way of passing `-Zmiri` flags and warn that this will need updating. For some simple situations we can probably make it still support the old way, but I plan to remove those hacks after a bit. This is just to give people and me time to go around and send PRs to all projects that use Miri on CI, and update their use of the flags.
* [x] Add a test for stdin handling (#1505). This should work now but we should be sure.
* [x] Add a test for cargo env vars (#1515).
* [x] Check if #1516 is resolved.
* [x] Check if #1001 and #1514 are resolved.
* [x] Check if #1312 is resolved (not sure if it is wort adding a test).
* [x] Check if #1512 is resolved (not sure if it is wort adding a test).

Fixes #700.
Fixes #739.
Fixes #1001.
Fixes #1312 (without a test, as we run without cargo's stdin/stdout wrapping now, as the test for stdin confirms).
Fixes #1416.
Fixes #1505.
Fixes #1512 (without a test, as cargo now does all that handling anyway, which various other tests confirm).
Fixes #1514.
Fixes #1516.

Cc `@alecmocatta` who reported many of the bugs above; would be great if you could help with the tests e.g. by providing some small examples I could try.
r? `@oli-obk`
bors added a commit that referenced this issue Sep 12, 2020
Redo cargo-miri logic

This rewrite the cargo-miri logic for running the requested crate(s) following what we outlined in #739: `cargo miri run/test $FLAGS` (almost) literally invokes `cargo run/test $FLAGS` but with some environment variables set so that we can control what happens:
* `RUSTC_WRAPPER` is set so that we get invoked instead of `rustc`. We use that power to mess with the flags being used for the build (things to be interpreted by Miri use a different sysroot), and when we are detecting a binary crate meant to be run by Miri, we grab the info we care about and put it into a JSON file for later use.
* `CARGO_TARGET_$TARGET_RUNNER` is set so what we get invoked when cargo wants to run a binary. At that point we take that JSON info from before and use it to invoke Miri.

Overall this works great! We get all sorts of cargo magic for free, and do not even need `cargo-metadata` any more. There's one annoying point though, which I have not managed to entirely work around yet: this means we are doing a full build, not just a check-build. Given that our sysroot is MIR-only, I was surprised that this even worked, but still -- this means we are doing more work than we should. So I also added some patching of arguments to make sure `--emit` does not contain `link`, and then more patching was required of the `--extern` flags for the binary because those referenced the `.rlib` files but now only `.rmeta` exists, and that is still not fully working because cargo seems to expect those `.rmeta` files and now triggers a rebuild each time as those files are still missing. My current plan is to make our wrapper create some empty dummy files with the right names, but the amount of hacks we are stacking on top of each other here is getting worrysome.^^ `@ehuss` your input would be welcome on this issue.

Due to re-using cargo more literally, this also changes flag parsing to match `cargo`. So `-Zmiri` flags now have to be passed via an environment variable (Cc #1416).

This PR is not ready yet, but the parts that are there I think can be reviewed already. TODO:
* [x] [Fix Windows](#1540 (comment)).
* [x] Figure out how we can do check-only builds without the rebuild problem above. ~~I am also worried about cases where `build.rs` script might detect check-only builds and then do less work; I think some crates in rustc are doing that and if this is a thing in the wider ecosystem we need to find a way to support this as well.~~ (postponed that until we have a concrete example)
* [x] Currently cargo runs doctests as well, and they are not run in Miri. We should at least figure out a way to not run them at all (resolving #584 is left for a future PR).
* [x] For some time, detect the old way of passing `-Zmiri` flags and warn that this will need updating. For some simple situations we can probably make it still support the old way, but I plan to remove those hacks after a bit. This is just to give people and me time to go around and send PRs to all projects that use Miri on CI, and update their use of the flags.
* [x] Add a test for stdin handling (#1505). This should work now but we should be sure.
* [x] Add a test for cargo env vars (#1515).
* [x] Check if #1516 is resolved.
* [x] Check if #1001 and #1514 are resolved.
* [x] Check if #1312 is resolved (not sure if it is wort adding a test).
* [x] Check if #1512 is resolved (not sure if it is wort adding a test).

Fixes #700.
Fixes #739.
Fixes #1001.
Fixes #1312 (without a test, as we run without cargo's stdin/stdout wrapping now, as the test for stdin confirms).
Fixes #1416.
Fixes #1505.
Fixes #1512 (without a test, as cargo now does all that handling anyway, which various other tests confirm).
Fixes #1514.
Fixes #1516.

Cc `@alecmocatta` who reported many of the bugs above; would be great if you could help with the tests e.g. by providing some small examples I could try.
r? `@oli-obk`
@bors bors closed this as completed in ce29fbf Sep 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cargo Area: affects the cargo wrapper (cargo miri) C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants