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

"Unable to install toolchain" on GitHub Actions Windows runner #1036

Open
robamler opened this issue Oct 20, 2024 · 7 comments
Open

"Unable to install toolchain" on GitHub Actions Windows runner #1036

robamler opened this issue Oct 20, 2024 · 7 comments

Comments

@robamler
Copy link

Running cargo msrv check from a github workflow (aka github action) on the windows-latest image results in the following error message:

error: could not create link from 'C:\Users\runneradmin/.cargo\bin\rustup.exe' to 'C:\Users\runneradmin/.cargo\bin\cargo.exe'

The same command works without any issues on github's ubuntu-latest and macos-latest images.

It seems like there's an issue with the file separators: the path C:\Users\runneradmin/.cargo\bin\rustup.exe mixes forward and backward slashes. This would also explain why the error only occurs on windows.

How to reproduce

More precisely, my workflow file runs the following command:

cargo msrv --log-level debug --output-format json verify -- cargo check --all-features

Here,

  • the --log-level and --output-format are set so that cargo msrv doesn't suppress its output (cargo msrv doesn't consider github's action environment as a terminal, so it would default to not printing any output or error messages); and
  • the custom check command (-- cargo check --all-features) is specific to my use case, but I don't think it makes a difference here since cargo msrv never even gets past toolchain installation on windows anyway.

The full output from this command on windows is:

{"type":"meta","instance":"cargo-msrv","version":"0.16.1","sha_short":null,"target_triple":"x86_64-pc-windows-msvc","cargo_features":"default,rust_releases_dist_source","rustc":"1.81.0"}
{"type":"subcommand_init","subcommand_id":"verify"}
{"type":"fetch_index","source":"rust_changelog","scope":{"id":0,"marker":"start"}}
{"type":"fetch_index","source":"rust_changelog","scope":{"id":0,"marker":"end"}}
{"type":"check_toolchain","toolchain":{"version":"1.75.0","target":"x86_64-pc-windows-msvc","components":[]},"scope":{"id":1,"marker":"start"}}
{"type":"setup_toolchain","toolchain":{"version":"1.75.0","target":"x86_64-pc-windows-msvc","components":[]},"scope":{"id":2,"marker":"start"}}
{"type":"setup_toolchain","toolchain":{"version":"1.75.0","target":"x86_64-pc-windows-msvc","components":[]},"scope":{"id":2,"marker":"end"}}
{"type":"check_toolchain","toolchain":{"version":"1.75.0","target":"x86_64-pc-windows-msvc","components":[]},"scope":{"id":1,"marker":"end"}}
{"type":"terminate_with_failure","reason":{"description":"Unable to install toolchain '1.75.0-x86_64-pc-windows-msvc', rustup reported:\n    \u001b[2minfo: syncing channel updates for '1.75.0-x86_64-pc-windows-msvc'\n    info: latest update on 2023-12-28, rust version 1.75.0 (82e1608df 2023-12-21)\n    info: downloading component 'cargo'\n    info: downloading component 'rust-std'\n    info: downloading component 'rustc'\n    info: installing component 'cargo'\n    info: installing component 'rust-std'\n    info: installing component 'rustc'\n    info: checking for self-update\n    warning: tool `rust-analyzer` is already installed, remove it from `C:\\Users\\runneradmin/.cargo\\bin`, then run `rustup update` to have rustup manage this tool.\n    warning: tool `rustfmt` is already installed, remove it from `C:\\Users\\runneradmin/.cargo\\bin`, then run `rustup update` to have rustup manage this tool.\n    warning: tool `cargo-fmt` is already installed, remove it from `C:\\Users\\runneradmin/.cargo\\bin`, then run `rustup update` to have rustup manage this tool.\n    error: could not create link from 'C:\\Users\\runneradmin/.cargo\\bin\\rustup.exe' to 'C:\\Users\\runneradmin/.cargo\\bin\\cargo.exe'\u001b[0m"}}

Here's a pretty-printed version of the message in the last JSON line:

Unable to install toolchain '1.75.0-x86_64-pc-windows-msvc', rustup reported:
info: syncing channel updates for '1.75.0-x86_64-pc-windows-msvc'
info: latest update on 2023-12-28, rust version 1.75.0 (82e1608df 2023-12-21)
info: downloading component 'cargo'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: installing component 'cargo'
info: installing component 'rust-std'
info: installing component 'rustc'
info: checking for self-update
warning: tool `rust-analyzer` is already installed, remove it from `C:\\Users\\runneradmin/.cargo\\bin`, then run `rustup update` to have rustup manage this tool.
warning: tool `rustfmt` is already installed, remove it from `C:\\Users\\runneradmin/.cargo\\bin`, then run `rustup update` to have rustup manage this tool.
warning: tool `cargo-fmt` is already installed, remove it from `C:\\Users\\runneradmin/.cargo\\bin`, then run `rustup update` to have rustup manage this tool.
error: could not create link from 'C:\\Users\\runneradmin/.cargo\\bin\\rustup.exe' to 'C:\\Users\\runneradmin/.cargo\\bin\\cargo.exe'
@foresterre
Copy link
Owner

foresterre commented Oct 21, 2024

Yikes! Thanks for the report!

It's a bit odd, since cargo-msrv's integration tests also run on Windows, although they're started via cargo run instead of directly.

I also use windows as one of my development platforms and also didn't see issues there.

I think I'll investigate this further by adding the windows platform to the separate msrv action on the ci, which acts as an e2e test.

I wouldn't be surprised if it's a path problem, only that I've not seen it before.

foresterre added a commit that referenced this issue Oct 25, 2024
In #1036, an issue was reported which reported toolchain install issues, possibly caused by path separator issues on windows (ubuntu and mac seem to be fine).

With this commit, we add a run of cargo-msrv as an e2e test to our own CI on windows and mac while we're at it.
Previously, we would only run on ubuntu; the e2e test was a side-effect of checking our own MSRV.
We do have tests which run via the 'cargo run' vehicle and temporary directories, but that's not as sandboxed as this approach.

Hopefully, running all primary platforms will (1) give an indication of whether #1036 is indeed a cargo-msrv issue, and (2) prevent similar bugs in the future.
@foresterre
Copy link
Owner

foresterre commented Oct 25, 2024

I am indeed able to reproduce this issue:

image

Thanks for the detailed report; I'll see what I can do.

@foresterre
Copy link
Owner

Today I had access to a windows machine, which let me test the reported issue locally. As it turns out, on this machine, there were no issues. I'll try to fix the potential path problem as far as its in my hands (because the invalid path is used and reported by rustup after delegating to it).

@foresterre
Copy link
Owner

I did some testing, but the results are unsatisfying for now.

An observation I made, is that the path with the forward vs backward slash is not set by cargo-msrv, but by the rust toolchain install action (at least if you use dtolnay/rust-toolchain@stable):

https://github.com/foresterre/cargo-msrv/actions/runs/11695406885/job/32570778599?pr=1041#step:3:32

image

image

In addition, by default, Github actions uses powershell 7 (pwsh) on Windows, while dtolnay/rust-toolchain@stable uses bash (the env var will get inherited regardless):

image

@robamler
Copy link
Author

robamler commented Nov 6, 2024

Interesting. So maybe this should be fixed in dtolnay/rust-toolchain then? I'd be happy to file a pull request there with the necessary fixes, unless you'd prefer to do this yourself.

(I'm not sure how to fix it but my initial guess would be to change this line from

echo CARGO_HOME=${CARGO_HOME:-${{runner.os == 'Windows' && '$USERPROFILE' || '$HOME'}}/.cargo} >> $GITHUB_ENV

to something like

echo CARGO_HOME=${CARGO_HOME:-${{runner.os == 'Windows' && "$USERPROFILE\\" || "$HOME/"}}.cargo} >> $GITHUB_ENV

However, I haven't checked whether rustup even uses the same name (i.e., ".cargo") for this directory on windows. There also seem to be a few more hard-coded / path separators in dtolnay/rust-toolchain that aren't gated by an OS check, so maybe they should be fixed too. I'm also not sure if this breaks backward compatibility of dtolnay/rust-toolchain on windows runners.)

@foresterre
Copy link
Owner

foresterre commented Nov 6, 2024

I don't know whether this is the solution. I tried setting shell: bash in the workflow to no avail. I also tried overwriting the CARGO_HOME environment value for Windows in the workflow, but that didn't work. According to actions/runner#1126 it is not possible to unset env. vars in workflows.

One thing I still want to try next is to simply run rustup toolchain install <x> and rustup component add <y> in the workflow, like how cargo-msrv would. If that fails, then this isn't a cargo-msrv specific issue.

An idea I still have, is to try to work around the issue next by probing rustup first for prior installed toolchains, targets and components.

Currently, I just say "add toolchain x" or "component y" and this works for all platforms because if they're already present, rustup still returns with exit code 0.

This is something I intended to do anyways at some point, because it also allows you to optionally clean up extra toolchains after cargo-msrv execution

@foresterre
Copy link
Owner

foresterre commented Nov 9, 2024

It is unlikely a dtolnay/rust-toolchain issue. Some more testing revealed that running the failing step manually works just fine:

2024_11_10_firefox_722_310_ZwQKPjHX8T

Really the only difference in output is the line error: could not create link from 'C:\\Users\\runneradmin/.cargo\\bin\\rustup.exe' to 'C:\\Users\\runneradmin/.cargo\\bin\\cargo.exe'.

I'll have to dive a bit into cargo's source code for what that means exactly, but I guess it has something to do with symlinks.

It also seems to be more and more unlikely that this is a / vs \ path separator issue, 🤷.

@foresterre foresterre changed the title "Unable to install toolchain" on windows (seems like a / vs. \ issue) "Unable to install toolchain" on windows Nov 10, 2024
@foresterre foresterre changed the title "Unable to install toolchain" on windows "Unable to install toolchain" on GitHub Actions Windows runner Nov 10, 2024
foresterre added a commit that referenced this issue Nov 10, 2024
In #1036, an issue was reported which reported toolchain install issues, possibly caused by path separator issues on windows (ubuntu and mac seem to be fine).

With this commit, we add a run of cargo-msrv as an e2e test to our own CI on windows and mac while we're at it.
Previously, we would only run on ubuntu; the e2e test was a side-effect of checking our own MSRV.
We do have tests which run via the 'cargo run' vehicle and temporary directories, but that's not as sandboxed as this approach.

Hopefully, running all primary platforms will (1) give an indication of whether #1036 is indeed a cargo-msrv issue, and (2) prevent similar bugs in the future.
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

No branches or pull requests

2 participants