Rustup on Don

Native Rust development on Windows 11

Callback Insanity
8 min readFeb 25, 2022

I have been keeping an eye on Microsoft HoloLens and the thinking about what potential augmented reality applications it could provide. Along side with that, I have also been thinking about Mozilla mixed reality initiatives, and how could Rust could tie all these together. At this point whether Rust can be used for HoloLens is more of an if and less of a how for me, but there’s only one way of finding out!

At some point Firefox Reality might support HoloLens. Firefox Reality in turn is powered by Servo, which does use Rust, specifically the rust-webvr library. The Github for rust-webvr says the project is deprecated, so the prospects of this particular avenue of research seem somewhat opaque.

While I do not own the physical HoloLens kit, Visual Studio provides an emulator (which I haven’t used yet) that could potentially be used for development without the actual physical kit. For a good horror story on Universal Windows Platform (UWP) and HoloLens development, check out Challenges in HoloLens Application Development by Vinothkumar Arputharaj.

I do most of my PHP / Drupal related work using Windows Subsystem for Linux, but in this story I am going to be making the leap back to native Windows land for installing Rust. The rationale being that while Rust can be installed in WSL, if I where to develop for HoloLens in the future those applications would need to be distributed as Universal Windows Programs, which are built natively (in the Windows host) and not in a WSL host.

While today’s story is not about HoloLens or UWP, I wanted to give a quick backgrounder on some of my motivations behind using Rust, however wild those ideas might be. Most likely I end up using something else for UWP or HoloLens development, and Rust for, well I don’t know what! Me using Rust is like a problem looking for a solution.

Getting Started

Fire up an elevated privilege command prompt and search for Visual Studio with winget search "visual studio" :

Funny how when searching for Visual Studio, Rust (MSVC) pops up in the search? Since I do not have (or need) a Visual Studio license at this time, a community edition will suffice.

Per the Microsoft guides, the easiest way to install Rust build dependencies natively is by installing Visual Studio. That does not mean I’m going to be using Visual Studio for development per-se, I’m just using it to install build dependencies. My main development environment shall be Visual Studio Code (VSC), forever and ever.

Install the Visual Studio dependency with:

winget install Microsoft.VisualStudio.2022.Community

Eventually a Visual Studio Installer windows pops up informing the user of the installation progress:

When the installer is done, the installer Window automatically closes the winget command should return a successful status:

Searching the Start Menu for “Visual Studio” should provide a fresh new result for Visual Studio 2022:

Launch Visual Studio Installer

When you open Visual Studio, if you click on the Menu -> Tools -> Get Tools and Features … option, you get the Visual Studio Installer program.

Alternatively, you can go to the installer directly without opening Visual Studio by typing “visual studio installer” into Windows Search:

Install native build dependencies using Visual Studio

Microsoft recommends installing four dependencies for working with Rust:

  • .NET desktop development
  • Desktop development with C++
  • Universal Windows Platform development
  • Git

Here are all there major dependencies selected:

Once you’ve done your selection, click on “modify” and the installer should take it from there:

Once the installer is done doing your bidding, you should receive a message as follows and you are ready for the next step:

Installing Rust

For installing Rust natively on Windows and not on WSL, Microsoft recommends using the official installer rustup from https://www.rust-lang.org/tools/install.

While I could, and it is indeed tempting, to use winget to install Rust using:

winget install Rustlang.Rust.MSVC

The version of Rust presented by the winget package manager is 1.58.1.0. As of this writing, the version available on the official Rust page is 1.59.0, making winget one major version behind.

Minor version 1.58.1 was released on January 20, 2022, which makes this release relatively fresh to date. Minor version 1.59.0 was released on February 24, 2022, that’s yesterday! I like my dependencies super fresh, so for that reason I will be going with the rustup installer instead of winget.

Rust version 1.59 adds improvements to variable destructuring operations, smaller compiled binaries when using certain Cargo options, inline assembly support, and other improvements.

After downloading rustup-init from the Rust install page, double-click as usual to execute and you should get a Windows Terminal console or equivalent asking you about the next steps. I will be installing the stable verson of Rust, so all the default options work for me and I just press 1) to continue:

Once the installer is done running, you should get a prompt asking you to close the terminal so the changes take effect. Note that if at this point you ran into an error while installing, maybe you did not install all the C++ build dependencies mentioned above, or didn’t wait for Visual Studio to finish the install process, and therefore you should re-attempt to install Rust once you have all the build dependencies for Rust already in place.

Ensure you are using the stable channel

I used to have at some point Rust installed natively on my Windows machine, and it happens that I had it set to use the nightly channel.

I want to switch to using the stable release channel for the language, so my instructions to rustup are:

rustup default stable
rustup update

Screenshot:

With those two commands now both my nightly and stable release channels are up to date:

Now my rust language versions stands at:

stable-i686-pc-windows-msvc updated - rustc 1.59.0 (9d1b2106e 2022-02-23) (from rustc 1.41.0 (5e1a79984 2020-01-27))stable-x86_64-pc-windows-msvc updated - rustc 1.59.0 (9d1b2106e 2022-02-23) (from rustc 1.48.0 (7eac88abb 2020-11-16))nightly-x86_64-pc-windows-msvc unchanged - rustc 1.61.0-nightly (4b043faba 2022-02-24)

If you are more interested in knowing what the rustup command is and how it works, check out the official documentation on Github: https://rust-lang.github.io/rustup/index.html.

Set up Visual Studio Code on Windows

This next step is about setting up VSC on Windows, not on WSL. To work with Rust there’s a few VSC extensions available at our disposal.

  • rust-analyzer (Preview). Market name: matklad.rust-analyzer
  • Rust, the official extension by the Rust community. Market name: rust-lang.rust
  • CodeLLDB, by Vadim Chugunov. Market name: vadimcn.vscode-lldb
  • C/C++, by Microsoft. Market name: ms-vscode.cpptools

A couple of notes about these extensions:

  • Both rust-analyzer and rust are language server extensions that will provide with enhancements to the editor experience. You shouldn’t use rust-analyzer with the rust extension, since they may conflict with each other.
  • CodeLLDB and C/C++ are used for debugging and you should use either or. According to Microsoft the former provides better editor experience, while the latter a more robust debugging capability.

You can install the extensions directly from the Visual Studio Marketplace, from VSC itself, or from the command line.

I fancy using the command line:

code --install-extension <extension-market-name>

It is curious to note that Microsoft is kind of recommending to use rust-analyzer over the official Rust extension. I haven’t used rust-analyzer in the past, so I’m going to give it a try. Even though it only has 147 stars in the marketplace, it’s rating stands at 5 stars. The official Rust extension has less stars with a count of 109, and a reputation of 3 stars.

Back in Windows Terminal I can type cls to clear the the screen, which is the equivalent of clear on *nix, and proceed to install rust-analyzer and CodeLLDB:

code --install-extension matklad.rust-analyzer
code --install-extension vadimcn.vscode-lldb

I did my best in an hour or two to try to use the CodeLLDB extension for debugging Rust on Windows, with no success. The launch configuration would run and the project would build with CodeLLDB, but no dice with the debugger hitting the breakpoints on VSC.

Instead I ended up installing the C/C++ extension on Windows Visual Studio Code, as mentioned in Getting Started with Rust on Windows and Visual Studio Code and the Microsoft document: Install Visual Studio Code.

Create new baby Goo Goo Da Da application

One of my neighbors just had a baby, so this section is baby themed instead of the de rigueur Hello World.

From the terminal I navigate to where I want to create my new Rust application and use Rust to instantiate a new project:

cd Sites
cargo new googoo

From within the terminal I switch directory to the new project location and instruct Visual Studio Code to open to the current location:

The Cargo command already created a sample hello world source file:

So I just change the println statement to use the newborn theme. When launching this project for the first time VSC is going to ask if we want to configure a debugging target for the project, I chose yes:

And the following launch file is created:

With launch.json in place, I can now put a breakpoint in my baby application and press F5 to debug. On the terminal I can see the sample output:

Ta Da!

Windows 11 now is configured for Rust development.

Even though this story was mainly targeted towards Windows users, if you are a ‘nix user and want more details on how to tweak the CodeLLDB launch configuration, check out their official docs.

The final launch.json I ended up using is here:

--

--

Callback Insanity

Organic, fair-sourced DevOps and Full-Stack things. This is a BYOB Establishment — Bring Your Own hipster Beard.