Skip to content

Commit 77babf8

Browse files
committed
[LDC] Set up CI / package generation with GitHub Actions and Cirrus CI
GH Actions: Windows x86 & x64, macOS x64 & ARM64, Linux x64, Android ARMv7-A & AArch64 Cirrus CI: Linux AArch64 2 packages per platform (enabled/disabled assertions), except for cross- compiled Android. Tagged builds are uploaded to the corresponding GitHub release, untagged builds to the GitHub 'CI' release.
1 parent e88b789 commit 77babf8

File tree

7 files changed

+644
-0
lines changed

7 files changed

+644
-0
lines changed

.cirrus.yml

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
environment:
2+
CIRRUS_CLONE_DEPTH: 50
3+
CLANG_VERSION: '15.0.3' # 15.0.6 requires a more recent libstdc++.so.6 than shipped with Ubuntu 20
4+
LLVM_PROJECTS_TO_ENABLE: compiler-rt;lld;bolt
5+
# keep these in sync with .github/workflows/ldc-release.yml for Linux x64:
6+
LLVM_TARGETS_TO_BUILD: all
7+
LLVM_EXPERIMENTAL_TARGETS_TO_BUILD: SPIRV
8+
BASE_CMAKE_FLAGS: -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_LIBEDIT=OFF -DLLVM_USE_STATIC_ZSTD=TRUE -DCOMPILER_RT_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_TESTS=OFF -DCOMPILER_RT_USE_LIBCXX=OFF
9+
EXTRA_CMAKE_FLAGS: -DLLVM_BINUTILS_INCDIR=/usr/include -DLLVM_STATIC_LINK_CXX_STDLIB=ON
10+
11+
task:
12+
name: Ubuntu 20.04 $TASK_NAME_SUFFIX
13+
compute_engine_instance:
14+
image_project: ubuntu-os-cloud
15+
image: family/ubuntu-2004-lts-arm64
16+
platform: linux
17+
architecture: arm64
18+
cpu: 4
19+
memory: 8G
20+
disk: 20
21+
timeout_in: 120m
22+
environment:
23+
PARALLELISM: 4
24+
GITHUB_TOKEN: ENCRYPTED[79b00f4f535df0fdfe3ceea87f9d4ec2ba7628e0c60730b99bcd91c7888af275409f02b2f1bc90015c2cb9cc4fb2dd12]
25+
matrix:
26+
- TASK_NAME_SUFFIX: aarch64
27+
LLVM_ENABLE_ASSERTIONS: 'OFF'
28+
- TASK_NAME_SUFFIX: aarch64 withAsserts
29+
LLVM_ENABLE_ASSERTIONS: 'ON'
30+
install_prerequisites_script: |
31+
export DEBIAN_FRONTEND=noninteractive
32+
apt-get -q update
33+
apt-get -yq install git-core curl xz-utils ninja-build g++ python3 pkg-config binutils-dev libxml2-dev libzstd-dev zlib1g-dev p7zip-full
34+
# install a more recent version of CMake
35+
curl -fL --retry 3 --max-time 300 -o cmake.tar.gz https://github.com/Kitware/CMake/releases/download/v3.28.4/cmake-3.28.4-linux-aarch64.tar.gz
36+
mkdir cmake_bin
37+
tar -xf cmake.tar.gz --strip 1 -C cmake_bin
38+
rm cmake.tar.gz
39+
# download & extract clang
40+
curl -fL --retry 3 --max-time 300 -o clang.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-$CLANG_VERSION/clang+llvm-$CLANG_VERSION-aarch64-linux-gnu.tar.xz
41+
mkdir clang_bin
42+
tar -xf clang.tar.xz --strip 1 -C clang_bin
43+
rm clang.tar.xz
44+
# make lld the default linker
45+
ln -sf "$PWD/clang_bin/bin/ld.lld" /usr/bin/ld
46+
ld --version
47+
clone_submodules_script: |
48+
git submodule update --init --depth $CIRRUS_CLONE_DEPTH
49+
build_script: |
50+
export PATH="$PWD/cmake_bin/bin:$PATH"
51+
export CC="$PWD/clang_bin/bin/clang"
52+
export CXX="$PWD/clang_bin/bin/clang++"
53+
nproc
54+
free
55+
cmake --version
56+
ninja --version
57+
mkdir build
58+
cd build
59+
cmake -G Ninja ../llvm \
60+
-DCMAKE_BUILD_TYPE=Release \
61+
-DCMAKE_INSTALL_PREFIX=$PWD/../install \
62+
-DLLVM_ENABLE_PROJECTS="$LLVM_PROJECTS_TO_ENABLE" \
63+
-DLLVM_TARGETS_TO_BUILD="$LLVM_TARGETS_TO_BUILD" \
64+
-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="$LLVM_EXPERIMENTAL_TARGETS_TO_BUILD" \
65+
-DLLVM_ENABLE_ASSERTIONS=$LLVM_ENABLE_ASSERTIONS \
66+
$BASE_CMAKE_FLAGS $EXTRA_CMAKE_FLAGS
67+
ninja -j$PARALLELISM install
68+
cd ..
69+
pack_artifact_script: |
70+
if [[ "${CIRRUS_TAG:-}" == ldc-v* ]]; then
71+
artifactID=${CIRRUS_TAG:5}
72+
else
73+
artifactID=${CIRRUS_CHANGE_IN_REPO:0:8}
74+
fi
75+
assertsSuffix=""
76+
if [[ "$LLVM_ENABLE_ASSERTIONS" == "ON" ]]; then
77+
assertsSuffix="-withAsserts"
78+
fi
79+
artifactName=llvm-$artifactID-linux-aarch64$assertsSuffix
80+
mv install $artifactName
81+
chmod -R go=rX $artifactName
82+
artifact=$artifactName.tar.xz
83+
tar -cf - --owner=0 --group=0 $artifactName | 7za a $artifact -si -txz -mx9 -mmt$PARALLELISM
84+
ls -lh $artifact
85+
# Upload to GitHub release (only for branches and tags, no PRs)
86+
upload_to_github_script: |
87+
if [[ "${CIRRUS_TAG:-}" == ldc-v* ]]; then
88+
releaseTag=$CIRRUS_TAG
89+
elif [[ "${CIRRUS_TAG:-}" == "" && "${CIRRUS_PR:-}" == "" ]]; then
90+
releaseTag=CI
91+
else
92+
echo 'Skipping upload'
93+
exit 0
94+
fi
95+
releaseID="$(set -eo pipefail; curl -fsS https://api.github.com/repos/ldc-developers/llvm-project/releases/tags/"$releaseTag" | grep '^ "id":' | head -n1 || echo "<error>")"
96+
if [[ "$releaseID" == "<error>" ]]; then
97+
echo "Error: no GitHub release found for tag '$releaseTag'" >&2
98+
exit 1
99+
fi
100+
releaseID=${releaseID:8:-1}
101+
artifact=$(ls llvm-*.tar.xz)
102+
echo "Uploading $artifact to GitHub release $releaseTag ($releaseID)..."
103+
curl -fsS \
104+
-H "Authorization: token $GITHUB_TOKEN" \
105+
-H "Content-Type: application/octet-stream" \
106+
--data-binary @$artifact \
107+
https://uploads.github.com/repos/ldc-developers/llvm-project/releases/$releaseID/assets?name=$artifact

.github/actions/1-setup/action.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Install prerequisites
2+
inputs:
3+
clang_version:
4+
required: true
5+
arch:
6+
required: true
7+
runs:
8+
using: composite
9+
steps:
10+
11+
- name: 'Linux: Install required apt packages'
12+
if: runner.os == 'Linux'
13+
shell: bash
14+
run: |
15+
set -eux
16+
export DEBIAN_FRONTEND=noninteractive
17+
sudo apt-get -q update
18+
sudo apt-get -yq install \
19+
git-core cmake g++ binutils-dev libzstd-dev python p7zip-full unzip
20+
21+
- name: 'Linux: Download & extract clang' # into ../clang
22+
if: runner.os == 'Linux'
23+
shell: bash
24+
run: |
25+
set -eux
26+
cd ..
27+
version='${{ inputs.clang_version }}'
28+
curl -fL --retry 3 --max-time 300 -o clang.tar.xz \
29+
https://github.com/llvm/llvm-project/releases/download/llvmorg-$version/clang+llvm-$version-x86_64-linux-gnu-ubuntu-18.04.tar.xz
30+
mkdir clang
31+
tar -xf clang.tar.xz --strip 1 -C clang
32+
rm clang.tar.xz
33+
clang/bin/clang --version
34+
35+
# use it as C(++) compiler for future steps
36+
echo "CC=$PWD/clang/bin/clang" >> $GITHUB_ENV
37+
echo "CXX=$PWD/clang/bin/clang++" >> $GITHUB_ENV
38+
39+
# make bundled lld the default linker
40+
sudo ln -sf "$PWD/clang/bin/ld.lld" /usr/bin/ld
41+
ld --version
42+
- name: 'Windows: Install clang'
43+
if: runner.os == 'Windows'
44+
shell: bash
45+
run: |
46+
set -eux
47+
cd ..
48+
curl -fL --retry 3 --max-time 300 -o clang.exe \
49+
https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ inputs.clang_version }}/LLVM-${{ inputs.clang_version }}-win64.exe
50+
./clang.exe //S # double-slash for bash
51+
rm clang.exe
52+
53+
# C:\Program Files\LLVM\bin should already be in PATH
54+
clang-cl --version
55+
56+
# use it as C(++) compiler for future steps
57+
echo "CC=clang-cl" >> $GITHUB_ENV
58+
echo "CXX=clang-cl" >> $GITHUB_ENV
59+
60+
if [[ '${{ inputs.arch }}' == x86 ]]; then
61+
# make CMake configure 64-bit clang-cl for 32-bit code emission
62+
echo "CFLAGS=-m32" >> $GITHUB_ENV
63+
echo "CXXFLAGS=-m32" >> $GITHUB_ENV
64+
echo "ASMFLAGS=-m32" >> $GITHUB_ENV
65+
fi
66+
67+
- name: Install ninja
68+
uses: seanmiddleditch/gha-setup-ninja@v4
69+
70+
- name: 'Windows: Set LDC_VSDIR env variable'
71+
if: runner.os == 'Windows'
72+
shell: bash
73+
run: echo "LDC_VSDIR=$(vswhere -latest -property installationPath)" >> $GITHUB_ENV

.github/actions/2-build/action.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Build & install LLVM incl. LLD, compiler-rt, BOLT
2+
inputs:
3+
arch:
4+
required: false # Windows only
5+
enable_projects:
6+
required: true
7+
targets_to_build:
8+
required: false
9+
default: all
10+
experimental_targets_to_build:
11+
required: false
12+
default: ''
13+
with_asserts:
14+
required: true
15+
extra_cmake_flags:
16+
required: false
17+
default: ''
18+
runs:
19+
using: composite
20+
steps:
21+
22+
- if: runner.os != 'Windows'
23+
shell: bash
24+
run: |
25+
set -eux
26+
cd ..
27+
cmake --version
28+
ninja --version
29+
mkdir build
30+
cd build
31+
cmake -G Ninja ../llvm-project/llvm \
32+
-DCMAKE_BUILD_TYPE=Release \
33+
-DCMAKE_INSTALL_PREFIX=$PWD/../install \
34+
-DLLVM_ENABLE_PROJECTS="${{ inputs.enable_projects }}" \
35+
-DLLVM_TARGETS_TO_BUILD="${{ inputs.targets_to_build }}" \
36+
-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="${{ inputs.experimental_targets_to_build }}" \
37+
-DLLVM_ENABLE_ASSERTIONS=${{ inputs.with_asserts == 'true' && 'ON' || 'OFF' }} \
38+
${{ inputs.extra_cmake_flags }}
39+
ninja install
40+
41+
# Windows: invoke CMake & ninja in MSVC env
42+
- if: runner.os == 'Windows'
43+
shell: cmd
44+
run: |
45+
call "%LDC_VSDIR%\Common7\Tools\VsDevCmd.bat" -arch=${{ inputs.arch }} || exit /b
46+
echo on
47+
cd .. || exit /b
48+
cmake --version || exit /b
49+
ninja --version || exit /b
50+
mkdir build || exit /b
51+
cd build || exit /b
52+
cmake -G Ninja ..\llvm-project\llvm ^
53+
-DCMAKE_BUILD_TYPE=Release ^
54+
"-DCMAKE_INSTALL_PREFIX=%CD%\..\install" ^
55+
"-DLLVM_ENABLE_PROJECTS=${{ inputs.enable_projects }}" ^
56+
"-DLLVM_TARGETS_TO_BUILD=${{ inputs.targets_to_build }}" ^
57+
"-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=${{ inputs.experimental_targets_to_build }}" ^
58+
-DLLVM_ENABLE_ASSERTIONS=${{ inputs.with_asserts == 'true' && 'ON' || 'OFF' }} ^
59+
${{ inputs.extra_cmake_flags }}
60+
if %errorlevel% neq 0 exit /b %errorlevel%
61+
62+
ninja install || exit /b

.github/actions/3-package/action.yml

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Create package & upload artifact(s)
2+
inputs:
3+
arch:
4+
required: true
5+
os:
6+
required: false
7+
default: '' # native
8+
with_asserts:
9+
required: true
10+
runs:
11+
using: composite
12+
steps:
13+
14+
- name: Pack installation dir
15+
shell: bash
16+
run: |
17+
set -euxo pipefail
18+
cd ..
19+
mkdir artifacts
20+
21+
if [[ '${{ github.ref }}' = refs/tags/ldc-v* ]]; then
22+
artifactID='${{ github.ref }}'
23+
artifactID="${artifactID:15}"
24+
else
25+
artifactID='${{ github.sha }}'
26+
artifactID="${artifactID:0:8}"
27+
fi
28+
29+
os='${{ inputs.os }}'
30+
if [[ "$os" == '' ]]; then
31+
if [[ '${{ runner.os }}' == Linux ]]; then
32+
os=linux
33+
elif [[ '${{ runner.os }}' == macOS ]]; then
34+
os=osx
35+
elif [[ '${{ runner.os }}' == Windows ]]; then
36+
os=windows
37+
else
38+
echo "Error: unknown OS '${{ runner.os }}'"
39+
exit 1
40+
fi
41+
fi
42+
43+
if [[ "$os" == windows ]]; then
44+
# on Windows, the lld symlinks are copies
45+
rm install/bin/{ld.lld,ld64.lld*,lld-link,wasm-ld}.exe
46+
mv install/bin/lld.exe install/bin/lld-link.exe
47+
fi
48+
49+
assertsSuffix="${{ inputs.with_asserts == 'true' && '-withAsserts' || '' }}"
50+
51+
artifactName="llvm-$artifactID-$os-${{ inputs.arch }}$assertsSuffix"
52+
mv install $artifactName
53+
if [[ '${{ runner.os }}' == Windows ]]; then
54+
cd $artifactName
55+
7z a -mx=9 ../artifacts/$artifactName.7z * >/dev/null
56+
cd ..
57+
else
58+
chmod -R go=rX $artifactName
59+
if [[ '${{ runner.os }}' == macOS ]]; then
60+
sudo chown -R root:wheel $artifactName
61+
tar -cf - $artifactName | 7za a artifacts/$artifactName.tar.xz -si -txz -mx9
62+
else
63+
tar -cf - --owner=0 --group=0 $artifactName | 7za a artifacts/$artifactName.tar.xz -si -txz -mx9
64+
fi
65+
fi
66+
67+
# export ARTIFACT_{ID,NAME}
68+
echo "ARTIFACT_ID=$artifactID" >> $GITHUB_ENV
69+
echo "ARTIFACT_NAME=$os-${{ inputs.arch }}$assertsSuffix" >> $GITHUB_ENV
70+
71+
- name: 'Linux: Pack source dir'
72+
if: runner.os == 'Linux' && inputs.os == '' && inputs.with_asserts == 'false'
73+
shell: bash
74+
run: |
75+
set -euxo pipefail
76+
git clean -dffx
77+
git submodule foreach git clean -dffx
78+
artifactName="llvm-$ARTIFACT_ID.src"
79+
# just the LLVM src dir + bolt + compiler-rt + lld
80+
mv compiler-rt llvm/projects
81+
mv bolt lld llvm/tools
82+
chmod -R go=rX llvm
83+
tar -cf - --exclude-vcs --owner=0 --group=0 --transform="s,^llvm,$artifactName," llvm | 7za a ../artifacts/$artifactName.tar.xz -si -txz -mx9
84+
85+
- name: 'Move artifacts dir for uploading'
86+
shell: bash
87+
run: mv ../artifacts ./
88+
89+
- name: Upload artifact(s)
90+
uses: actions/upload-artifact@v4
91+
with:
92+
name: ${{ env.ARTIFACT_NAME }}
93+
path: artifacts/
94+
compression-level: 0

0 commit comments

Comments
 (0)