-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: build and cache LLVM from source
Generalizes the build process for any LLVM version and any set of configuration options. To make it faster, the set of targets is reduced to only what we need for MrDocs. When we change the LLVM parameters, the first run will take slightly longer in CI and subsequent runs will reuse the cached binaries. This means we no longer need to host the binaries on mrdocs.com and update them manually, making the process of updating the LLVM version much simpler and cheaper since github will be hosting the binaries. It also allows us to explore other static ways to build LLVM in CI, which is required to create executables that are not associated with a specific ubuntu version. fix #548
- Loading branch information
1 parent
b615e97
commit 03b55df
Showing
3 changed files
with
112 additions
and
184 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,6 @@ jobs: | |
outputs: | ||
matrix: ${{ steps.cpp-matrix.outputs.matrix }} | ||
steps: | ||
- name: Clone cpp-actions | ||
uses: actions/checkout@v3 | ||
|
||
- name: Generate Test Matrix | ||
uses: alandefreitas/cpp-actions/[email protected] | ||
id: cpp-matrix | ||
|
@@ -59,15 +56,90 @@ jobs: | |
contents: write | ||
|
||
steps: | ||
- name: Install git | ||
- name: Install Essential Packages | ||
if: ${{ matrix.container }} | ||
env: | ||
DEBIAN_FRONTEND: 'noninteractive' | ||
TZ: 'Etc/UTC' | ||
uses: alandefreitas/cpp-actions/[email protected] | ||
with: | ||
apt-get: git | ||
apt-get: git build-essential python3 | ||
|
||
- name: Clone MrDocs | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup CMake | ||
uses: alandefreitas/cpp-actions/[email protected] | ||
id: setup-cmake | ||
with: | ||
# Clang requires clang-scan-deps to work on the latest CMake versions | ||
version: ${{ matrix.compiler == 'clang' && '3.26' || '>=3.26' }} | ||
check-latest: 'true' | ||
update-environment: 'true' | ||
|
||
- name: Setup Ninja | ||
uses: seanmiddleditch/gha-setup-ninja@v4 | ||
if: ${{ runner.os == 'Windows' }} | ||
|
||
- name: LLVM Parameters | ||
id: llvm-parameters | ||
run: | | ||
echo -E "llvm-hash=29b20829cc6ce3e6d9c3809164994c1659e0da56" >> $GITHUB_OUTPUT | ||
echo -E "llvm-build-preset=${{ runner.os == 'Windows' && 'release-win' || 'release-unix' }}" >> $GITHUB_OUTPUT | ||
cd .. | ||
llvm_root=$(pwd)/third-party/llvm-project/install | ||
if [[ ${{ runner.os }} == 'Windows' ]]; then | ||
llvm_root=$(echo "$llvm_root" | sed 's/\\/\//g') | ||
llvm_root=$(echo $llvm_root | sed 's|^/d/|D:/|') | ||
echo "$llvm_root" | ||
fi | ||
echo -E "llvm-root=$llvm_root" >> $GITHUB_OUTPUT | ||
- name: LLVM Binaries | ||
id: llvm-cache | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.llvm-parameters.outputs.llvm-root }} | ||
key: llvm-${{ runner.os }}-${{ steps.llvm-parameters.outputs.llvm-build-preset }}-${{ steps.llvm-parameters.outputs.llvm-hash }} | ||
|
||
- name: Install LLVM | ||
id: llvm-install | ||
if: steps.llvm-cache.outputs.cache-hit != 'true' | ||
shell: bash | ||
run: | | ||
# LLVM is be installed with the default compiler | ||
set -x | ||
# Shallow clone LLVM_HASH in ../third-party/llvm | ||
cd .. | ||
mkdir -p third-party/llvm-project | ||
cd third-party/llvm-project | ||
llvm_project_root=$(pwd) | ||
git config --global init.defaultBranch master | ||
git config --global advice.detachedHead false | ||
git init | ||
git remote add origin https://github.com/llvm/llvm-project.git | ||
git fetch --depth 1 origin ${{ steps.llvm-parameters.outputs.llvm-hash }} | ||
git checkout FETCH_HEAD | ||
# Copy presets | ||
cp ../../mrdocs/third-party/llvm/CMakePresets.json ./llvm | ||
cp ../../mrdocs/third-party/llvm/CMakeUserPresets.json.example ./llvm/CMakeUserPresets.json | ||
# Build | ||
cd llvm | ||
llvm_root=$(pwd) | ||
cmake --version | ||
cmake -S . -B ./build --preset=${{ steps.llvm-parameters.outputs.llvm-build-preset }} | ||
if [[ ${{ runner.os }} == 'Linux' ]]; then | ||
cmake --build ./build --target help | ||
fi | ||
N_CORES=$(nproc 2>/dev/null || echo 1) | ||
cmake --build ./build --config Release --parallel $N_CORES | ||
cmake --install ./build --prefix "$llvm_project_root"/install | ||
# Setup C++ after installing LLVM to use the default compiler | ||
# for LLVM and the specified compiler for MrDocs | ||
- name: Setup C++ | ||
uses: alandefreitas/cpp-actions/[email protected] | ||
id: setup-cpp | ||
|
@@ -87,45 +159,6 @@ jobs: | |
cxx: ${{ steps.setup-cpp.outputs.cxx || matrix.cxx }} | ||
cxxflags: ${{ matrix.cxxflags }} | ||
|
||
- name: Install LLVM | ||
id: llvm-install | ||
shell: bash | ||
run: | | ||
set -xe | ||
config_type="Release" | ||
filename="${{ runner.os }}-$config_type-29b20829.${{ ( runner.os == 'Windows' && '7z' ) || 'tar.xz' }}" | ||
url="https://mrdox.com/llvm+clang/$filename" | ||
# Download | ||
if command -v curl &> /dev/null | ||
then | ||
curl -L -o "$filename" "$url" | ||
elif command -v wget &> /dev/null | ||
then | ||
wget -O "$filename" "$url" | ||
else | ||
echo "Neither curl nor wget are available" | ||
exit 1 | ||
fi | ||
# Extract | ||
llvm_root="${{runner.tool_cache}}/llvm+clang" | ||
llvm_root=$(echo "$llvm_root" | sed 's/\\/\//g') | ||
mkdir -p "$llvm_root" | ||
if [ "${{ runner.os }}" != "Windows" ]; then | ||
tar -xvf "$filename" -C "$llvm_root" --strip-components=1 | ||
else | ||
7z x "$filename" | ||
cd "$config_type" | ||
mv * "$llvm_root" | ||
cd .. | ||
rm -rf "$config_type" | ||
fi | ||
# Export | ||
echo "llvm_root=$llvm_root" | ||
echo -E "llvm-root=$llvm_root" >> $GITHUB_OUTPUT | ||
- name: Install Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
|
@@ -137,16 +170,16 @@ jobs: | |
cmake-version: '>=3.20' | ||
cxxstd: ${{ matrix.cxxstd }} | ||
cc: ${{ steps.setup-cpp.outputs.cc || matrix.cc }} | ||
ccflags: ${{ matrix.ccflags }} | ||
ccflags: ${{ matrix.ccflags }}${{ ( matrix.compiler == 'gcc' && ' -static-libstdc++') || '' }}${{ ( matrix.asan && ' -static-libasan') || '' }}${{ ( matrix.tsan && ' -static-libtsan') || '' }} | ||
cxx: ${{ steps.setup-cpp.outputs.cxx || matrix.cxx }} | ||
cxxflags: ${{ matrix.cxxflags }}${{ ( matrix.compiler == 'gcc' && ' -static-libstdc++') || '' }}${{ ( matrix.asan && ' -static-libasan') || '' }}${{ ( matrix.tsan && ' -static-libtsan') || '' }} | ||
generator: Ninja | ||
toolchain: ${{ steps.package-install.outputs.vcpkg_toolchain || steps.package-install.outputs.vcpkg-toolchain }} | ||
build-type: ${{ matrix.build-type }} | ||
install-prefix: .local | ||
extra-args: | | ||
-D LLVM_ROOT="${{ steps.llvm-install.outputs.llvm-root || '/usr/local' }}" | ||
-D Clang_ROOT="${{ steps.llvm-install.outputs.llvm-root || '/usr/local' }}" | ||
-D LLVM_ROOT="${{ steps.llvm-parameters.outputs.llvm-root || '../third-party/llvm-project/install' }}" | ||
-D Clang_ROOT="${{ steps.llvm-parameters.outputs.llvm-root || '../third-party/llvm-project/install' }}" | ||
export-compile-commands: true | ||
run-tests: true | ||
install: true | ||
|
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
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