玩转它,首先要能在atom中能把rust代码走下来。
今天,主要讲一下第一次在atom中如何把rust代码走起来。原来写过一篇,但有点老,rust本身也有变化,所以重新更新一下。也供自己折腾使用吧。
一、windows中的几个前提
(1)准备好atom
这个我就不说了,不清楚的,找官网。下载并安装。
(2)看看是否装了MSYS2
https://github.com/rust-lang/rust
There are two prominent ABIs in use on Windows: the native (MSVC) ABI used by Visual Studio, and the GNU ABI used by the GCC toolchain. Which version of Rust you need depends largely on what C/C++ libraries you want to interoperate with: for interop with software produced by Visual Studio use the MSVC build of Rust; for interop with GNU software built using the MinGW/MSYS2 toolchain use the GNU build.
(3)rust的安装
找到rust官网:
https://www.rust-lang.org/en-US/
看到么,安装rust.
但是,有一个检查,需要注意:
是否安装了Microsoft Visual C++ Build Tools 2017。
On Windows, Rust additionally requires the C++ build tools for Visual Studio 2013 or later. The easiest way to acquire the build tools is by installing Microsoft Visual C++ Build Tools 2017 which provides just the Visual C++ build tools. Alternately, you can install Visual Studio 2017, Visual Studio 2015, or Visual Studio 2013 and during install select the "C++ tools".
建议下载vs2017或vs2015
下载完了后,再运行rustup-init.exe.
这个过程可能很长。短则半小时,长则一二个小时不等。
这个过程装好后,你可以看到cargo,rustc,rustup三个重要的文件在其中。但racer现是不在其中的。
这步如果没有成功,后面就会出现很大的问题。
二、在cargo中安装 racer
这一步是必须的。
C:\>cargo install racer
完成这步,上面的racer.exe文件才会出现在.cargo\bin\下面。
如果这步不成功,后面racer.exe的路径就无法填写了。
三、转到Atom
需要说明的是:
Atom中最重必要的两个库是build、cargo build(出现cargo:build 标识的唯一决定因素)。
另外一个就是language-rust。这个和cargo build需要一起配合。
而:其他如racer、rustfmt、linter-rust是可有可无的。
(1)建议在atom中下载
(2)在cargo build中进行配置
在atom 中的cargo build:
同样,在racer中配置,其中有一栏很清楚:(这一步不是必须的)
下面有一个源代码的目录。
这个可以到这儿下载,并解压,找到src的目录:
装好后,重启。
如果你看到左下面的出现了cargo:run(release)图标(这个地方点击后,你就知道如何运行rust代码了)时,证明ok了。
如果你不喜欢,可以下了它:
rustup self uninstall
另外,以下两个库推荐:
关于如何装上rustfmt,可以参见2017年2月份的博客文章:
Rust: 如何在Atom中用上Atom Beautify(绑定rustfmt)?
简单地说,需要在cargo 中安装,在atom中下载。
祝你使用愉快。