Visual Studio extension for Rust Currently in development, and not feature complete. Stable versions are available on the Visual Studio extension gallery. Unstable, but more recent builds are downloadable from AppVeyor (choose 'Configuration: Release' and 'Artifacts'). To start using Rust, download the installer, then run the program and follow the onscreen instructions. You may need to install the Visual Studio C Build tools when prompted to do so. Lexus subcompact suv hybrid. If you are not on Windows see 'Other Installation Methods'. Download rustup-init.exe (32-bit).
Rust is an exciting programming language and I highly recommend giving it a shot. Getting started is a cinch. If you’re interested in programming Rust on Windows, follow the steps below and you’ll be up and writing code in no time.
If you would rather follow in video format, you can catch a video of this post on my YouTube channel.
Interestingly enough, the Rust compiler requires the Microsoft C++ Build Tools to do its job. Before proceeding, you’ll need to ensure the Visual Studio Build Tools are installed on your machine. Visual Studio comes prepackaged with these build tools. However, VS Code does not. You can find the Visual Studio Build Tools 2019 version here. It is free to download and install.
Clicking the link above will take you to a page entitled, “Thank you for downloading Visual Studio.” Don’t be fooled by this title. the download of the build tools will begin shortly after clicking the link.
Once you’ve downloaded the build tools, execute the setup. Select the option to install the C++ Build Tools and click the Install button. Upon completion, close the window entitled “Visual Studio Installer.”
Next, head on over to the Installation page and click the gargantuan button labeled “Rustup-Init.exe.” There are a few alternate ways to install Rust, but I don’t recommend them. Even though you may be tempted, I strongly suggest not installing Rust through Chocolatey, as it doesn’t appear to install all of the required tools in the tool chain (mainly rustup). With rustup missing, you won’t be able to get the Rust Language Server (RLS) up and running in Visual Studio Code.
When you click on the button, your browser will download the rustup-init.exe executable, which is essentially a command-line installer. Proceed along with the defaults until the installation is complete. Installing Rust will alter your machine’s PATH environment variable. So once the installation is complete, you’ll need to launch a new command prompt for changes to take affect.
Open a new PowerShell window or command prompt and execute the following:
If you see a version number, the tool chain should be successfully installed. You can then verify that the latest version of Rust and all of the other tools in the tool chain are installed with the following command line:
Launch VS Code. Note that if VS Code was running before the Rust installation completed, you’ll need to restart it for the environmental changes to take affect.
There are a variety of VS Code extensions that support Rust. I found the “Rust Extension Pack” to be a great pick on the marketplace. Not only does it bundle the Rust RLS official extension, but it includes the most popular cargo and TOML plugins available. To install this extension pack:
The only deficiency in the Rust Extension Pack is the lack of test integration. Unfortunately, there currently isn’t a lot to choose from. However, there is one that appears to do a decent job – “Rust Test Explorer“. Follow the steps above to install this extension and you’ll be able to navigate and execute unit tests from the Test Explorer panel.
In VS Code, open a new, empty folder. We’ll flesh out a simple Rust project from here. In the Explorer panel, create a new file named “Cargo.toml” with the following information:
Create a new directory named ‘src.’ Within that directory, create a file named main.rs with the following content:
VS Code will execute a default task every time you choose to build your code. We will configure Code to execute the “cargo build” command line every time you kick off this build process.
Open the command palette (Ctrl-Shift-P) and type in “build” and select “Tasks: Configure Default Build Task”
Select “Rust: cargo build”
This should create a tasks.json file that has a single, default build task.
Cargo Build Task in Tasks.json
Now, every time that you press Control-Shift-B or run a build from the command palette, VS Code will execute cargo build.
Just like with the Build task, Code also executes a default task when you choose to run unit tests. To get you up and running, we’ll create a simple test that always fails. Open the main.rs file and add a simple test below the main function:
Save the file and open the command palette again. Type in “task” and select “Tasks: Configure Default Test Task”
Select “Rust: cargo test”
This should add a cargo test task to the tasks.json file. Now, every time that you run the Test Task, VS Code will execute the “cargo test” command and provide feedback in the Terminal panel. If you would prefer to execute your unit tests from a UI, you can also execute tests directly from the Test Explorer.
If your tests aren’t showing up in Test Explorer, press the circular refresh button to refresh the test list.
The thought of typing “cargo run” every time I want to run my app is not very enticing. I also want to be able to debug my app. I thought debugging Rust in Code was going to a be a pain until I found a blog by Bryce Van Dyk, entitled “Debug Rust on Windows with Visual Studio Code and the MSVC Debugger.” His post is awesome; read through it if you get a chance.
If you don’t want to read the whole article and still want to take advantage of debugging Rust in Code, perform the following steps:
Your launch.json should look similar to mine:
Rust Debug Configuration in Launch.json
Next, you’ll need to alter your settings to allow breakpoints in Rust files.
Alternatively, you can open your settings.json file and add the following:
Now, when you hit F5, VS Code will start debugging a new instance of your program. You can add breakpoints where needed.
If you're just getting started withRust and would like a more detailed walk-through, see ourgetting started page.
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 2019 which provides just the Visual C++ build tools. Alternately, you can install Visual Studio 2019, Visual Studio 2017, Visual Studio 2015, or Visual Studio 2013 and during install select the “C++ tools.”
For further information about configuring Rust on Windows see the Windows-specific rustup
documentation.
rustup
Rust is installed and managed by the rustup
tool. Rust has a 6-week rapid release process and supports a great number of platforms, so there are many builds of Rust available at any time. rustup
manages these builds in a consistent way on every platform that Rust supports, enabling installation of Rust from the beta and nightly release channels as well as support for additional cross-compilation targets.
If you've installed rustup
in the past, you can update your installation by running rustup update
.
For more information see the rustup
documentation.
PATH
environmentvariable In the Rust development environment, all tools are installed to the ~/.cargo/bin
%USERPROFILE%.cargobin
directory, and this is where you will find the Rust toolchain, including rustc
, cargo
, and rustup
.
Accordingly, it is customary for Rust developers to include this directory in their PATH
environment variable. During installation rustup
will attempt to configure the PATH
. Because of differences between platforms, command shells, and bugs in rustup
, the modifications to PATH
may not take effect until the console is restarted, or the user is logged out, or it may not succeed at all.
If, after installation, running rustc --version
in the console fails, this is the most likely reason.
If at any point you would like to uninstall Rust, you can run rustup self uninstall
. We'll miss you though!