bazelbuild / rules_rust

Rust rules for Bazel
https://bazelbuild.github.io/rules_rust/
Apache License 2.0
656 stars 423 forks source link

No matching toolchain when trying to run rust_analyzer #2160

Open xander-zitara opened 1 year ago

xander-zitara commented 1 year ago

I have rust_register_toolchains() in my WORKSPACE, and I've also tried register_toolchains(rust_analyzer_toolchain_repository()), but trying to run rust_analyzer like

bazel run @rules_rust//tools/rust_analyzer:gen_rust_project

gives this error

ERROR: Analysis of aspects '[@rules_rust//rust:defs.bzl%rust_analyzer_aspect] with parameters {} on //target' failed; build aborted: No matching toolchains found for types @rules_rust//rust:toolchain_type.
To debug, rerun with --toolchain_resolution_debug='@rules_rust//rust:toolchain_type'

Running with the suggested debug argument, it looks like a toolchain is indeed identified (I've removed rejected toolchains from the output):

INFO: ToolchainResolution: Target platform //linux_x86: Selected execution platform //linux_x86, type @bazel_tools//tools/cpp:toolchain_type -> toolchain @llvm_toolchain//:cc-clang-x86_64-linux, type @rules_rust//rust:toolchain_type -> toolchain @rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools//:rust_toolchain
INFO: ToolchainResolution: Target platform //linux_x86: Selected execution platform //linux_x86, type @rules_rust//rust/rust_analyzer:toolchain_type -> toolchain @rust_analyzer_1.72.0_tools//:rust_analyzer_toolchain, type @rules_rust//rust:toolchain_type -> toolchain @rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools//:rust_toolchain
INFO: ToolchainResolution: Target platform //linux_x86: Selected execution platform //linux_x86, type @bazel_tools//tools/cpp:toolchain_type -> toolchain @llvm_toolchain//:cc-clang-x86_64-linux, type @rules_rust//rust:toolchain_type -> toolchain @rust_linux_x86_64__x86_64-unknown-linux-gnu__stable_tools//:rust_toolchain

It would seem to me that the first INFO line here shows bazel does find a toolchain for the given type. Why doesn't rust_analyzer_aspect find this? Should I be concerned about some duplicate information being shown in this debug output?

akesling commented 5 months ago

I'm receiving the same error, but mine is complaining explicitly about a target (//router/test:test_route_server_linux) that has nothing to do with Rust (it's a go target). See my output in this gist.

I'm running this with Bazel 7.1.1. rules_rust is loaded via WORKSPACE (though pretty much everything else I use has moved over to bzlmod).