Cross-platform development on Windows is suddenly awesome
Tags: windows, linux, rust
Published: 2016-11-07 03:42:04

---
title: Cross-platform development on Windows is suddenly awesome
published: true
description: 
cover_image: 
tags: windows,linux,rustlang
---

Anyone who's done cross-platform development on Windows knows that getting things to compile can be a huge pain in the ass. Sometimes it's not even possible. The whole situation kinda sucked, until now.

## Enter Linux on Windows

There's this new thing called the [Windows Subsystem for Linux](https://en.wikipedia.org/wiki/Windows_Subsystem_for_Linux). Without going into too much detail, WSL provides a bash shell that exposes a Linux environment. It's native Linux, too — These are ELF binaries running inside Windows. The Windows file-system is fully accessible, with each drive having its own mount point. Linux processes can bind to the Windows loopback address and it all just works. You can read the technical details [here](https://blogs.msdn.microsoft.com/wsl/2016/10/19/windows-and-ubuntu-interoperability/), but the practical implications are simple enough: Windows is finally a good OS for doing cross-platform development.

![A native Linux environment running inside Windows.](https://d262ilb51hltx0.cloudfront.net/max/1600/1*x5Qn3W34ZHqe0VTlng3kEg.png)

WSL isn't installed by default, so you'll need to follow [these instructions](https://msdn.microsoft.com/en-us/commandline/wsl/install_guide) to get started.

## A practical example

I do a lot of Rust development in my personal time. Rust actually has excellent Windows support, however, there are packages that link against C libraries that aren't well supported on Windows. One of my projects depends transitively on OpenSSL, for example. Trying to compile on Windows results in this:

![](https://d262ilb51hltx0.cloudfront.net/max/2000/1*S54oqozA4mHXB8z4DauBow.png)

While most of these issues can be resolved with enough persistence, it's a huge waste of time and effort. My typical reaction is to ditch my beefy desktop and its multiple monitors for a small, relatively under-powered MacBook where things just work™. Not anymore!

To get started, I needed to install the Linux Rust toolchain. Something I haven't mentioned to this point is that the WSL uses Ubuntu, meaning it uses [apt](https://en.wikipedia.org/wiki/Advanced_Packaging_Tool) for package management. Installing things from the bash shell inside Windows is no different than doing it on any other Ubuntu installation:

    brian@DESKTOP-O4RQ37I:~$ sudo apt-get install build-essential
    ...
    brian@DESKTOP-O4RQ37I:~$ curl https://sh.rustup.rs -sSf | sh
    ...

First I install the `build-essential` package which installs gcc (among other things). Then I install rustup, Rust's toolchain manager, via its handy shell script. That's it — I navigate to the same code base that failed to compile within the standard prompt and compile it from the bash shell instead:

![](https://d262ilb51hltx0.cloudfront.net/max/1600/1*T3gmdGd6d9k5QPL0Iu9YBQ.png)

I was even able to configure IntelliJ IDEA to launch the bash shell in its terminal, meaning my entire workflow stays the same. The difference is that I'm now compiling a Linux binary and running it directly in Windows!