Setting Up WSL 2 & Rust on Windows 10

I've never been super-keen on doing development on Windows machines.

With WSL aka Windows Subsystem for Linux, there's the possibility of developing on a Windows machine with Windows apps... but with all the Linux goodness.

WSL 2 is the new-to-2020 version that uses the native Linux filesystem (very fast) and has a bunch of other goodies that makes the Windows 10/Linux integration really nice.

I've also been working on Mesa X... a re-imagination of spreadsheets written in Rust (for the server) and TypeScript (front end).

Here's my development setup.

Install WSL 2

First, you have to install WSL 2 on your Win10 machine.

From PowerShell in Administrator mode, type:

  • dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
  • dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

Next, restart your machine.

Next, enabled WSL 2: wsl --set-default-version 2

You may be prompted to download a Linux Kernel patch.

Install Ubuntu 20.04

Next, open the "Microsoft Store," search for "Ubuntu 20.04," and install it. Also, install the "Windows Terminal" application (it's worlds better than the old DOS-derived terminal.)

Launch the Ubuntu app. You'll be prompted for a username and password. Enter your favorite username (mine is "dpp") and a password.

Set up ssh-agent

You'll be doing a lot of ssh-ing... using git and doing other stuff.

I found this post and like using keychain.

To update the packages and install keychain git and editors, type: sudo apt update && sudo apt upgrade -y && sudo apt install -y keychain emacs vim git

Enter your ssh keys: vim .ssh/id_rsa .ssh/ and ensure that the directory is only readable by you: chmod -R og-rwx .ssh/

Update ~/.bashrc adding the following at the end of the file:

/usr/bin/keychain --nogui $HOME/.ssh/id_rsa 
source $HOME/.keychain/$HOSTNAME-sh

Exit the Ubuntu window and then open a Windows Terminal session to Ubuntu. You should be greeted with a prompt to enter your ssh key's password:

 * keychain 2.8.5 ~
 * Starting ssh-agent...
 * Adding 2 ssh key(s): /home/dpp/.ssh/id_rsa 
Enter passphrase for /home/dpp/.ssh/id_rsa:
 * ssh-add: Identity added: /home/dpp/.ssh/id_rsa 

To test if this works, try cloning a repo (assuming the ssh key is your GitHub key): git clone mesax

Installing Rust, Dev Tools, etc.

Install Rust with RustUp: curl --proto '=https' --tlsv1.2 -sSf | sh

Then make sure you've included the updated environment variables: source $HOME/.cargo/env and add export PATH="$HOME/.cargo/bin:$PATH" to the end of your ~/.bashrc file.

Install other stuff that's needed: sudo apt install -y build-essential npm protobuf-compiler

Can you build Mesa X?

In the step above, you checked out the Mesa X source. Now, cd mesax.

Check out the tag used in this blog post: git switch -c for_blog

To make sure Rust works, type cargo test. The Rust code should build.

Next cd mesa-client and install the npm dependencies: npm install and check to see if you can run protoc (the stuff that compiles protocol buffer files): npm run protoc. If all that works, start the npm app: npm start and your Windows browser should open to the application.

Using VS Code

Visual Studio Code is currently (July 2020) the hotness in IDEs.

If you've got VS Code installed in Windows-land, just type code . in the mesax directory and you should get VS Code running in Windows... but editing your WSL-based code.

Have fun

Have fun with a very nice Windows/Linux development experience!