admin管理员组

文章数量:1571376

概要

本篇文章介绍了windows系统rust的安装流程和crates换源的方式。

安装流程

  1. 在运行rustup-init.exe之前首先需要下载安装Visual Studio C++ Build tools,理论上只需要勾选MSVC和windows10 SDK这两个选项。

  2. 从官网下载rustup-init.exe

  3. 运行rustup-init.exe,在一开始的三个选项中选择 1)Proceed with installation (default),之后一直按回车即可完成安装

  4. 在代码编辑器方面,推荐使用vs code,并且安装rust插件

  5. 之后让我们来试试写一个hello world并且运行它,新建一个hello_world.rs,写入代码,编译并且运行

    fn main(){
        println!("hello,world!");
    }
    
    PS E:\OneDrive\文档\我的路\学习之路\rust_work_space> rustc hello_world.rs
    PS E:\OneDrive\文档\我的路\学习之路\rust_work_space> .\hello_world.exe
    hello,world!
    
  6. 如果能够运行hello world,说明rust已经成功安装了,这里再补充一点关于crates换源(之后会用到)。下面讲讲怎么换源,首先找到$HOME/.cargo这个文件夹($HOME代表的是C盘的用户目录),然后新建一个config文件(注意这个config文件没有后缀名),然后将以下的内容复制进去,这样就相当于将源换成了清华源。

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

本文标签: 系统安装方式WindowscratesRust