Skip to content

Latest commit

 

History

History
150 lines (125 loc) · 9.61 KB

BUILD.md

File metadata and controls

150 lines (125 loc) · 9.61 KB

Building LLVM on Windows

LLVM project This document presents our build from the LLVM source distribution on a Windows machine.

build.bat

Command build.bat consists of ~350 lines of batch/PowerShell code we wrote to generate additional Windows binaries not available in the LLVM binary distribution.

🔎 For instance, LLVM tools such as llvm-as.exe (assembler), llvm-dis.exe (disassembler), opt.exe (optimizer), llc.exe (static compiler) and lli.exe (bitcode interpreter) are not part of the LLVM binary distribution (e.g. LLVM-15.0.7-win64.exe).

Usage examples

Directory llvm-15.0.7.src\ 1 is setup as follows:

> curl -sL -o llvm-15.0.7.src.tar.xz https://github.com/llvm/llvm-project/releases/tag/llvmorg-15.0.7/llvm-15.0.7.src.tar.xz
> tar xzvf llvm-15.0.7.src.tar.xz
> cp bin\llvm\build.bat llvm-15.0.7.src
> cd llvm-15.0.7.src

🔎 In our case we successively worked with versions 8.0.1, 9.0.1, 10.0.1, 11.0.1, 11.1.0, 12.0.1, 13.0.1, 14.0.6, 15.0.6 of the LLVM source distribution and today we build our binaries from directory L:\llvm-15.0.7.src\.

Command build.bat -verbose compile 2 generates the additional binaries (both .exe and .lib files) into directory build\Release\ (resp. build\Debug\). Be patient, build time is about 55 minutes on an Intel i7-4th with 16 GB of memory.

> cd
L:\llvm-15.0.7.src
 
> build -verbose compile
Toolset: MSVC/MSBuild, Project: LLVM
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.11.11
** Copyright (c) 2019 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
INCLUDE="..."
LIB="..."
Configuration: Debug, Platform: x64
[build] Current directory is: L:\llvm-15.0.7.src\build
[...]
 
> dir build\Release\bin\ll?.exe | findstr /b [0-9]
07.12.2022  08:07        72 299 520 llc.exe
07.12.2022  08:08        23 104 512 lli.exe

🔎 Command build -verbose run also execute lli.exe -version at the end of the build process :

[...]
Generate LLVM executables (LLVM.sln)
Execute build\Release\bin\lli.exe --version
LLVM (http://llvm.org/):
  LLVM version 15.0.7
  Optimized build.
  Default target: x86_64-pc-windows-msvc
  Host CPU: haswell

Command build.bat -verbose install copies the generated binaries to the LLVM installation directory (in our case C:\opt\LLVM-15.0.7\).

> build -verbose install
Do really want to copy files from 'build\' to 'c:\opt\LLVM-15.0.7\' (Y/N)? y
Copy files from directory build\Release\bin to C:\opt\LLVM-15.0.7\bin\
Copy files from directory build\Release\lib to C:\opt\LLVM-15.0.7\lib\
Copy files from directory build\lib\cmake to C:\opt\LLVM-15.0.7\lib\cmake\
Copy files from directory include to C:\opt\LLVM-15.0.7\include\

🔎 Before installation our LLVM installation directory contains 18 llvm-*.exe executables:

> where /r c:\opt\LLVM-15.0.7 llvm*.exe | wc -l
18

and after installation it contains 78 llvm-*.exe executables:

> where /r c:\opt\LLVM-15.0.7 llvm*.exe | wc -l
78

We list below several executables in the LLVM installation directory; e.g. commands like clang.exe, lld.exe and lldb.exe belong to the orginal distribution while commands like llc.exe, lli.exe and opt.exe were build/added from the LLVM source distribution.

> where /t clang llc lld lldb lli opt
 111801856   30.11.2022      10:46:14  C:\opt\LLVM-15.0.7\bin\clang.exe
  72299520   07.12.2022      01:34:48  C:\opt\LLVM-15.0.7\bin\llc.exe
  82472960   30.11.2022      10:48:04  C:\opt\LLVM-15.0.7\bin\lld.exe
    215552   30.11.2022      10:50:04  C:\opt\LLVM-15.0.7\bin\lldb.exe
  23104512   07.12.2022      01:35:01  C:\opt\LLVM-15.0.7\bin\lli.exe
  77778432   07.12.2022      01:43:52  C:\opt\LLVM-15.0.7\bin\opt.exe

Footnotes

[1] Cmake modules

In order to successfully generate the LLVM distribution from the sources we need to copy some missing CMake files to directory L:\llvm-X.Y.Z.src\cmake\modules\:

LLVM versionCMake files
15ExtendPath.cmake
FindPrefixFromConfig.cmake
16CMakePolicy.cmake
ExtendPath.cmake
FindPrefixFromConfig.cmake
GNUInstallPackageDir.cmake

[2] CmakeLists.txt

We need to comment out the lines marked with #ME# in file CMakeLists.txt in order to build a LLVM distribution in our Windows environment :

if (LLVM_INCLUDE_BENCHMARKS)
  ...
  # Since LLVM requires C++11 it is safe to assume that std::regex is available.
  set(HAVE_STD_REGEX ON CACHE BOOL "OK" FORCE)
  #ME# add_subdirectory(${LLVM_THIRD_PARTY_DIR}/benchmark 
  #ME#   ${CMAKE_CURRENT_BINARY_DIR}/third-party/benchmark)
  #ME# add_subdirectory(benchmarks)
endif()


mics/August 2024