Skip to end of banner
Go to start of banner

How to setup Windows on Arm for llvm development

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 16 Next »

This describes how to setup a Windows on Arm laptop to build llvm.

Adding to the PATH

For all the steps below you’ll need to put things on the PATH, if an installer doesn’t do it for you. To do that open the start menu, type “environment” and open the link to “System Properties”. There click “Environment Variables” to see a GUI for editing them.

Note that we configure the RunAsRob service that runs buildbot to run as “tcwg”, not “System” user, so environment changes will also apply to the buildbot.

Note: just like in Unix, adding to the path doesn’t refresh active terminals. You’ll need to open a fresh one/google the “source ~/.bashrc” equivalent for Windows.

Install Visual Studio Build Tools

This is the command line portion of visual studio, download it from https://visualstudio.microsoft.com/downloads/ . (“Tools for Visual Studio 2019” → “Build Tools for Visual Studio 2019”)

The Visual Studio installer has many options but generally, you want various things to do with C++ desktop development for ARM64. (there are some ARM components, these are Arm 32 bit, we don’t need those).

If you have build issues later, come back to the installer and add anything that seems relevant. Here’s the list of what is minimally needed, check this against “Individual Components” in your “Installation Details” panel:

  • MSVC v142 - VS 2019 C++ x64/x86 build tools (latest)

    • This is needed to make vsdevcmd.bat correctly setup LIB/LIBPATH/INCLUDE variables for x86->arm64 cross-compilation. All the lib/header files are actually present, but vsdevcmd.bat doesn’t add them without x86-hosted tools.

    • Installing this may become optional in the future

  • MSVC v142 - VS 2019 C++ ARM64 build tools (latest)

    • Without these vsdecmd.bat doesn’t setup x86->arm64 cross-compilation.

  • C++ ATL for latest v142 build tools (ARM64)

    • LLVM uses ATL libraries

  • Windows 10 SDK

    • Versions … are known to work

    • Version 20348 is known to cause LLVM build failure

    • This is required for correct cross-compilation setup. Not sure if SDK libraries are actually used

Note: there’s probably a choice in the installer for where to install to. If you do that modify any instructions as needed. The default that I got was “C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\”.

(worst case, you can always search C:\ for a file, it isn’t as slow as you’d expect)

Install MSVC Redist libraries

Search filesystem for vc_redist.arm64.exe, and you’ll most likely find it in C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Redist\MSVC\v142\ .

Install these libraries to get msvcp140.dll, vcruntime140.dll, concrt140.dll and other libraries. Without these DLLs MSVC-built application will not run; in LLVM build this manifests itself as llvm-tblgen.exe failing.

Why these libraries aren’t installed by default in the OS or, at the very least, as part of VS installation – escapes me.

Install latest llvm for Windows on Arm

Go to https://github.com/llvm/llvm-project/releases/tag/llvmorg-12.0.0 and download the Windows on Arm (“woa64”) installer. Run it and if it asks to add llvm to the path say yes. If it doesn’t or you forget that you can always add …/LLVM/bin to PATH yourself.

Install CMake

Recent versions of VS ship cmake as x86_64 binary (in VS circa-2020.08 cmake was x86_32 binary). Instead install the i386 build from https://cmake.org/download/ and add that to user’s PATH.

Install Python

If you run “python” it takes you to the Windows Store which allegedly will give you a (native?) copy of Python3. As per usual with the Windows Store, it didn’t do anything when I clicked install.

So instead, you can go to Python.org and get a 32 bit build of the latest Python3. Remember to

  1. tell the installer to add python variables to environment (so that cmake can find python3)

  2. tell the installer to install debug libs, if you want to build a debug lldb. (everything else is fine with a release Python afaict)

Install Git

Usual thing, go to https://git-scm.com/download/win and get the latest 32 bit installer. Again there’s probably a git in the build tools install, so if you can use that more power to you, however -

Installing git also gives you a bunch of command line tools that lit needs for testing:

llvm-lit.py: C:\Work\david.spickett\llvm-project\llvm\utils\lit\lit\llvm\config.py:46: note: using lit tools: C:\Program Files (x86)\Git\usr\bin

(you can get these by installing MSYS2 instead, git for windows is based on anyway that I think)

Build Ninja

Again build tools can/does come with a ninja but the default one doesn’t run on WoA. I built ninja from source (https://github.com/ninja-build/ninja ) using the cmake build method.

Checking out LLVM

The git for windows install will default to converting line endings to windows style. This applies to any file git thinks is ASCII, which includes some archive files used for llvm tests. As stated in https://llvm.org/docs/GettingStarted.html#checkout-llvm-from-git , use the following to override this behaviour:

git clone --config core.autocrlf=false https://github.com/llvm/llvm-project.git

Testing the Install

First, open a plain terminal “Command Prompt”. Ignore the cross prompts shortcuts you might find in the start menu.

Then run VsDevCmd.bat to setup the environment.

"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\VsDevCmd.bat" -host_arch=x86 -arch=arm64
<...>
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\VsDevCmd.bat" -test
<...>
set PATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\DIA SDK\bin\arm64;%PATH%

If the second test command fails, your build probably won’t work. If figuring out why it failed is tricky, just go ahead and do a build and the compiler’s errors will probably be more informative.

Note: We setup the Visual Studio env first because it adds some copies of cmake and ninja that we don’t want. By doing it first, then checking cmake and ninja, we know if our preferred versions are being used.

Note: We have to add the arm64 DIA (debug information access) DLL onto the path otherwise it will find the x86_32 version in BuildTools\Common7\IDE.

Now check that cmake and ninja can run at all.

ninja --version
cmake --version

Doing a Build

(in the same command prompt from above)
Set your compiler(s) to be the clang-cl.exe we installed earlier.

set "CC=clang-cl.exe"
set "CXX=clang-cl.exe"

Then make a folder next to your llvm checkout and from that folder:

cmake ..\llvm-project\llvm -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;lldb;lld;llvm" -DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_C_FLAGS="-fms-compatibility-version=19.14" -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.14" -DCMAKE_TRY_COMPILE_CONFIGURATION=Release -DLLVM_DEFAULT_TARGET_TRIPLE="arm64-pc-windows-msvc" -G Ninja

Some specifics:

  • https://reviews.llvm.org/D92515 bumped llvm’s required MSVC version, ironically meaning that clang-cl version 12 can’t build it. That’s why we need the “ms-compatibility-version" flag to have clang-cl pretend to be a newer MSVC.

  • Known issue with cmake 3.21.1, it builds all try_compile/try_run as debug even if you select release mode. This is why we set “-DCMAKE_TRY_COMPILE_CONFIGURATION=Release”. Not doing so causes a try_run to fail to get error message strings, so lit defaults to Linux strings and a bunch of tests fail.

  • We set LLVM_DEFAULT_TARGET_TRIPLE manually because the prompt we use is an x86 32 bit host prompt. There is no arm64 to arm64 prompt, so cmake detects the host/default target triple “correctly” but it’s not what we really want.

Then build as usual with ninja.

Here is where you might get errors about includes and linker directories and so on. Best way to solve this is to go back to the Visual Studio Installer and add anything that looks related.

You will find things online about adding certain dirs to your path but be careful because you could just be adding x86 libs. Installing ARM64 specific variants is almost always what you want.

If you’re doing a debug build and you see linker errors about missing libs, see if the file names end with “d”. E.g. “foo.lib” would be “food.lib” for a debug build. When I had this issue I think I did actually add those libs to Path, but I’m not sure that’s the way you’re supposed to do it.

Excluding the test folder from Windows Defender

Windows Defender likes to scan new files, including those that tests create. Which can change their last accessed times. There’s at least one test known to fail because of this, “LLVM :: ThinLTO/X86/cache.ll”. To exclude the folder follow https://support.microsoft.com/en-us/windows/add-an-exclusion-to-windows-security-811816c0-4dfd-af4a-47e4-c301afe13b26 and add “<llvm-build-dir>/test”. (you shouldn’t need to restart defender or the machine, it takes effect automatically)

  • No labels