Working example of Bazel + IntelliJ + Rust integration, allowing for all of IntelliJ's Rust code completion, navigation and refactoring features to work in a Bazel project.
Please note: This video was taken from a previous version of the integration, where Cargo.toml generation worked differently, but the end result remains unchanged.
bazel-intellij-rust-demo.mov
This integration is achieved using a fork of the Rust IntelliJ plugin:
As well as a Cargo project generator that converts Bazel to Cargo:
The Rust plugin is built to work with Cargo projects, so to make it work with Bazel projects, we need to generate the Cargo manifest files using Bazel, which we do in our Cargo project generator.
External crates from https://crates.io are supported using cargo-raze - see https://github.com/vaticle/bazel-intellij-rust-example/tree/master/dependencies/crates for a usage example.
The modified Rust plugin is able to detect the Rust toolchain in the Bazel sandbox, as well as the standard library sources.
Currently the plugins have only been tested against IntelliJ IDEA 2021.3 UE, IntelliJ IDEA 2022.2 UE and CLion 2022.2. Further changes may be needed to ensure compatibility with other environments. It is unlikely that the Cargo project generator runs on Windows.
The Rust toolchain paths are largely hardcoded - it would be preferable to load them via Bazel commands run in the Rust plugin.
The overall architecture of the Bazel support in intellij-rust
is suboptimal, and warrants a proper discussion.
We need support to bring these plugins to production quality, via any of the following means:
- Submit a PR to https://github.com/vaticle/intellij-rust;
- We use Discord as our primary communications channel: https://vaticle.com/discord