You can install Rust by simply downloading the installer and double clicking on it. Although developers who deal with more complex tools, or those who need to build "unsafe" (unsafe) C / C ++ libraries from source, have a little more to do. However, if you show a little perseverance, to understand this is quite realistic.
During this whole process, make sure that you install the correct version of the libraries: currently only the 64-bit version of Rust is available for MSVC. You will get strange errors every now and then if you try to use 32-bit libraries. Believe me.
I repeat: if you need a Rust compiler, go to the
official website and click "Install". If you plan to work with native C / C ++ libraries, read on!
')
Rust on Windows - what we need
Compiler C
You can choose GCC, but this will entail using MSYS and MinGW. Trying to configure MSYS2 for Windows, I burned countless times, so now I prefer to avoid this option. Instead, I use the Microsoft compiler. You can get MSVC through one of these links:
Both options are good - Microsoft made Visual C ++ free to develop open source software. At least he was at the time of this writing (2016-03-22).
Translator’s note: The Visual Studio Community is free not only for open source projects, but also for individual developers, academic research, training, and small companies. More details .Let's get to the hard part: you need to make the Visual C ++ magic work in your environment. To facilitate this task in Visual C ++ there are many environment variables and complex installation scripts. You can use the command shell that Microsoft provides with VS and VC ++ (Visual C ++ 2015 x64 Native Build Tools Command Prompt). Everything discussed below will work if you select this option.
I use a cmder that uses PowerShell, so to make the command line tools work in my environment, I had to overcome another obstacle. I chose the recipe from the
PowerShell Cookbook (you definitely need to buy it, if you like this sample code, you will find many lines of PowerShell code in it that you don’t have to write yourself). In any case, after saving the recipe to a file, I added the following to my PowerShell profile:
Invoke-CmdScript.ps1 "C:\Program Files (x86)\Microsoft Visual C++ Build Tools\vcbuildtools.bat" amd64
Openssl
If you want to use Rust as a server language for web development, you will need OpenSSL.
Win32 OpenSSL Installation Project supports multiple installers. Follow the link and browse to “Download Win32 OpenSSL”. Select the 64-bit version of OpenSSL (not Light). Install it.
They will show you the message "Support us, because we work for free." I supported. If you continue to use OpenSSL for Windows, you might also donate money. Set yourself a reminder, and if in a month you will be working with this library, do it.
OpenSSL Environment Variables
Make sure the compiler sees OpenSSL. You should set the following environment variables:
DEP_OPENSSL_INCLUDE=C:\OpenSSL-Win64\include OPENSSL_INCLUDE_DIR=C:\OpenSSL-Win64\include OPENSSL_LIB_DIR=C:\OpenSSL-Win64\lib\VC OPENSSL_LIBS=ssleay32MT:libeay32MT
Obviously, this implies that you have placed OpenSSL in the standard installation directory C: \ OpenSSL-Win64.
Freetype
Instructions on how to configure Freetype for MSVC can be found
here .
Installing Rust on Windows
You can go two ways: using the installer Rust or
multirust .
Installer Rust
Go to the Rust
download page and download the MSVC ABI installer.
So you get one of the versions of Rust (for example, 1.7.0). When new versions of the language appear, you will have to decide whether you want to upgrade and, as a result, change one or more environment variables. It's easy, but since Rust releases are released every six weeks, you may be a little tired of frequent language changes.
Rustup
Rustup is a tool for maintaining multiple versions of Rust on a single operating system. Thanks to him, you can use different versions of Rust for different projects and even test new features in the night version!
Now visit
rustup.rs and download the current installer. After downloading, double click on it and wait. When it is complete, open a new terminal and run
rustup default stable-x86_64-stable
.
We need to make sure the environment variable is set. I think you know where to look for her. Check the
PATH
to see if the path
~/.cargo/bin
been added. I use
~
to denote your home directory. On my computer, I check if
C:\Users\jeremiah\.cargo\bin
in
PATH
. If not, add it.
Additional Rust Tools
At this stage, we already have a working version of Rust. We can start using
rustc
and
cargo
for software development. However, we can install additional tools to make the job easier.
Rust source code
You can read it, but now we just want to use it for some additional tools. Go to the Rust
downloads page and download the sources. This is a .tar.gz file, so you might need something like 7-zip. I will leave the choice of a specific program for you.
After downloading the source code, extract it into a directory that you do not accidentally delete. I chose src in my home directory and can find Rust sources like this:
C:\users\jeremiah\src\rust-1.7.0
. Again open the environment variables, create a new variable
RUST_SRC_PATH
and write in it the path to the source code Rust.
Racer
Racer provides code completion in software development tools. It can be very useful if you are learning a language or parsing code, trying to understand what parameters the function accepts. If you added
.cargo\bin
to
PATH
and set the environment variable
RUST_SRC_PATH
, installing Racer will be very easy. Just run
cargo install racer
and wait.
rustfmt
rustfmt formats the code on Rust. He will help you a great job. Not that you couldn’t format the code yourself, but this program ensures that the same style is observed. Argue about formatting the code is not worth it. Avoid this.
cargo install rustfmt
READY!
Editor
I personally use
Visual Studio Code . I’ve heard that Sublime Text has recently worked well with Rust. This language is also supported in Atom and other editors.
On
the Racer page, you can find links to instructions for working with different editors. In the Visual Studio Code, I installed only the extensions
Rusty Code and
vsc-rustfmt .
Translator's note: I didn’t really like the Visual Studio Code, so there was a lot of hope for the VisualRust extension for Visual Studio. Unfortunately, at the moment this extension does not support Cargo.Somehow difficult!
It may seem to you that this path is too long, but it is quite easy to go through and, frankly, it is faster than waiting for Visual Studio and 90 other dependencies to be installed.