傲渊山岳 发表于 2025-3-15 07:09:28

『Rust』Rust运行情况搭建

rust编译工具rustup

https://www.rust-lang.org/zh-CN/tools/install
换源
RUSTUP_DIST_SERVER https://rsproxy.cn
RUSTUP_UPDATE_ROOT https://rsproxy.cn
修改rustup和cargo的安装路径
RUSTUP_HOME D:\rust\.rustup
CARGO_HOME D:\rust\.cargo
运行rustup-init.exe
1) Quick install via the Visual Studio Community installer
   (free for individuals, academic uses, and open source).
>1

1) Proceed with selected options (default - just press enter)
>1
将%CARGO_HOME%\bin
添加到PATH
%CARGO_HOME%\bin
安装后运行验证:
rustc -V
rustup -V
cargo -V
rustup show
C:\Users\Ho1aAs>rustc -V
rustc 1.85.0 (4d91de4e4 2025-02-17)

C:\Users\Ho1aAs>rustup -V
rustup 1.28.1 (f9edccde0 2025-03-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.85.0 (4d91de4e4 2025-02-17)`

C:\Users\Ho1aAs>cargo -V
cargo 1.85.0 (d73d2caf9 2024-12-31)

C:\Users\Ho1aAs>rustup show
Default host: x86_64-pc-windows-msvc
rustup home:D:\rust\.rustup

installed toolchains
--------------------
stable-x86_64-pc-windows-msvc (active, default)

active toolchain
----------------
name: stable-x86_64-pc-windows-msvc
active because: it's the default toolchain
installed targets:
x86_64-pc-windows-msvc
Visual Studio + VS Code

Visual Studio 2022 + Visual Studio Code 1.98.1
vscode安装扩展:Chinese + rust-analyzer + Native Debug + C/C++
https://i-blog.csdnimg.cn/direct/6cb5672a298d4f1e844603ffa2a4782c.png#pic_center
(安装时可选)添加空白处右键、文件夹右键、文件右键以VSCode打开
# 1.reg
Windows Registry Editor Version 5.00


@="Open with Code"
"Icon"="D:\\Microsoft VS Code\\Code.exe"


@="\"D:\\Microsoft VS Code\\Code.exe\" \"%1\""



@="Open with Code"
"Icon"="D:\\Microsoft VS Code\\Code.exe"


@="\"D:\\Microsoft VS Code\\Code.exe\" \"%V\""



@="Open with Code"
"Icon"="D:\\Microsoft VS Code\\Code.exe"


@="\"D:\\Microsoft VS Code\\Code.exe\" \"%V\""
测试编译

手动编译

新建~\Desktop\rust用vscode打开,cargo新建项目:cargo new rust-test
https://i-blog.csdnimg.cn/direct/5c9fb2d2bc464f86800148e6df339809.png#pic_center
cd进项目,build和run即可编译为exe
cd rust-test
cargo build
cargo run

# || rust-test.exe
https://i-blog.csdnimg.cn/direct/eda14edf359b4e7ca27733cf77401c1d.png#pic_center
VSCode编译设置

项目路径新建.vscode,在其中新建tasks.json和launch.json
// tasks.json
{
    "version":"2.0.0",
    "tasks":[
      {
            "label":"build",
            "type":"shell",
            "command":"cargo",
            "args":["build"]
      }
    ]
}
launch.json需要微调,主要是Console标签谁人位置
// launch.json
{
    "version":"0.2.0",
    "configurations":[
      {
            "name":"Run Rust",
            "preLaunchTask":"build",
            "type":"cppvsdbg",
            "request":"launch",
            "program":"${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe",
            "args":[],
            "stopAtEntry":false,
            "cwd":"${workspaceFolder}",
            "environment":[],
      "console": "integratedTerminal",
      }
    ]
}
打断点调试
https://i-blog.csdnimg.cn/direct/ba473e4c2aa6498facc63330560f9823.png#pic_center
参考

   https://www.runoob.com/rust/rust-setup.html
https://www.runoob.com/rust/cargo-tutorial.html


   欢迎关注我的CSDN博客 :@Ho1aAs
版权属于:Ho1aAs
本文链接:https://ho1aas.blog.csdn.net/article/details/146232471
版权声明:本文为原创,转载时须注明出处及本声明

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 『Rust』Rust运行情况搭建