Rust开发环境指南

XWOS RUST编译工具安装指南

Rust的开发工具

  • 根据官方指导安装 RUST
  • 切换镜像源
    • Ubuntu配置文件路径: ~/.cargo/config
    • Windows配置文件路进: C:\Users\用户名\.cargo\config
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = "ustc"

[source.ustc]
registry = "http://mirrors.ustc.edu.cn/crates.io-index"

[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

[source.sjtu]
registry = "http://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"
  • Ubuntu安装unstable版本
rustup install nightly
rustup +nightly target add thumbv8m.main-none-eabihf
rustup +nightly target add thumbv8m.main-none-eabi
rustup +nightly target add thumbv8m.base-none-eabi
rustup +nightly target add thumbv7m-none-eabi
rustup +nightly target add thumbv7em-none-eabihf
rustup +nightly target add thumbv7em-none-eabi
rustup +nightly target add thumbv6m-none-eabi
rustup +nightly target add riscv32imac-unknown-none-elf
rustup +nightly target add aarch64-unknown-none
rustup +nightly component add rust-src
  • Windows安装unstable版本

注意:Windows只支持使用 gnu 版的工具链

rustup install nightly-x86_64-pc-windows-gnu
rustup +nightly-x86_64-pc-windows-gnu target add thumbv8m.main-none-eabihf
rustup +nightly-x86_64-pc-windows-gnu target add thumbv8m.main-none-eabi
rustup +nightly-x86_64-pc-windows-gnu target add thumbv8m.base-none-eabi
rustup +nightly-x86_64-pc-windows-gnu target add thumbv7m-none-eabi
rustup +nightly-x86_64-pc-windows-gnu target add thumbv7em-none-eabihf
rustup +nightly-x86_64-pc-windows-gnu target add thumbv7em-none-eabi
rustup +nightly-x86_64-pc-windows-gnu target add thumbv6m-none-eabi
rustup +nightly-x86_64-pc-windows-gnu target add riscv32imac-unknown-none-elf
rustup +nightly-x86_64-pc-windows-gnu target add aarch64-unknown-none
rustup +nightly-x86_64-pc-windows-gnu component add rust-src

安装LSP

LSP(Language Server Protocol,语言服务协议)是新一代查看源码的工具。 Rust语言的LSP推荐使用 rust-analyzer

有两种安装方法:

  • 通过命令安装,可获得稳定版
rustup +nightly component add rust-analyzer
rustup +nightly component add rust-src
  • 通过源码安装,可获得最新版本
git clone https://github.com/rust-analyzer/rust-analyzer.git
cd rust-analyzer
cargo xtask install