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

rust-analyzer can invoke build scripts with RUSTC_BOOTSTRAP=1, wreaking havoc on feature detection #15057

Closed
SludgePhD opened this issue Jun 15, 2023 · 8 comments · Fixed by #16621
Labels
C-bug Category: bug

Comments

@SludgePhD
Copy link

rust-analyzer version: 0.3.1541

rustc version: rustc 1.70.0 (90c541806 2023-05-31)

relevant settings:

  • "rust-analyzer.cargo.buildScripts.useRustcWrapper": false,

Some crates (for instance anyhow and thiserror) determine whether they are being built by a supported nightly compiler by performing a trial compilation in their build script (think autotools). It seems like rust-analyzer will invoke build scripts while having RUSTC_BOOTSTRAP set (perhaps only under some circumstances), which makes those crates think they can use nightly features.

This appears to "work" in rust-analyzer, and "poisons" the build cache with the build script output. A later cargo run in the terminal will then reuse the build script output, and build the crate in question without having RUSTC_BOOTSTRAP set, leading to errors like this:

error[E0554]: `#![feature]` may not be used on the stable release channel
   --> /home/sludge/.cargo/registry/src/index.crates.io-6f17d22bba15001f/anyhow-1.0.71/src/lib.rs:214:32
    |
214 | #![cfg_attr(backtrace, feature(error_generic_member_access, provide_any))]
    |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on the stable release channel
   --> /home/sludge/.cargo/registry/src/index.crates.io-6f17d22bba15001f/anyhow-1.0.71/src/lib.rs:214:61
    |
214 | #![cfg_attr(backtrace, feature(error_generic_member_access, provide_any))]
    |                                                             ^^^^^^^^^^^

This has previously been reported in dtolnay/thiserror#192 as affecting users that have rust-analyzer.cargo.buildScripts.useRustcWrapper enabled (the default), while I have it disabled, so it seems that the setting may be a red herring and doesn't matter.

@SludgePhD SludgePhD added the C-bug Category: bug label Jun 15, 2023
@loynoir
Copy link

loynoir commented Oct 24, 2023

Got same error when dtolnay/thiserror and dtolnay/anyhow in dependency tree.

At the same time, I use sccache.

Try below does not working.

  • "rust-analyzer.cargo.buildScripts.useRustcWrapper": false

Then

  • disable RA

  • cargo clean

  • build

Now seems working correctly.

@lnicola
Copy link
Member

lnicola commented Oct 24, 2023

This should have been fixed in #12973 / #13010. anyhow works fine for me. Which versions are you using, and does it happen in a new project?

@loynoir
Copy link

loynoir commented Oct 24, 2023

Yes, recent project, maybe 1~2 weeks.

Old cache deleted, did not backup for reproduce.

@loynoir
Copy link

loynoir commented Oct 24, 2023

Now, I try with

        "rust-analyzer.cargo.buildScripts.useRustcWrapper": true,
        "rust-analyzer.rust.analyzerTargetDir": "{{RA_TARGET}}"

Guess in this way will not pollute real build cache forever.

Hope will not happen again.

@lnicola
Copy link
Member

lnicola commented Oct 24, 2023

It works fine for me without changing any settings. Are you sure you're not running a very old version of RA? And please try in an empty project (with anyhow as a dep).

@loynoir
Copy link

loynoir commented Oct 24, 2023

RA v0.3.1705.

FYI. I depend on X, and X deep dependency depends on dtolnay/thiserror and dtolnay/anyhow.

Background, rust newbie.

@Veykril
Copy link
Member

Veykril commented Jan 11, 2024

This should be fixed?

@txase
Copy link
Contributor

txase commented Feb 21, 2024

This issue isn't fixed yet. I posted PR #16621 to fix it.

bors added a commit that referenced this issue Feb 23, 2024
fix: Recompiles due to RUSTC_BOOTSTRAP

Some packages (e.g. thiserror) force a recompile if the value of the `RUSTC_BOOTSTRAP` env var changes. RA sets the variable to 1 in order to enable rustc / cargo unstable options. This causes flapping recompiles when building outside of RA.

Fixes #15057
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.

5 participants