Building llvm-mos on Windows

From llvm-mos

Generally speaking, builds of llvm-mos on Windows are finicky and opinionated, because LLVM itself is finicky and opinionated to build on Windows. I use a stable release of LLVM to compile LLVM.

When checking out from git, it's important to make sure that core.autocrlf is set to False. Windows installations strongly encourage you to set this to true, but if you do, then LLVM acceptance tests will fail.

To set up a Windows development and testing machine, I install Chocolatey first, at an administrator PowerShell prompt:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

Then, I run the following commands to install all prerequisites:

choco install git.install --params "/NoAutoCrlf"
choco install cmake python llvm vscode ninja visualstudio2019community visualstudio2019-workload-nativedesktop 

The LLVM documentation suggests that you need the GnuWin32 utilities, but I don't think that's necessary; you can simply use the ones that the Windows version of git installs at C:/Program Files/git/usr/bin . You can point the LLVM_LIT_TOOLS_DIR build variable at that directory, and llvm-lit will use all the tools in that directory for building the check-all target.

As of this writing, my Windows build batch file looks like this:

set "WORKSPACE_FORWARD_SLASH=%WORKSPACE:\=/%"
set LLVM_BIN=C:/Progra~1/LLVM/bin
cmake ../../llvm -G Ninja -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="MOS" -DLLVM_OPTIMIZED_TABLEGEN=1 -DLLVM_ENABLE_PROJECTS="clang;lld" -DLIBXML2_LIBRARIES=IGNORE -DCMAKE_INSTALL_PREFIX=%WORKSPACE_FORWARD_SLASH%/build/install -DCMAKE_AR=%LLVM_BIN%/llvm-ar -DCMAKE_RANLIB=%LLVM_BIN%/llvm-ranlib -DCMAKE_C_COMPILER=%LLVM_BIN%/clang-cl.exe -DCMAKE_CXX_COMPILER=%LLVM_BIN%/clang-cl.exe -DCMAKE_LINKER=%LLVM_BIN%/lld-link.exe -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_TARGETS_TO_BUILD=all -DLLVM_LIT_TOOLS_DIR="C:/Program Files/git/usr/bin"
cmake --build . --config Release --target check-all
cmake --build . --config Release --target install