rust-lang / rust-lang/rust-analyzer

Learn `cfg`s enabled in `build.rs`

Open
#14,452 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-cargo C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

Wasmtime enables cfg(compiler) when one of its compilers (Cranelift or, soon, Winch) is available and therefore JIT compilation is available. This cfg is enabled in build.rs when the cargo features for the underlying compilers are enabled. This is much easier and more future proof than writing out cfg(any(feature = "cranelift", feature = "winch")) all over the place, which is why things are done this way.

However, rust-analyzer does not treat code blocks guarded by #[cfg(compiler)] as enabled, and fails to do autocomplete/jump-to-def/etc within these regions, even though changing the cfg to the wordier cfg(any(...)) does work.

It would be nice if rust-analyzer looked at the cfgs defined by build.rs and enabled them for the project.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining the referenced crates/wasmtime/build.rs, especially how it enables cfg(compiler) from compiler features, and reproduce the rust-analyzer behavior inside those guarded regions. Compare this with cfg(any(feature = "cranelift", feature = "winch")) and determine how support should be validated. Done means rust-analyzer recognizes build.rs-defined cfgs for autocomplete and jump-to-definition.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.