573 字
3 分鐘
Rust 工具鏈
Rust 的工具鏈 rust/install
在 rust 中主要使用的工具鏈有這些,透過這些工具進行開發與編譯:
rustup: 自更新、安裝、管理 Rust 工具鏈的工具cargo: Rust 的構建工具,類似於npm,pip,composer…rustc: Rust 編譯器,將 Rust 編譯成可執行檔(binary)/庫(library)
安裝 Rust
透過
rustup安裝 Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# 安裝完後確定是否安裝成功
# (如果出現 command not found, 請重新登入 shell 環境或是 source 自己的環境)
rustc --version透過 cargo 建立專案 (熟悉的 Hello World)
通常情況下會使用 cargo 建立出專案,並且使用其進行專案開發。
# 建立專案 (可執行) -> 預設就是可執行的專案,所以可以省略 --bin
cargo new hello_binary --bin
# 建立庫
cargo new hello_lib --lib
# 進入專案目錄
cd hello_binary
# 🎇 執行當前專案 -> 此時應該會看到 Hello, world!
cargo run
# 編譯專案。 `--release` 會進行最佳化的編譯
# 編譯後會放在 target/release/ 目錄下
cargo build --release更新 Rust
自更新 Rust 工具鏈
rustup update移除 Rust
rustup self uninstall安裝指定版本的 Rust
rustup install 1.50.0切換 Rust 版本
rustup default 1.50.0列出所有安裝的 Rust 版本
rustup show主要版本有幾種 Rust 的開發流程與發佈管道
Rust 開發團隊有個發布時刻表(train schedule)。
發佈採用軟體發佈火車模型 (software release train model)。
這也被用於 Cisco IOS 與其他軟體專案。 Rust 有三個發佈管道 (Release Channels).
- stable (穩定版)
→ 每隔 6 週會推進一次,這些版本是為了讓開發者可以使用的穩定版本。
- beta (準穩定版/測試版)
→ 每隔 6 週會推進一次,這些版本是為了讓開發者可以提前測試新功能。並且在穩定版發佈前進行測試。
- nightly (每夜版)
→ 每天晚上都會產生新的每夜版,而這些發佈版本均由基礎設施自動產生。(排程自動進行推進)
Rust 切換發佈管道 (global 全域)
全域調整使用版本:
rustup default {stable|beta|nightly}
rustup default stable
rustup updateRust 切換發佈管道 (by 專案)
在(各別)專案目錄中指定使用的 Rust 的版本:
rustup override set {stable|beta|nightly}
rustup override set nightly
