Windows 10 配置Rust+vscode开发环境

在windows 10系统下配置Rustvscode环境 1. 安装git环境 rust项目管理工具cargo配置的新项目默认使用git管理,最好是将git也按照到系统中。 下载地址: htt

在windows 10系统下配置Rust+vscode环境

1. 安装git环境

rust项目管理工具cargo配置的新项目默认使用git管理,最好是将git也按照到系统中。
下载地址: https://git-scm/downloads ,我下载的按照包文件为Git-2.30.0.2-64-bit.exe

点击进行按照既可(可以选择安装目录等,其他的信息如果不清楚一路默认即可)

安装完成后验证:

C:\Users\xxxx> git --version
git version 2.30.0.windows.2

如果有需要,可以安装一个git可视化客户端 TortoiseGit

2. 安装Microsoft C++生成工具

Rust 的编译工具依赖 C 语言的编译工具,可以使用Microsoft C++ 生成工具(或者 MinGW + GCC 编译环境)。如果系统没有安装Visual Studio IDE开发环境,一般Microsoft C++ 生成工具是没有的,需要单独安装。

下载地址:https://visualstudio.microsoft/zh-hans/visual-cpp-build-tools/ 进行下载生成工具
例如我下载到的版本是:vs_buildtools__24487664.1602228744.exe ,管理员角色运行exe文件,弹出的窗口选中[C++ 生成工具],然后进行安装,语言可以选择中文+英语

安装远程以后,控制面板查看程序,包含如下

3. 安装配置Rust

使用官方推荐的rustup工具安装&管理Rust工具链

3.1 安装rustup

下载地址(64-bit): https://static.rust-lang/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe
点击 rustup-init.exe 进行安装,如果没有之前的安装Microsoft C++生成工具,会弹出提示进行安装,这里我们预安装好了,直接回车[Enter]就可以了。

安装成功后进行确认(cmd窗口)

rustup --version
rustup 1.23.1 (3df2264a9 2020-11-30)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.49.0 (e1884a8e3 2020-12-29)`

rustc --version
rustc 1.49.0 (e1884a8e3 2020-12-29)

cargo --version
cargo 1.49.0 (d00d64df9 2020-12-05)

3.2 写个helloworld验证一下

3.2.1 直接rustc[不用cargo]
> type hello_world.rs
fn main() {
    let greetings = "hello world!";
    println!("{}", greetings);
}

> rustc hello_world.rs

> hello_world.exe
hello world!

3.2.2 使用cargo创建项目
E:\Workspace\Lang\rust> cargo new hello
     Created binary (application) `hello` package
E:\Workspace\Lang\rust> cd hello
E:\Workspace\Lang\rust\hello> dir
src
Cargo.toml
.gitignore

E:\Workspace\Lang\rust\hello>type src\main.rs
fn main() {
    println!("Hello, world!");
}

E:\Workspace\Lang\rust\hello>cargo run
   Compiling hello v0.1.0 (E:\Workspace\Lang\rust\hello)
    Finished dev [unoptimized + debuginfo] target(s) in 1.22s
     Running `target\debug\hello.exe`
Hello, world!

4. 配置vsCode

4.1 安装vscode

可以使用Visual Studio Code 通过配置插件作为Rust的开发环境(IDE)
vsCode下载地址:https://code.visualstudio/Download 我下载到的当前System Installer版本 VSCodeSetup-x64-1.53.0.exe 点击进行安装即可

可以根据自己的需要选择安装目录或者默认,以后一路下一步默认即可。

安装完成,运行如下

4.2 在vscode配置Rust开发插件

  • rust-analyzer – 新一代rls,老的可以不用安装了。
  • CodeLLDB – Debug时需要用到的插件
  • Better TOML – TOML标记语言支持
  • crates – crates.io 依赖的一个扩展,Cargo.toml管理依赖使用
  • Tabnine – 只能助手,很好用,就是有点耗费CPU/内存,可以选择安装使用
  • Auto Close Tag – 自动添加HTML/XML close tag

4.3 使用vsCode开发rust项目

导航栏 – terminal – New Terminal· 或者 快捷键 Ctrl+Shift+`
在termi里切换工作目录,创建rust项目工程,之后 导航栏 – File – Open Folder 选择项目路径,打开项目

打开项目目录,可以开发代码了,之后再terminal里面可以编译,运行代码[cargo run],如下

到这里,windows 10 +rust +vsCode 开发环境搭建完成,VsCode还有很多其他玩法,例如远程开发等

发布者:admin,转转请注明出处:http://www.yc00.com/web/1754736255a5196802.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信