Skip to content

Instantly share code, notes, and snippets.

@marler8997
Last active June 17, 2025 13:39
Show Gist options
  • Save marler8997/0717cca7ebc5dd700387ab8eb11db1d8 to your computer and use it in GitHub Desktop.
Save marler8997/0717cca7ebc5dd700387ab8eb11db1d8 to your computer and use it in GitHub Desktop.

Build LLVM for Zig on Windows

> mkdir c:\llvm20
> cd c:\llvm20

Install MSVC Build Tools

> curl -L -o msvcup.zip https://github.com/marler8997/msvcup/releases/download/v2025_06_16/msvcup-x86_64-windows.zip
> tar xf msvcup.zip
> del msvcup.zip

You now have msvcup.exe in the current directory, install MSVC build tools with:

> msvcup install msvc-14.44.17.14 sdk-10.0.22621.7 --lock-file msvcup.lock --manifest-update-off

Next, make an "autoenv" directory which allows us to use MSVC without being inside a "Visual Studio Developer Prompt".

> msvcup autoenv --target-cpu x64 --out-dir autoenv msvc-14.44.17.14 sdk-10.0.22621.7

The "autoenv" subdirectory will now have a set of ".exe" files like cl.exe and a toolchain.cmake you can use.

Install Cmake

> curl -L -o cmake.zip https://github.com/Kitware/CMake/releases/download/v4.0.3/cmake-4.0.3-windows-x86_64.zip
> tar xf cmake.zip
> del cmake.zip

Install Ninja

> curl -L -o ninja.zip https://github.com/ninja-build/ninja/releases/download/v1.12.1/ninja-win.zip
> tar xf ninja.zip
> del ninja.zip

Build LLVM/LLD/Clang

> git clone --depth 1 --branch llvmorg-20.1.7 https://github.com/llvm/llvm-project.git src

LLVM:

> cmake-4.0.3-windows-x86_64\bin\cmake -S src\llvm -B out-llvm-release -DCMAKE_BUILD_TYPE=Release -GNinja -DCMAKE_MAKE_PROGRAM=C:\llvm20\ninja.exe -DCMAKE_TOOLCHAIN_FILE=C:\llvm20\autoenv\toolchain.cmake -DLLVM_USE_CRT_RELEASE=MT -DCMAKE_INSTALL_PREFIX=C:\llvm20\install-release -DLLVM_ENABLE_ZLIB=OFF
> ninja -Cout-llvm-release install

LLD:

> cmake-4.0.3-windows-x86_64\bin\cmake -S src\lld -B out-lld-release -DCMAKE_BUILD_TYPE=Release -GNinja -DCMAKE_MAKE_PROGRAM=C:\llvm20\ninja.exe -DCMAKE_TOOLCHAIN_FILE=C:\llvm20\autoenv\toolchain.cmake -DLLVM_USE_CRT_RELEASE=MT -DCMAKE_INSTALL_PREFIX=C:\llvm20\install-release
> ninja -Cout-lld-release install

Clang:

> cmake-4.0.3-windows-x86_64\bin\cmake -S src\clang -B out-clang-release -DCMAKE_BUILD_TYPE=Release -GNinja -DCMAKE_MAKE_PROGRAM=C:\llvm20\ninja.exe -DCMAKE_TOOLCHAIN_FILE=C:\llvm20\autoenv\toolchain.cmake -DLLVM_USE_CRT_RELEASE=MT -DCMAKE_INSTALL_PREFIX=C:\llvm20\install-release -DCMAKE_PREFIX_PATH=C:\llvm20\install-release -DLLVM_INCLUDE_TESTS=OFF
> ninja -Cout-clang-release install

Build Zig

From your zig repository:

> mkdir build-release
> c:\llvm20\cmake-4.0.3-windows-x86_64\bin\cmake -S . -B build-release -DCMAKE_BUILD_TYPE=Release -GNinja -DCMAKE_MAKE_PROGRAM=C:\llvm20\ninja.exe -DCMAKE_TOOLCHAIN_FILE=C:\llvm20\autoenv\toolchain.cmake -DCMAKE_PREFIX_PATH=C:\llvm20\install-release
> C:\llvm20\ninja -Cbuild-release
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment