Rust with Visual Studio Code on Windows from Ubuntu
Say you want to play with Rust on a Windows machine.
Rust comes with a native installer for Windows, but that requires you to download and install MS C/C++ build tools first (several GB).
Here is a quick way to avoid doing that.
- On Windows side, make sure WSL remote is added-on your Visual Studio Code
- install Ubuntu on WSL2
- Then terminal into Linux side, install Rust on the Linux side, and remember to install “build-essential” (compiler tool chain on Linux)
- run Visual Studio Code (
code .) in the Linux terminal; a VSCODE window will pop-up as a Windows program, and it remotes to the Linux side.
- Now you can compile and run Rust code in VSCODE; it’s going to be compiled for Linux with the Linux compiler tool chain.
- No need for GB sized MS C/C++ compiler toolchain; Rust toolchain resides on Linux side; Linux is just a Rust compiler and runtime.
- The source code files are kept in Windows folders, in case WSL2 goes nuts.