First, you need to clone the LLVM repository and check out the
llvmorg-19.1.6
tag. For example, the following commands would check out the
right commit (I would strongly recommend running these outside this
repository):
$ git clone https://github.com/llvm/llvm-project.git llvm
$ cd llvm
$ git checkout llvmorg-19.1.6
There are some scripts for building LLVM on different operating systems under
ci/
, but the instructions below guide you through building LLVM by
hand.
Try the following. Say Release
instead of RelWithDebInfo
if you don't need
debug symbols and want to save some disk space. You should also set
-DLLVM_PARALLEL_LINK_JOBS=1
instead of 2 if you have less than ~32 GB of RAM.
You may want to leave out enabling assertions too, if you care about the
performance impact, but this may cause you other problems — see the
Debugging guide of the README). Also, on macOS,
you don't need to bother specifying -DLLVM_USE_LINKER=gold
since lld
is
fast enough (the GNU ld
installed on a typical GNU/Linux system is the slow
one). Also, -DLLVM_INSTALL_UTILS=TRUE
is important if you want to run the
test suite, since it installs the LLVM FileCheck tool we use in testing.
$ mkdir build && cd build
$ cmake -G Ninja -DLLVM_ENABLE_PROJECTS=mlir -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_ASSERTIONS=TRUE -DLLVM_PARALLEL_LINK_JOBS=2 -DCMAKE_INSTALL_PREFIX=/path_to_llvm_install_dir/ -DLLVM_TARGETS_TO_BUILD=Native -DLLVM_USE_LINKER=gold -DLLVM_INSTALL_UTILS=TRUE ../llvm
$ ninja install
You'll need to do the following as well:
$ export MLIR_DIR=/path_to_llvm_install_dir/lib/cmake/mlir/
$ export PATH=$PATH:/path_to_llvm_install_dir/bin/
You will probably want to put both export
s in your ~/.bashrc
.
I had luck following the LLVM guide for LLVM in Visual Studio. Here is some Qwerty-specific advice to complement their guide:
- Use the
git clone
command above withC:\qwerty
as your current directory (that is, clone LLVM atC:\qwerty\llvm-project
). Check out the tagllvmorg-19.1.6
. - When you install Python, if you want to do a debug build of the Qwerty
compiler, you should check "Download debugging symbols" and "Downloaded debug
binaries" under "Advanced Options" in the installer. This will install
python312_d.lib
(as opposed to onlypython312.lib
), without which you may see some linker errors when you do a debug build. (Note, however, that debug builds are currently broken on Windows due to other linker problems.) - I used the following
cmake
command line inside an administrator "x64 Native Tools Command Prompt for VS 2022":(Turning off DIA withcmake -S llvm\llvm -B build -DLLVM_ENABLE_PROJECTS=mlir -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=TRUE -DCMAKE_INSTALL_PREFIX=C:\qwerty\llvm19 -DLLVM_TARGETS_TO_BUILD=Native -DLLVM_ENABLE_DIA_SDK=OFF -Thost=x64 -DLLVM_INSTALL_UTILS=TRUE
-DLLVM_ENABLE_DIA_SDK=OFF
is more important than it looks; without it, the generated LLVM CMake scripts end up making the Qwerty CMake scripts attempt to link withC:/Program Files/Microsoft Visual Studio/2022/Community/DIA SDK/lib/amd64/diaguids.lib
, which may not exist on some systems, namely GitHub Actions hosts.) - The guide mentions this, but make sure that when you open
C:\qwerty\llvm\
, you choose "Release" as your configuration here:
- To build, you can right-click "ALL_BUILD" under
"CMakePredefinedTargets" in Solution Explorer and choose "Build":
This took about an hour on my machine, during which it was otherwise unusable. - To install, you can right-click "INSTALL" in the same place and again choose "Build". If you skip the previous step, this fails (in my experience).
- Press Start and type in "environment variables" (I would recommend editing
system variables, not user variables).
Set
MLIR_DIR
toC:\qwerty\llvm19\lib\cmake\mlir
and addC:\qwerty\llvm19\bin
toPath