Skip to end of banner
Go to start of banner

How to build flang on Windows on Arm (WIP)

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 7 Next »

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 on Arm for llvm development

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

At the moment, due to a bug that needs further investigation, clang is failing to find the builtins, and adding the path to the builtin library as described in the https://clang.llvm.org/docs/UsersManual.html#finding-clang-runtime-libraries doesn’t seem to be working (bug report pending, since the LLVM bugzilla is currently locked due to the upstream migration to Github issues). However, we can work around this issue by adding the builtin library directly on every link command (-DCMAKE_EXE_LINKER_FLAGS=path/to/clang_rt.builtins-aarch64.lib).

You should end up with a script that looks something like this:

REM You need to modify the paths below:
set build_dir=path\to\where\you\want\the\build
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-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

Depending on which revision of flang you’re building, you should now have one or both of f18.exe or flang-new.exe in %build_dir%/bin.

At the time of writing, clang version 13.0.0 is known to work for building flang. The flang binary obtained from main does not have support for code generation yet. A prototype for this exists in the fir-dev branch and should be upstreamed in the hopefully near future. However, even a flang built from the fir-dev branch is not currently capable of compiling a hello world on windows on arm. Current progress towards that goal is tracked in Jira.

  • No labels