自学内容网 自学内容网

Rust开发环境搭建

Rust开发环境搭建

环境

rust: 1.79.0(2024-06-13)

1. Rustup下载器在线安装

windows:

https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe

unix:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

2. Rust独立安装包离线安装

windows:

https://static.rust-lang.org/dist/rust-1.79.0-x86_64-pc-windows-msvc.msi

linux:

https://static.rust-lang.org/dist/rust-1.79.0-x86_64-unknown-linux-gnu.tar.xz

macos:

https://static.rust-lang.org/dist/rust-1.79.0-x86_64-apple-darwin.pkg

3. Rust命令行

  • 查看rust版本
$ rustc -V
rustc 1.79.0
  • 新建rust项目
cargo new hello_world
  • cargo编译rust项目
$ cargo build
  • rustc编译rust项目
$ rustc src/main.rs
  • 运行rust程序
$ ./target/debug/hello_world
Hello, world!

4. IDE集成开发环境

4.1 VSCode

Rust with Visual Studio Code

4.2 vs2022

[User Manual (rust-analyzer.github.io)

5. 使用镜像加速cargo

$CARGO_HOME/config中加入如下内容

[source.crates-io]
replace-with = 'mirror'

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

注:$CARGO_HOME:在 Windows 系统默认为:%USERPROFILE%\.cargo,在类 Unix 系统默认为:$HOME/.cargo


Reference:

  1. Other Installation Methods - Rust Forge (rust-lang.org)

原文地址:https://blog.csdn.net/itas109/article/details/140231106

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!