目录

rust环境配置

官网

  • 主要安装rustup和cargo工具链
  • linux

    text

    $ # for bash
    $ echo 'export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup' >> ~/.bash_profile
  • windows

    修改环境变量:

    变量名为

    text

    RUSTUP_DIST_SERVER

    变量值为

    text

    https://mirrors.tuna.tsinghua.edu.cn/rustup
  • windows

    text

    # 新建 %USERPROFILE%\.cargo\config 
    [source.crates-io]
    replace-with = "rustcc"
    
    [source.rustcc]
    registry = "https://code.aliyun.com/rustcc/crates.io-index"
  • linux

    text

    tee $HOME/.cargo/config <<-'EOF'
    [source.crates-io]
    replace-with = "rustcc"
    
    [source.rustcc]
    registry = "https://code.aliyun.com/rustcc/crates.io-index"
  • 安装vscode后,安装rust(rls)插件,用cargo new hello_cargo新建工程文件,打开工程按照提示安装rls等工具。

  • 调试环境,windows安装C/C++插件,linux安装codelldb插件

  • 配置launch.json调试文件如下:

    text

    
        {
        "version": "0.2.0",
        "configurations": [
                "name": "Debug",
                "type": "cppvsdbg",
                "request": "launch",
                //调试程序位置
                "program": "${workspaceFolder}/target/debug/YOUR_EXECUTABLE.exe",
                "args": [],
                "stopAtEntry": false,
                "externalConsole": false,
                "preLaunchTask": "cargo build",
                "type": "cppvsdbg",
                // rust源码文件
                "sourceFileMap": {
                    "/rustc/4560ea788cb760f0a34127156c78e2552949f734": "${env:HOME}${env:USERPROFILE}\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\src\\rust"
                }
            ]
        }

rust中文文档