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

RUSTUP_TOOLCHAIN override prevents rustup overrides from being respected #16932

Closed
makspll opened this issue Mar 23, 2024 · 3 comments
Closed
Labels
C-bug Category: bug

Comments

@makspll
Copy link

makspll commented Mar 23, 2024

As seen here:
https://github.com/rust-lang/rust-analyzer/blob/e265e3d5189513c42d037999d41a696369af9388/crates/flycheck/src/lib.rs#L408C1-L408C80

With the given settings.json:

    "rust-analyzer.check.invocationStrategy": "per_workspace",
    "rust-analyzer.check.invocationLocation": "workspace",
    "rust-analyzer.check.overrideCommand": [
        "cargo",
        "clippy",
        "--message-format=json"
    ],
    "rust-analyzer.linkedProjects": [
        "./crates/another_crate/Cargo.toml",
        "Cargo.toml"
    ],

I believe cargo clippy will be run from the root instead of the workspace location, meaning that rustup overrides are not respected, and hence checking fails for projects using different toolchains in each linked project.

Is there any work around?

@makspll makspll added the C-bug Category: bug label Mar 23, 2024
@makspll
Copy link
Author

makspll commented Mar 23, 2024

Actually it looks like it's being run in the correct directory, BUT the toolchain is being overidden:

2024-03-23T15:01:44.709609Z  INFO project_model::build_scripts: Running build scripts in /<PATH>/ RA_RUSTC_WRAPPER="1" RUSTC_WRAPPER="<PATH>/server/rust-analyzer" RUSTUP_TOOLCHAIN="/<PATH>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu" "/<PATH>/bin/cargo" "check" "--quiet" "--workspace" "--message-format=json" "--manifest-path" "/<PATH>/crates/crate/Cargo.toml" "--all-targets"

@makspll makspll changed the title rust analyzer check invocation strategy not working RUSTUP_TOOLCHAIN override prevents rustup overrides from being respected Mar 24, 2024
@makspll
Copy link
Author

makspll commented Mar 24, 2024

I've investigated further, the root issue can be seen here:

    "rust-analyzer.linkedProjects": [
        "./crates/bevy_api_gen/Cargo.toml",
        "Cargo.toml"
    ],
    "rust-analyzer.check.invocationStrategy": "per_workspace",
    "rust-analyzer.check.invocationLocation": "workspace",
    "rust-analyzer.check.overrideCommand": [
        "/home/makspll/git/bevy_mod_scripting/check.sh"
    ]

check.sh:

echo "invoked '$0' at '$PWD' with args: '$@', using toolchain '$(rustup show active-toolchain)'" >> /home/makspll/git/bevy_mod_scripting/log
cargo clippy --message-format=json

log:

invoked '/home/makspll/git/bevy_mod_scripting/check.sh' at '/home/makspll/git/bevy_mod_scripting' with args: '', using toolchain 'stable-x86_64-unknown-linux-gnu (environment override by RUSTUP_TOOLCHAIN)'
invoked '/home/makspll/git/bevy_mod_scripting/check.sh' at '/home/makspll/git/bevy_mod_scripting/crates/bevy_api_gen' with args: '', using toolchain 'stable-x86_64-unknown-linux-gnu (environment override by RUSTUP_TOOLCHAIN)'

You can see the rustup toolchain overrides are being overridden via the RUSTUP_TOOLCHAIN env variable, I am not sure why it's being set here

@Veykril
Copy link
Member

Veykril commented Mar 25, 2024

See #16563, this is intentional. We want to make sure that we invoke the correct binaries for a given discovered sysroot of a workspace.

@makspll makspll closed this as completed May 19, 2024
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

No branches or pull requests

2 participants