Rust 生態系統中的許多工具假設您使用的是 Cargo。如果是這類工具,由於我們的建構作業沒有對應項目,可以使用產生 Cargo.toml
檔案的公用程式。您可以使用 Cargo 自行執行 (例如 cargo check
)。
這項功能是由志工維護。GN 和 Cargo 的設計有部分不相符,可能會導致產生的 Cargo.toml
檔案完全無法運作,或需要手動調整。因此,我們「不」正式支援福奇亞樹中的貨運,因為設施可能會不時發生。
正在產生 Cargo.toml
個檔案
為了根據 GN 的建構圖產生貨物檔案,請將 --cargo-toml-gen
新增至 fx set
指令,或將 //build/rust:cargo_toml_gen
目標新增至 $OUT_DIR/args.gn
的 universe_package_labels
。這會為 gn gen
新增幾秒鐘。更新設定後,請務必執行完整的 fx build
:
fx set PRODUCT.BOARD --cargo-toml-gen <other fx args>
fx build
注意:如果需要 Cargo.toml
才能完成 fx build
(例如需要執行 cbindgen
以為 Rust Crate 產生新的 C 繫結),您可能需要改用 //build/rust:cargo_toml_gen
建構目標。這個目標只會建構 Cargo.toml
檔案。
大多數編輯器會要求 Cargo.toml
檔案位於 src/
目錄旁的位置。您可以使用下列指令產生這些檔案的符號連結,其中 //foo/path/to/target:some_label
是您要處理的 GN 目標:
fx gen-cargo foo/path/to/target:some_label
注意:上述方法不適用於 rustc_staticlib
目標,例如用於產生 C 繫結的 Rust Crate 通常會使用 rustc_staticlib
目標範本。如果是 rustc_staticlib
目標,請改用下列指令。
fx gen-cargo foo/path/to/target:_some_label_rustc_static
請注意,這個標籤必須指向 rustc_...
GN 範本 (而非 Fuchsia 套件或其他 GN 目標)。例如:
rustc_binary("some_label") {
...
}
產生 .cargo/config 檔案
部分外掛程式需要 .cargo/config
檔案,才能讓 Cargo 為 Fuchsia 正確運作 (例如執行 cargo check
)。如要輕鬆產生這個檔案,請使用 fargo
工具。
- 安裝 Rustup
執行下列指令,設定
rustup
以使用 Fuchsia Rust 工具鍊:rustup toolchain link fuchsia $($FUCHSIA_DIR/scripts/youcompleteme/paths.py VSCODE_RUST_TOOLCHAIN) rustup default fuchsia
按照 Fargo 的入門指南操作,在
$FUCHSIA_DIR
中複製並安裝fargo
工具。建立設定:
cd $FUCHSIA_DIR && fargo write-config # Note the caveats about changing architecture in the fargo readme # https://fuchsia.googlesource.com/fargo/#creating-a-cargo_config