build-llvm-binaries #113
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: build-llvm-binaries | |
on: | |
workflow_dispatch: | |
inputs: | |
llvm_version: | |
description: 'LLVM Version' | |
default: '17.0.6' | |
required: false | |
type: string | |
env: | |
SCCACHE_DIRECT: yes | |
jobs: | |
build_tools: | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [windows-latest, macos-latest, ubuntu-latest] | |
include: | |
# Default valuies | |
- c_compiler: clang | |
- cxx_compiler: clang++ | |
- executable_suffix: | |
# Overrides | |
- os: windows-latest | |
c_compiler: cl | |
cxx_compiler: cl | |
executable_suffix: .exe | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
repository: llvm/llvm-project | |
ref: llvmorg-${{ inputs.llvm_version }} | |
path: ${{ github.workspace }}/SourceCache/llvm-project | |
show-progress: false | |
- uses: compnerd/gha-setup-vsdevenv@main | |
- uses: seanmiddleditch/gha-setup-ninja@master | |
with: | |
version: 1.11.1 | |
- name: Setup sccache | |
uses: compnerd/[email protected] | |
with: | |
max-size: 100M | |
key: ${{ matrix.os }}-build_tools | |
restore-keys: ${{ matrix.os }}-build_tools | |
variant: sccache | |
append-timestamp: false | |
- name: Configure Tools | |
run: >- | |
cmake -B ${{ github.workspace }}/BinaryCache/0 | |
-D CMAKE_BUILD_TYPE=MinSizeRel | |
-D CMAKE_C_COMPILER=${{ matrix.c_compiler }} | |
-D CMAKE_C_COMPILER_LAUNCHER=sccache | |
-D CMAKE_CXX_COMPILER=${{ matrix.cxx_compiler }} | |
-D CMAKE_CXX_COMPILER_LAUNCHER=sccache | |
-D CMAKE_MT=mt | |
-G Ninja | |
-S ${{ github.workspace }}/SourceCache/llvm-project/llvm | |
-D LLVM_ENABLE_ASSERTIONS=NO | |
-D LLVM_ENABLE_LIBEDIT=NO | |
-D LLVM_ENABLE_PROJECTS="" | |
- name: Build tools | |
run: >- | |
cmake --build ${{ github.workspace }}/BinaryCache/0 | |
--target llvm-tblgen | |
--target llvm-config | |
- name: Archive tools | |
run: tar cf tools.tar bin | |
working-directory: ${{ github.workspace }}/BinaryCache/0 | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: build-tools-${{ matrix.os }} | |
path: ${{ github.workspace }}/BinaryCache/0/tools.tar | |
distribution: | |
needs: [build_tools] | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [windows-latest, macos-latest, ubuntu-latest] | |
arch: [x86_64, arm64] | |
configuration: [Debug, MinSizeRel] | |
include: | |
# Default values | |
- c_compiler: clang | |
- cmake_find_root_path_option: | |
- cmake_system_processor_option: | |
- compile_cache_max_size: 1G | |
- cxx_compiler: clang++ | |
- executable_suffix: | |
- into_environment: '>> $GITHUB_ENV' | |
- llvm_target_arch_option: | |
- package_command: tar --zstd -cf | |
- package_suffix: .tar.zst | |
- static_lib_suffix: .a | |
- toolset_suffix: | |
- triple_cpu: | |
- install_target: install-distribution-stripped | |
- llvm_distribution_tools: addr2line;ar;c++filt;dsymutil;dwp;lld;llvm-ar;llvm-config;llvm-cov;llvm-cvtres;llvm-cxxfilt;llvm-dlltool;llvm-dwarfdump;llvm-dwp;llvm-lib;llvm-lipo;llvm-mt;llvm-nm;llvm-objcopy;llvm-objdump;llvm-pdbutil;llvm-profdata;llvm-ranlib;llvm-rc;llvm-readelf;llvm-readobj;llvm-size;llvm-strings;llvm-strip;llvm-symbolizer;llvm-undname;nm;objcopy;objdump;ranlib;readelf;size;strings | |
- zstd_root_option: | |
# Overrides | |
- configuration: Debug | |
compile_cache_max_size: 2G | |
install_target: install-distribution | |
llvm_distribution_tools: lld;llvm-config | |
- os: windows-latest | |
c_compiler: cl | |
cxx_compiler: cl | |
executable_suffix: .exe | |
into_environment: '| Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append' | |
package_command: 7z a -t7z | |
package_suffix: .7z | |
static_lib_suffix: .lib | |
toolset_suffix: -msvc17 | |
- arch: x86_64 | |
triple_cpu: x86_64 | |
- arch: arm64 | |
cmake_find_root_path_option: >- | |
-D CMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER | |
-D CMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY | |
-D CMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY | |
-D CMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY | |
cmake_system_processor_option: -D CMAKE_SYSTEM_PROCESSOR=arm64 | |
llvm_target_arch_option: -D LLVM_TARGET_ARCH=arm64 | |
triple_cpu: arm64 | |
- arch: arm64 | |
os: ubuntu-latest | |
cmake_system_processor_option: -D CMAKE_SYSTEM_PROCESSOR=aarch64 | |
c_compiler: aarch64-linux-gnu-gcc | |
cxx_compiler: aarch64-linux-gnu-g++ | |
triple_cpu: aarch64 | |
- arch: arm64 | |
os: macos-latest | |
zstd_root_option: -D zstd_ROOT=/opt/local | |
# Extensions | |
- arch: arm64 | |
llvm_backend_libs: 'LLVMAArch64AsmParser;LLVMAArch64CodeGen;LLVMAArch64Desc;LLVMAArch64Disassembler;LLVMAArch64Info;LLVMAArch64Utils' | |
- arch: x86_64 | |
llvm_backend_libs: 'LLVMX86AsmParser;LLVMX86CodeGen;LLVMX86Desc;LLVMX86Disassembler;LLVMX86Info;LLVMX86TargetMCA' | |
- os: windows-latest | |
cmake_system_name: Windows | |
triple_suffix: unknown-windows-msvc17 | |
- os: ubuntu-latest | |
cmake_system_name: Linux | |
triple_suffix: unknown-linux-gnu | |
- os: macos-latest | |
cmake_system_name: Darwin | |
triple_suffix: apple-darwin23.3.0 | |
runs-on: ${{ matrix.os }} | |
env: | |
cmake_c_compiler_target_option: ${{ matrix.arch != 'x86_64' && format('-D CMAKE_C_COMPILER_TARGET={0}-{1}', matrix.triple_cpu, matrix.triple_suffix) || '' }} | |
cmake_cxx_compiler_target_option: ${{ matrix.arch != 'x86_64' && format('-D CMAKE_CXX_COMPILER_TARGET={0}-{1}', matrix.triple_cpu, matrix.triple_suffix) || '' }} | |
cmake_system_name_option: ${{ matrix.arch != 'x86_64' && format('-D CMAKE_SYSTEM_NAME={0}', matrix.cmake_system_name) || '' }} | |
llvm_host_triple_option: ${{ matrix.arch != 'x86_64' && format('-D LLVM_HOST_TRIPLE={0}-{1}', matrix.triple_cpu, matrix.triple_suffix) || '' }} | |
PACKAGE_NAME: llvm-${{ inputs.llvm_version }}-${{ matrix.triple_cpu }}-${{ matrix.triple_suffix }}-${{ matrix.configuration }} | |
steps: | |
# https://github.com/actions/runner-images/issues/2840#issuecomment-790492173 | |
- name: Free up disk space for debug builds | |
if: ${{ matrix.os == 'ubuntu-latest' }} | |
run: | | |
sudo rm -rf /usr/share/dotnet | |
sudo rm -rf /opt/ghc | |
sudo rm -rf "/usr/local/share/boost" | |
sudo rm -rf "$AGENT_TOOLSDIRECTORY" | |
- uses: actions/download-artifact@v4 | |
with: | |
name: build-tools-${{ matrix.os }} | |
path: ${{ github.workspace }}/BinaryCache/0 | |
- name: Extract tools | |
run: tar xf tools.tar | |
working-directory: ${{ github.workspace }}/BinaryCache/0 | |
- name: Clean up artifact | |
run: ${{ matrix.os == 'windows-latest' && 'Remove-Item' || 'rm' }} tools.tar | |
working-directory: ${{ github.workspace }}/BinaryCache/0 | |
- uses: actions/checkout@v4 | |
with: | |
repository: llvm/llvm-project | |
ref: llvmorg-${{ inputs.llvm_version }} | |
path: ${{ github.workspace }}/SourceCache/llvm-project | |
show-progress: false | |
- uses: actions/checkout@v4 | |
with: | |
path: ${{ github.workspace }}/SourceCache/llvm-build | |
show-progress: false | |
- name: Patch LLVM | |
run: git apply ${{ github.workspace }}/SourceCache/llvm-build/llvm.patch | |
working-directory: ${{ github.workspace }}/SourceCache/llvm-project | |
- uses: seanmiddleditch/gha-setup-ninja@master | |
with: | |
version: 1.11.1 | |
- name: Setup sccache | |
uses: compnerd/[email protected] | |
with: | |
max-size: ${{ matrix.compile_cache_max_size }} | |
key: ${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.configuration }}-package | |
restore-keys: ${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.configuration }}-package | |
variant: sccache | |
append-timestamp: false | |
- uses: compnerd/gha-setup-vsdevenv@main | |
with: | |
host_arch: amd64 | |
toolset_version: 14.37.32822 | |
components: 'Microsoft.VisualStudio.Component.VC.14.37.17.7.x86.x64;Microsoft.VisualStudio.Component.VC.14.37.17.7.ARM64' | |
arch: ${{ matrix.arch == 'arm64' && 'arm64' || 'amd64' }} | |
- name: Workaround MSVC#10444970 | |
if: ${{ matrix.arch == 'arm64' && matrix.os == 'windows-latest' }} | |
run: | | |
$clangTooling = "${{ github.workspace }}/SourceCache/llvm-project/clang/lib/Tooling/Inclusions/Stdlib/CMakeLists.txt" | |
Set-Content $clangTooling @" | |
$(Get-Content -Raw $clangTooling) | |
set_source_files_properties(StandardLibrary.cpp PROPERTIES | |
COMPILE_FLAGS "/Od /Gw /Oi /Oy /Gw /Ob2 /Ot /GF") | |
"@ | |
$clangCodeGen = "${{ github.workspace }}/SourceCache/llvm-project/clang/lib/CodeGen/CMakeLists.txt" | |
Set-Content $clangCodeGen @" | |
$(Get-Content -Raw $clangCodeGen) | |
set_source_files_properties(CGBuiltin.cpp PROPERTIES | |
COMPILE_FLAGS "/Od /Gw /Oi /Oy /Gw /Ob2 /Ot /GF") | |
"@ | |
- name: Native prerequisites (macOS) | |
if: ${{ matrix.os == 'macos-latest' && matrix.arch == 'x86_64' }} | |
run: brew install zstd | |
- name: Cross-build prerequisites (macOS) | |
if: ${{ matrix.os == 'macos-latest' && matrix.arch != 'x86_64' }} | |
uses: melusina-org/setup-macports@v1 | |
with: | |
parameters: ${{ github.workspace }}/SourceCache/llvm-build/.github/parameters/setup-macports.yaml | |
- name: Cross-build prerequisites (ubuntu) | |
if: ${{ matrix.os == 'ubuntu-latest' && matrix.arch != 'x86_64' }} | |
run: | | |
sudo dpkg --add-architecture arm64 | |
sudo sed -i '' -Ee 's#^deb (http://[^/]+/ubuntu/) (.*)#deb [arch=amd64,i386] \1 \2\ndeb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ \2#g' /etc/apt/sources.list | |
sudo apt-get update | |
sudo apt-get build-dep -a arm64 llvm | |
sudo apt-get install aarch64-linux-gnu-g++ aarch64-linux-gnu-gcc | |
- name: Configure LLVM | |
run: >- | |
cmake -GNinja | |
-D CMAKE_BUILD_TYPE=${{ matrix.configuration }} | |
-S ${{ github.workspace }}/SourceCache/llvm-project/llvm | |
-B ${{ github.workspace }}/BinaryCache/1 | |
-C ${{ github.workspace }}/SourceCache/llvm-build/cmake/caches/LLVM.cmake | |
-D CMAKE_C_COMPILER=${{ matrix.c_compiler }} | |
-D CMAKE_C_COMPILER_LAUNCHER=sccache | |
${{ env.cmake_c_compiler_target_option }} | |
-D CMAKE_CXX_COMPILER=${{ matrix.cxx_compiler }} | |
-D CMAKE_CXX_COMPILER_LAUNCHER=sccache | |
${{ env.cmake_cxx_compiler_target_option }} | |
${{ matrix.cmake_find_root_path_option }} | |
-D CMAKE_MSVC_DEBUG_INFORMATION_FORMAT=Embedded | |
-D CMAKE_MT=mt | |
-D CMAKE_INSTALL_PREFIX=${{ github.workspace }}/BuildRoot/${{ env.PACKAGE_NAME }} | |
${{ env.cmake_system_name_option }} | |
${{ matrix.cmake_system_processor_option }} | |
-D LLVM_DISTRIBUTION_COMPONENTS="${{ matrix.llvm_backend_libs }};LLVMAggressiveInstCombine;LLVMAnalysis;LLVMAsmParser;LLVMAsmPrinter;LLVMBinaryFormat;LLVMBitReader;LLVMBitWriter;LLVMBitstreamReader;LLVMCFGuard;LLVMCodeGen;LLVMCodeGenTypes;LLVMCore;LLVMCoroutines;LLVMDebugInfoBTF;LLVMDebugInfoCodeView;LLVMDebugInfoDWARF;LLVMDebugInfoMSF;LLVMDebugInfoPDB;LLVMDemangle;LLVMFrontendOpenMP;LLVMGlobalISel;LLVMIRPrinter;LLVMIRReader;LLVMInstCombine;LLVMInstrumentation;LLVMLinker;LLVMMC;LLVMMCA;LLVMMCDisassembler;LLVMMCParser;LLVMObjCARCOpts;LLVMObject;LLVMPasses;LLVMProfileData;LLVMRemarks;LLVMScalarOpts;LLVMSelectionDAG;LLVMSupport;LLVMSymbolize;LLVMTarget;LLVMTargetParser;LLVMTextAPI;LLVMTransformUtils;LLVMVectorize;LLVMipo;llvm-headers;cmake-exports;lld-cmake-exports;${{ matrix.llvm_distribution_tools }}" | |
-D LLVM_CONFIG_PATH=${{ github.workspace }}/BinaryCache/0/bin/llvm-config${{ matrix.executable_suffix }} | |
-D LLVM_NATIVE_TOOL_DIR=${{ github.workspace }}/BinaryCache/0/bin | |
-D LLVM_TABLEGEN=${{ github.workspace }}/BinaryCache/0/bin/llvm-tblgen${{ matrix.executable_suffix }} | |
-D LLVM_USE_HOST_TOOLS=NO | |
-D PACKAGE_VENDOR=hylo-lang.org | |
-D LLVM_APPEND_VC_REV=NO | |
-D LLVM_ENABLE_PROJECTS="lld" | |
${{ env.llvm_host_triple_option }} | |
-D LLVM_PARALLEL_LINK_JOBS=2 | |
${{ matrix.llvm_target_arch_option }} | |
-D LLVM_VERSION_SUFFIX="" | |
${{ matrix.zstd_root_option }} | |
- name: Build LLVM | |
run: cmake --build ${{ github.workspace }}/BinaryCache/1 --target distribution | |
- name: Reclaim disk space | |
if: ${{ matrix.os != 'windows-latest' }} | |
run: find ${{ github.workspace }}/BinaryCache/ -name '*.o' -print0 | xargs -0 rm | |
- name: Install LLVM | |
run: cmake --build ${{ github.workspace }}/BinaryCache/1 --target ${{ matrix.install_target }} | |
- name: Package LLVM | |
working-directory: ${{ github.workspace }}/BuildRoot/ | |
run: >- | |
${{ matrix.package_command }} ${{ github.workspace }}/${{ env.PACKAGE_NAME }}${{ matrix.package_suffix }} ${{ env.PACKAGE_NAME }} | |
- name: Release | |
uses: softprops/action-gh-release@v1 | |
if: startsWith(github.ref, 'refs/tags/') | |
with: | |
files: ${{ env.PACKAGE_NAME }}${{ matrix.package_suffix }} |