rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

target selection for per-project rust-analyzer.toml does not seem to work

Open J-Pai opened this issue 5 months ago • 2 comments

rust-analyzer version: rust-analyzer 1.96.0 (ac68faa 2026-05-25)

rustc version: rustc 1.96.0 (ac68faa20 2026-05-25)

editor or extension: neovim v0.12.2

relevant settings:

rust-analyzer.toml at root of project:

[cargo]
allTargets = false
target = "wasm32-unknwon-unknown"

code snippet to reproduce:

#[cfg(target_arch = "wasm32")]
fn main() {
}
  • Neovim configuration has an inline check that tells me the wasm32 target_arch is disabled. Downstream dependencies also do not have this feature enabled.

  • Does not seem like there are bugs tracking the fact that the target configuration does not appear to work in cargo.

  • Other options seem to be fine (e.g. check configurations), but anything underneath cargo seems to be ignore.

  • Would be nice to get this feature working (or make a note that it is not supported in https://rust-analyzer.github.io/book/configuration.html.

  • Working a in a project with mixed targets (wasm32 for frontend, aarch64 for backend) pretty much requires the ability to provide a per-project or per-crate rust-analyzer.toml file so code completion will work properly.

J-Pai avatar Jun 27 '26 22:06 J-Pai

True, the cargo.target setting is global.

Work on rust-analyzer.toml is not complete, but I'm not sure this is something we can ever support: the target has to be known before we know the crate graph, because building it requires information from Cargo that needs the target. So it cannot be per-crate.

What might work (but I'm not sure if it works today), is to duplicate the workspace with different targets. This will consume duplicate resources of course, but it should be possible to support this within the same client, assuming the crates are disjoint and workspaces are explicitly specified.

ChayimFriedman2 avatar Jun 28 '26 21:06 ChayimFriedman2

Ah. I always assumed rust-analyzer had a separate build config / view of the world.

Either way, would be cool to get rust-analyzer set up in a more isolated fashion. It's help for folks who work on embedded projects.

J-Pai avatar Jun 28 '26 22:06 J-Pai