1: Introduction
LLVM is huge, complex ecosystem of tools, languages, libraries, data structures & algorithms, frameworks and community (people, forums, discord, conferences, books, articles, etc.) gathered around the topic of compiler development. LLVM is directly used by giant companies like Nvidia, Apple, AMD, Samsung or Intel. It is used by products like Clang, Swift, Rust and by hobbyists/researchers for R&D / experimental languages and/or compilers. Proficiency in LLVM's ecosystem can be decent career choice since such skills, knowledge and experience are usually needed by big companies who can compensate well. Additionally you can work on really interesting stuff like bleeding edge hardware products. In this post I'd want to help you setting your LLVM development environment on Windows. Keep in mind that I'm just LLVM beginner and that LLVM constantly changes, so there may be better ways to achieve something. Before you start I'd want to make you aware that LLVM really likes computer resources, so try to prepare 1) Hundreds of GBs of free disk space (preferably fast, NVMe like disk) 2) At least 64 GB of RAM or at least utilize swap 3) Of course good CPU, so it compiles those giant C++ projects fast It is not required, but you may have to work around issues e.g lack of memory, so bigger swap needed or fancy compilation flags/switches need to be applied, etc.
2: WSL
Despite it being possible to develop LLVM on Windows directly with Visual Studio, I believe that it may be slightly easier to start with Linux, so that's why I recommend WSL2. WSL2 is an official Windows component that behaves like Linux virtual machine with better performance and very strong integration with Windows, which makes developer experience way better than traditional virtual machines. In order to enable WSL2 you should visit official docs: https://learn.microsoft.com/en-us/windows/wsl/ You can install Ubuntu WSL2 distro using this command:
Or if you want to specify which disk should be used (e.g because you lack of space) then you can use this:
PS: If you have already some distro installed, then you can see it and its name by using
Once installation completes you'll be able to run "wsl" or "wsl -d WSL_Instance_Name" in order to enter your Linux e.g
Once we're in let's install basic packages
3: Cloning LLVM repo & building it
Now we need to get LLVM's source code and build it
Before building LLVM you may want (that's optional) to create bigger swap file, for example I gave it 30GB
Now we can try to build some basic LLVM components to see if it works. Let's start with cmake
Once cmake completed successfully we can start actually compiling it and have some free time waiting for it to complete :)
After it completed, here are our binaries, yay!
4: Setting up VS Code with working Intellisense
I'm not sure how common this approach is, but I recommend using VS Code on Windows and connecting via SSH to the WSL2 Linux box. Although it is possible to open VS Code on Windows and work on WSL2 files without SSH step, for me it had problems with include paths resolution (for Intellisense) and SSH approach worked flawlessly. So, I recommend getting "Remote SSH" extension, direct link: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh; docs: https://code.visualstudio.com/docs/remote/ssh Let's then setup SSH server on our WSL2 box and let's check IP of that WSL2 machine
Here's our IP printed by ifconfig
Then in VS Code's command palette type ">ssh" and select "Remote-SSH: Connect to host"
Then type your WSL2 username and ip address e.g "[email protected]"
Then accept fingerprint by selecting "Continue"
Then enter WSL2 password
And then VS Code will install its stuff on the WSL2 machine
Once it completes you should open VS Code inside the recently git-cloned llvm-project folder, so it is your workspace
and you need to install C++ Extension - I've used the one from Microsoft
But you also need to make sure that this is installed on that WSL2 machine by going into Extensions -> SSH -> clicking that Cloud-ish icon
After that you can try to open this file /llvm-project/llvm/lib/Transforms/Utils/HelloWorld.cpp and start messing with it to see whether Intellisense works
If Intellisense doesn't work and the issue looks like that
then I recommend adding Include Paths
or via file
After doing so you may need to Reset Intellisense Database via command palette and wait for completion (right bottom corner)
5: SSH-Key as a convenience feature
In order to avoid having to type your WSL credentials whenever you open VS Code I recommend adding SSH Key since this is quick. Start by generating your private and public key in "%userprofile%\.ssh" directory (on your Windows machine), like this:
You'll have such two files:
After that go into your WSL box and create "~/.ssh/" directory
Now you must copy your public key from Windows to your WSL2 box, I suggest copying it over SSH
We can confirm that file & the public key is indeed there
Since now you should be able to connect via SSH without using password, either when using command palette or via recent folder in Windows Search
In next post I'll try to cover setting up debugger, writing some basic pass and invoking it
.png)


