Rust IDE 設定

Android 中的 Rust IDE 支援功能仰賴 rust-analyzerrust-analyzer 是 IDE 用來瞭解程式碼結構,並提供程式碼補全或跳至定義等功能的語言伺服器通訊協定。開始前,請搜尋 rust-analyzer 快速入門說明文件,瞭解如何設定 IDE 或編輯器以使用 rust-analyzer 通訊協定。

Android 提供的設定可讓 rust-analyzer 瞭解如何建構 Android Rust 模組。這項資訊已在 Soong 產生的 rust-project.json 檔案中說明。對於 Visual Studio Code 等部分 IDE,此檔案是由 aidegen 使用 -l r 選項引數 (用於選取 Rust 做為語言) 產生。如果您使用其他 IDE,請使用下列程式碼手動產生 rust-project.json 檔案:

// 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

rust-analyzer 的預先建構穩定版可在樹狀結構中取得,位於 prebuilts/rust/linux-x86/stable/rust-analyzer