Rust IDE 設置

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

Android 提供了使rust-analyzer能夠了解 Android Rust 模塊是如何構建的配置。這在宋生成的文件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

prebuilts/rust/linux-x86/stable/rust-analyzer在樹中提供了一個預構建的穩定版本的rust-analyzer -analyzer。