Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In order to build flang on a Windows on Arm machine, you will first need to setup your machine for LLVM development as described here: How to setup Windows 10 on Arm for llvm development

Info

We have moved regular LLVM development to Windows 11 while some information on this page is still valid overall, please follow https://linaro.atlassian.net/l/cp/6SWAH1pt page in order to setup your Windows 11 machines for LLVM development.

You will have to add flang, clang and mlir to the list of enabled projects.

...

Code Block
languagebash
REM You need to modify the paths below:
set build_dir=path\to\where\you\want\the\build (must alredy exist)
set clang_root=path\to\where\clang\is\installed
set clang_version=x.0.y (should match what’s in %clang_root%)

REM Some helper variables.
REM Setting CMAKE_CL_SHOWINCLUDES_PREFIX to work around PR27226.
set cmake_flags=^
  -DCMAKE_BUILD_TYPE=Release ^
  -DLLVM_ENABLE_ASSERTIONS=ON ^
  -DLLVM_INSTALL_TOOLCHAIN_ONLY=ON ^
  -DLLVM_BUILD_LLVM_C_DYLIB=ON ^
  -DCMAKE_INSTALL_UCRT_LIBRARIES=ON ^
  -DCMAKE_CL_SHOWINCLUDES_PREFIX="Note: including file: " ^
  -DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-unknown-windows-msvc ^
  -DLLVM_HOST_TRIPLE=aarch64-windows-msvc ^
  -DLLVM_TARGET_ARCH=AArch64 ^
  -DCLANG_DEFAULT_LINKER=lld 

cd %build_dir%

set clang_path=%clang_root%\bin\clang-cl.exe
set builtins_path=%clang_root%\lib\clang\%clang_version%\lib\windows
set builtins_lib=clang_rt.builtins-aarch64.lib

set CC=%clang_path%
set CXX=%clang_path%

REM We enable clang because it is needed by the flang driver.
cmake -GNinja %cmake_flags% ^
  -DLLVM_ENABLE_PROJECTS="clang;flang;mlir" ^
  -DLLVM_TARGETS_TO_BUILD="AArch64" ^
  -DCMAKE_C_FLAGS="-fms-compatibility-version=19.14" ^
  -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.14" ^
  -DCMAKE_EXE_LINKER_FLAGS="%builtins_path%/%builtins_lib%" ^
  ..\llvm-project\llvm || exit /b

ninja all || ninja all || ninja all || exit /b

...

However, if you want to build a flang that can generate actual binaries, you need to use custom development branches such as this one. The latter is based on the community’s fir-dev branch, which is currently in the process of being upstreamed, plus a few hacks and workarounds some minor changes to get things working on Windows on Arm. You can use the steps described above to build even this version of flang, and the resulting executable should be able to compile a simple ‘hello world’ with a bit of help from clang. See the example script for more details(to link it with the builtins, pass -Xlinker /path/to/clang_rt.builtins-aarch64.lib to flang, just as you did earlier to compile flang itself).

We are naturally working hard towards getting upstream flang to work on Windows on Arm in the cleanest way possible. Current progress is tracked in Jira.