Rust IDE setup

The IDE support for Rust in Android relies on rust-analyzer. rust-analyzer is a language server protocol used by your IDE to understand the code structure and to provide features such as code completion or jump-to definition. Before you start, search the rust-analyzer QuickStart documentation for how to configure your IDE or editor to use the rust-analyzer protocol.

Android provides the configuration that enables rust-analyzer to understand how Android Rust modules are built. This is described in the Soong-generated file rust-project.json. For some IDEs such as Visual Studio Code, this file is generated by aidegen, using the -l r option arguments (to select Rust as the language). If you use a different IDE, manually generate a rust-project.json file with the following code:

// Generates rust-project.json in out/soong/
SOONG_GEN_RUST_PROJECT=1 m nothing
// Creates a symbolic link
ln -s $ANDROID_BUILD_TOP/out/soong/rust-project.json $ANDROID_BUILD_TOP

A prebuilt, stable version of rust-analyzer is available in-tree at prebuilts/rust/linux-x86/stable/rust-analyzer.