Rust IDE 設置

Android 中對 Rust 的 IDE 支援依賴於rust-analyzerrust-analyzer是 IDE 用來理解程式碼結構並提供程式碼完成或跳躍定義等功能的語言伺服器協定。在開始之前,請搜尋rust-analyzer 快速入門文檔,以了解如何配置 IDE 或編輯器以使用rust-analyzer協定。

Android 提供了讓rust-analyzer能夠了解 Android Rust 模組是如何建構的配置。這在 Soong 產生的檔案rust-project.json中進行了描述。對於某些 IDE(例如 Visual Studio Code),此檔案由aidegen使用-lr選項參數(選擇 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樹中找到。