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

Wrong PATH override on Windows #7475

Closed
sinkuu opened this issue Oct 3, 2019 · 6 comments · Fixed by #7482
Closed

Wrong PATH override on Windows #7475

sinkuu opened this issue Oct 3, 2019 · 6 comments · Fixed by #7482
Labels
C-bug Category: bug

Comments

@sinkuu
Copy link
Contributor

sinkuu commented Oct 3, 2019

EDIT: See #7475 (comment) for better description. Thank you @ehuss!

Problem

This is a regression introduced in the recent cargo update in rust repo.

On windows, within test processes run by cargo test, PATH variable now looks like:

C:\projects\rust-clippy\clippy_dev\target\debug\deps;C:\projects\rust-clippy\clippy_dev\target\debug;C:\Users\appveyor\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\bin;C:\Users\appveyor\.cargo\bin;C:\Users\appveyor\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\bin;.....

The first three paths are added by cargo. Note that nightly-x86_64-pc-windows-msvc\bin is now preferred than .cargo\bin.

In clippy CI, cargo +nightly fmt is invoked during integration test. This have been worked until the recent update. Today, the plain cargo binary from nightly-x86_64-pc-windows-msvc\bin is run instead of the rustup's one in .cargo\bin that supports +toolchain_name argument.

Steps

See recent failed builds in https://ci.appveyor.com/project/rust-lang-libs/rust-clippy

Clippy's CI involves two versions of toolchains: nightly and master.

  1. cargo test (master) runs tests/fmt.rs integration test.
  2. tests/fmt.rs invokes cargo +nightly run on clippy_dev. This succeeds because master does not have cargo. Now we are in nightly environment.
  3. clippy_dev invokes cargo +nightly fmt. This fails because nightly has cargo.

Possible Solution(s)

.cargo\bin should always be preferred (come first in PATH variable).

Notes

Output of cargo version:

cargo 1.40.0-nightly (8b0561d68 2019-09-30)

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Oct 3, 2019

It seems the bug is present since the latest update of cargo in the rustc repo:
rust-lang/rust@e1d9f82

@Eh2406
Copy link
Contributor

Eh2406 commented Oct 3, 2019

Is there some cargo test we can add to make sure this doesn't happen again? If so we can use it to bisec to find the what broke it.

@mati865
Copy link
Contributor

mati865 commented Oct 3, 2019

It's reproducible on Windows (both msvc and gnu) by running cargo +nightly-2019-10-02 test on rust-lang/rust-clippy@737f0a6

It's far from being minimal though.

@ehuss
Copy link
Contributor

ehuss commented Oct 3, 2019

The issue is due to #7425, though I'm not yet sure I understand it fully.

@ehuss
Copy link
Contributor

ehuss commented Oct 3, 2019

@alexcrichton I'm running out of energy for today, but I'll try to distill what is happening and see if you have some ideas.

Problem: Due to #7425, on Windows, cargo test now sets the PATH with …\toolchains\$HOST\bin. Previously it would be …\toolchains\$HOST\lib\rustlib\$HOST\lib. This causes a problem for anyone running commands like cargo +nightly from within a test because the bin path is the actual cargo, not the rustup one in ~/.cargo/bin. I also imagine there might be issues with dylib linking to target dylibs, but I'm not sure how to trigger that. I believe the old behavior is more correct, although the difference is subtle.

Cause: Previously, BuildContext::target_info would be populated as-if --target $HOST was set. Now, BuildContext::target_info is an empty HashMap. The result is that Compilation::target_dylib_path is set to the host dylib path (…/bin). Tests use target_process and this dylib path is populated here.

Possible solution? I was thinking maybe BuildContext could populate target_info with a $HOST entry if --target is not specified. Compilation::target_dylib_path would need to use this host entry. It feels kinda messy, so there's probably a more elegant solution.

bors added a commit to rust-lang/rust-clippy that referenced this issue Oct 4, 2019
Workaround cargo issue on appveyor

Use absolute paths for `cargo` and `rustfmt` to workaround rust-lang/cargo#7475.

Appveyor passed on my fork: https://ci.appveyor.com/project/sinkuu/rust-clippy/builds/27870367
bors added a commit to rust-lang/rust-clippy that referenced this issue Oct 4, 2019
Workaround cargo issue on appveyor

Use absolute paths for `cargo` and `rustfmt` to workaround rust-lang/cargo#7475.

Appveyor passed on my fork: https://ci.appveyor.com/project/sinkuu/rust-clippy/builds/27870367

changelog: none
@alexcrichton
Copy link
Member

Thanks for the investigation @ehuss, that sounds spot-on to me! I've posted #7482 which has the same shape of solution

bors added a commit that referenced this issue Oct 4, 2019
Fix wrong directories in PATH on Windows

This fixes an accidental regression from #7425 where `PATH` was being
augmented on Windows with the wrong search path for target/host
libraries. This commit fixes the issue by simply always calculating the
host/target library paths for `TargetInfo`, and then we explicitly use
the same `TargetInfo` for filling out information in `Compilation`.

Closes #7475
@bors bors closed this as completed in 61188d7 Oct 4, 2019
@bors bors closed this as completed in #7482 Oct 4, 2019
jnbr added a commit to jnbr/cargo that referenced this issue Jan 14, 2020
This fixes a regression from rust-lang#7475 where the sysroot_target_libdir leaks into
the host libdir. This can cause problems when the dynamic linker does
not ignore the target libraries but tries to load them instead. This
happens for example when building on x86_64-musl for aarch64-musl.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants