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

fix ./x.py test miri #2407

Closed
wants to merge 7 commits into from
Closed

fix ./x.py test miri #2407

wants to merge 7 commits into from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jul 21, 2022

Ok, this one works now. I had to manually remove .cargo/bin from my path to reproduce the rustc failure, and then figure out a few shenanigans around how cargo forwards arguments.

CONTRIBUTING.md Outdated Show resolved Hide resolved
@@ -668,7 +668,10 @@ fn phase_cargo_miri(mut args: env::Args) {
"WARNING: Ignoring `RUSTC` environment variable; set `MIRI` if you want to control the binary used as the driver."
);
}
cmd.env_remove("RUSTC");

if env::var_os("RUSTC_STAGE").is_none() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment. Note the comment above:

Having both RUSTC_WRAPPER and RUSTC set does some odd things, so let's avoid that.

@@ -1181,6 +1190,13 @@ fn main() {
let binary = Path::new(arg);
if binary.exists() {
assert!(!arg.starts_with("--")); // not a flag
if let Some(rustc) = std::env::var_os("RUSTC") {
if rustc == arg {
// In bootstrap we can't rely on rustc just being named rustc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh yeah I think this is exactly why we did env_remove("RUSTC") above. I'm a bit worried we might get some weird mixup here...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without RUSTC cargo would call rustc which doesn't exist on rust's CI. It needs to use the rustc set in RUSTC by rust's build system, not the system rustc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is that we need to be able to specify a specific rustc with the RUSTC env var, as cargo just invokes the env var or rustc when doing -vV. Unfortunately we can only set it to a binary, not a script or similar.

Copy link
Member

@RalfJung RalfJung Jul 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without RUSTC cargo would call rustc which doesn't exist on rust's CI. It needs to use the rustc set in RUSTC by rust's build system, not the system rustc.

cargo-miri should never invoke rustc. It should always only invoke miri itself, including when it needs rustc. That's what all that MIRI_BE_RUSTC stuff is for.

Copy link
Member

@RalfJung RalfJung Jul 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to invoke both miri and rustc but that leads to strange errors very quickly when those two are not exactly in sync. It's much better to ensure that everything goes through the same binary, miri, which can do both compilation and interpretation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cargo just invokes the env var or rustc when doing -vV

Oh wait it ignores RUSTC_WRAPPER for that? That sounds like a cargo bug to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might need something like this

miri/cargo-miri/bin.rs

Lines 480 to 486 in 88ad9ca

let cargo_miri_path = std::env::current_exe().expect("current executable path invalid");
if env::var_os("RUSTC_STAGE").is_some() {
command.env("RUSTC_REAL", &cargo_miri_path);
} else {
command.env("RUSTC", &cargo_miri_path);
}
command.env("MIRI_CALLED_FROM_XARGO", "1");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure how that helps. we're not invoking the bootstrap rustc thingy that forwards to RUSTC_REAL, if RUSTC is empty, cargo literally invokes rustc -vV

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait it ignores RUSTC_WRAPPER for that? That sounds like a cargo bug to me.

yea, I found no way to influence that binary other than via the RUSTC env var

Copy link
Member

@RalfJung RalfJung Jul 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah IMO that's definitely a cargo bug. Reported as rust-lang/cargo#10885.

I guess you could set RUSTC to the underlying Miri driver? For -vV that'll be fine and thanks to the RUSTC_WRAPPER all the other calls should end up in the right spot. Let's use an absolute canonical path for this so it should not be possible to have confusion in the phase selection logic in main.

cargo-miri/bin.rs Outdated Show resolved Hide resolved
cargo-miri/bin.rs Outdated Show resolved Hide resolved
@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 21, 2022

uuh... what happened to our CI, something seems to be out of disk space

@RalfJung
Copy link
Member

uuh... what happened to our CI, something seems to be out of disk space

Seems to work again? At least the linux builder.

@RalfJung RalfJung changed the title Rustup fix ./x.py test miri Jul 21, 2022
Some("rustc") => phase_rustc(args, RustcPhase::Build),
// Work around a cargo bug where it ignores `RUSTC_WRAPPER`, so we get
// called ourselves and handle the special case for `rustc -vV`.
Some("-vV") => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tried this, cargo miri test in our test-cargo-miri failed because the libc build script invokes RUSTC --version...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh... it works in the ui test suite, I didn't check test-cargo-miri

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it fails that way on CI now

error: failed to run custom build command for libc v0.2.126

@bors
Copy link
Contributor

bors commented Jul 21, 2022

☔ The latest upstream changes (presumably #2409) made this pull request unmergeable. Please resolve the merge conflicts.

@oli-obk oli-obk closed this Jul 21, 2022
@RalfJung RalfJung deleted the rustup branch July 24, 2022 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants