Skip to content

Commit 0f772dd

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 97aca54 commit 0f772dd

File tree

7 files changed

+655
-0
lines changed

7 files changed

+655
-0
lines changed

.cirrus.yml

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

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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 -cJf artifacts/$artifactName.tar.xz --options='compression-level=9' $artifactName
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 + mlir
80+
mv compiler-rt llvm/projects
81+
mv bolt lld mlir 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@v3
91+
with:
92+
name: ${{ env.ARTIFACT_NAME }}
93+
path: artifacts/

0 commit comments

Comments
 (0)