build-llvm-binaries #177
Workflow file for this run
This file contains hidden or 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: | |
| push: | |
| branches: [ main ] | |
| paths-ignore: | |
| - "**.md" | |
| - "LICENSE" | |
| - ".gitignore" | |
| workflow_dispatch: | |
| inputs: | |
| llvm_version: | |
| description: 'LLVM Version' | |
| required: true | |
| default: '20.1.6' | |
| type: string | |
| env: | |
| SCCACHE_DIRECT: true | |
| llvm_version: ${{ github.event.inputs.llvm_version }} | |
| jobs: | |
| create_tag: | |
| runs-on: ubuntu-22.04 | |
| outputs: | |
| tag_name: ${{ steps.timestamp.outputs.time }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| show-progress: false | |
| - name: Capture time | |
| uses: Kaven-Universe/github-action-current-date-time@v1 | |
| id: timestamp | |
| with: | |
| format: "YYYYMMDD-HHmmss" | |
| - name: Create the tag. | |
| uses: EndBug/latest-tag@latest | |
| with: | |
| ref: ${{ steps.timestamp.outputs.time }} | |
| distribution: | |
| needs: [create_tag] | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [windows-2025, macos-14, ubuntu-22.04] | |
| arch: [x86_64, arm64] | |
| configuration: [Debug, MinSizeRel] | |
| include: | |
| # Default values | |
| - c_compiler: clang | |
| - cmake_msvc_options: | |
| - 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-2025 | |
| c_compiler: cl | |
| # Swift's runtime is compiled this way, and can't be | |
| # linked to a C++ binary other settings. | |
| cmake_msvc_options: -D CMAKE_CXX_FLAGS=-D_ITERATOR_DEBUG_LEVEL=0 -D CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL | |
| cxx_compiler: cl | |
| executable_suffix: .exe | |
| into_environment: '| Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append' | |
| 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-22.04 | |
| 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-14 | |
| 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-2025 | |
| cmake_system_name: Windows | |
| triple_suffix: unknown-windows-msvc17 | |
| - os: ubuntu-22.04 | |
| cmake_system_name: Linux | |
| triple_suffix: unknown-linux-gnu | |
| - os: macos-14 | |
| cmake_system_name: Darwin | |
| triple_suffix: apple-darwin24.1.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-${{ github.event.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: ${{ runner.os == 'Linux' }} | |
| 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/checkout@v4 | |
| with: | |
| path: ./SourceCache/llvm-build | |
| show-progress: false | |
| - name: Set up LLVM build tools and sources | |
| uses: ./SourceCache/llvm-build/.github/actions/build-tools | |
| with: | |
| llvm_version: ${{ env.llvm_version }} | |
| - uses: seanmiddleditch/gha-setup-ninja@master | |
| with: | |
| version: 1.11.1 | |
| - name: Setup sccache | |
| id: sccache | |
| uses: compnerd/[email protected] | |
| with: | |
| max-size: ${{ matrix.compile_cache_max_size }} | |
| key: ${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.configuration }}-package | |
| variant: sccache | |
| append-timestamp: false | |
| - uses: compnerd/gha-setup-vsdevenv@main | |
| - name: Workaround MSVC#10444970 | |
| if: ${{ matrix.arch == 'arm64' && runner.os == 'Windows' }} | |
| 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: Install prerequisites (macOS) | |
| if: ${{ runner.os == 'macOS' }} | |
| run: brew install zstd | |
| - name: Cross-build prerequisites (ubuntu) | |
| if: ${{ runner.os == 'Linux' && matrix.arch != 'x86_64' }} | |
| run: | | |
| sudo dpkg --add-architecture arm64 | |
| # See answer #4 at https://answers.launchpad.net/ubuntu/+source/apt/+question/661407 | |
| sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak | |
| sudo sed -E \ | |
| -e 's#^deb[[:space:]]+([^[:space:]]+)[[:space:]]+(.*)#deb [arch=amd64,i386] \1 \2\ndeb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports/ \2#g' \ | |
| -e 's/^# deb-src /deb-src /' \ | |
| -e 'w /etc/apt/sources.list' \ | |
| /etc/apt/sources.list.bak | |
| cat /etc/apt/sources.list | |
| sudo apt-get update | |
| sudo apt-get build-dep -a arm64 llvm | |
| sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu | |
| - 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_msvc_options }} | |
| ${{ matrix.cmake_system_processor_option }} | |
| -D LLVM_DISTRIBUTION_COMPONENTS="${{ matrix.llvm_backend_libs }};LLVMAggressiveInstCombine;LLVMAnalysis;LLVMAsmParser;LLVMAsmPrinter;LLVMBinaryFormat;LLVMBitReader;LLVMBitWriter;LLVMBitstreamReader;LLVMCFGuard;LLVMCGData;LLVMCodeGen;LLVMCodeGenTypes;LLVMCore;LLVMCoroutines;LLVMDebugInfoBTF;LLVMDebugInfoCodeView;LLVMDebugInfoDWARF;LLVMDebugInfoMSF;LLVMDebugInfoPDB;LLVMDemangle;LLVMFrontendAtomic;LLVMFrontendOffloading;LLVMFrontendOpenMP;LLVMGlobalISel;LLVMHipStdPar;LLVMIRPrinter;LLVMIRReader;LLVMInstCombine;LLVMInstrumentation;LLVMLinker;LLVMMC;LLVMMCA;LLVMMCDisassembler;LLVMMCParser;LLVMObjCARCOpts;LLVMObject;LLVMPasses;LLVMProfileData;LLVMRemarks;LLVMSandboxIR;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 ${{ runner.os == 'Windows' && matrix.configuration == 'Debug' && '--verbose' || '' }} | |
| - name: Reclaim disk space | |
| if: ${{ runner.os != 'Windows' }} | |
| 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: Patch VS path in LLVMExports.cmake (Windows only) | |
| if: ${{ matrix.runner == 'Windows' }} | |
| shell: pwsh | |
| working-directory: ${{ github.workspace }}/BuildRoot/${{ env.PACKAGE_NAME }} | |
| run: | | |
| pwsh -File ${{ github.workspace }}/SourceCache/llvm-build/scripts/fix-vs.ps1 | |
| - name: Make llvm.pc pkg-config file | |
| shell: bash | |
| run: '"${{ github.workspace }}/SourceCache/llvm-build/scripts/make-pkgconfig.sh" "${{ github.workspace }}/BuildRoot/${{ env.PACKAGE_NAME }}/pkgconfig/llvm.pc"' | |
| working-directory: ${{ github.workspace }}/BuildRoot/${{ env.PACKAGE_NAME }}/bin # makes llvm-config available | |
| - 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 | |
| with: | |
| files: ${{ env.PACKAGE_NAME }}${{ matrix.package_suffix }} | |
| tag_name: ${{ needs.create_tag.outputs.tag_name }} | |
| - name: Clear old sccache | |
| shell: bash | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| gh extension install actions/gh-actions-cache | |
| gh actions-cache delete sccache-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.configuration }}-package- --confirm -R ${{ github.repository }} | |
| continue-on-error: true |