Skip to content

Commit 3093657

Browse files
committed
[workflows] Port buildkite Windows config to GitHub actions
This reuses most of the generate-buildkite-pipeline-premerge script which determines which projects to build and which check targets to use. This new workflow only tests clang, llvm, and lld due to resource contraints on the GitHub runners.
1 parent 2de269a commit 3093657

File tree

3 files changed

+302
-0
lines changed

3 files changed

+302
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: 'Compute Projects To Test'
2+
inputs:
3+
projects:
4+
required: false
5+
type: 'string'
6+
7+
outputs:
8+
check-targets:
9+
description: "A space delimited list of check-targets to pass to ninja."
10+
value: ${{ steps.compute-projects.outputs.check-targets }}
11+
12+
projects:
13+
description: "A semi-colon delimited list of projects to pass to -DLLVM_ENABLE_PROJECTS."
14+
value: ${{ steps.compute-projects.outputs.projects }}
15+
16+
runs:
17+
using: "composite"
18+
steps:
19+
- id: compute-projects
20+
run: .github/workflows/compute-projects-to-test/compute-projects-to-test.sh ${{ inputs.projects }}
21+
shell: bash
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
#!/usr/bin/env bash
2+
#===----------------------------------------------------------------------===##
3+
#
4+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
# See https://llvm.org/LICENSE.txt for license information.
6+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
#
8+
#===----------------------------------------------------------------------===##
9+
10+
#
11+
# This file generates a Buildkite pipeline that triggers the various CI jobs for
12+
# the LLVM project during pre-commit CI.
13+
#
14+
# See https://buildkite.com/docs/agent/v3/cli-pipeline#pipeline-format.
15+
#
16+
# As this outputs a yaml file, it's possible to log messages to stderr or
17+
# prefix with "#".
18+
19+
20+
set -eu
21+
set -o pipefail
22+
23+
# Environment variables script works with:
24+
25+
# Set by GitHub
26+
: ${GITHUB_OUTPUT:=}
27+
: ${RUNNER_OS:=}
28+
29+
# Allow users to specify which projects to build.
30+
all_projects="bolt clang clang-tools-extra compiler-rt cross-project-tests flang libc libclc lld lldb llvm mlir openmp polly pstl"
31+
if [ "$#" -ne 0 ]; then
32+
wanted_projects="${@}"
33+
else
34+
wanted_projects="${all_projects}"
35+
fi
36+
37+
# List of files affected by this commit
38+
: ${MODIFIED_FILES:=$(git diff --name-only HEAD~1...HEAD)}
39+
40+
echo "Files modified:" >&2
41+
echo "$MODIFIED_FILES" >&2
42+
modified_dirs=$(echo "$MODIFIED_FILES" | cut -d'/' -f1 | sort -u)
43+
echo "Directories modified:" >&2
44+
echo "$modified_dirs" >&2
45+
echo "wanted_projects: $wanted_projects"
46+
47+
function remove-unwanted-projects() {
48+
projects=${@}
49+
for project in ${projects}; do
50+
if echo "$wanted_projects" | tr ' ' '\n' | grep -q -E "^${project}$"; then
51+
echo "${project}"
52+
fi
53+
done
54+
}
55+
56+
function compute-projects-to-test() {
57+
projects=${@}
58+
for project in ${projects}; do
59+
echo "${project}"
60+
case ${project} in
61+
lld)
62+
for p in bolt cross-project-tests; do
63+
echo $p
64+
done
65+
;;
66+
llvm)
67+
for p in bolt clang clang-tools-extra flang lld lldb mlir polly; do
68+
echo $p
69+
done
70+
;;
71+
clang)
72+
for p in clang-tools-extra compiler-rt flang libc lldb openmp cross-project-tests; do
73+
echo $p
74+
done
75+
;;
76+
clang-tools-extra)
77+
echo libc
78+
;;
79+
mlir)
80+
echo flang
81+
;;
82+
*)
83+
# Nothing to do
84+
;;
85+
esac
86+
done
87+
}
88+
89+
function add-dependencies() {
90+
projects=${@}
91+
for project in ${projects}; do
92+
echo "${project}"
93+
case ${project} in
94+
bolt)
95+
for p in lld llvm; do
96+
echo $p
97+
done
98+
;;
99+
cross-project-tests)
100+
for p in lld clang; do
101+
echo $p
102+
done
103+
;;
104+
clang-tools-extra)
105+
for p in llvm clang; do
106+
echo $p
107+
done
108+
;;
109+
compiler-rt|libc|openmp)
110+
echo clang lld
111+
;;
112+
flang|lldb)
113+
for p in llvm clang; do
114+
echo $p
115+
done
116+
;;
117+
lld|mlir|polly)
118+
echo llvm
119+
;;
120+
*)
121+
# Nothing to do
122+
;;
123+
esac
124+
done
125+
}
126+
127+
function exclude-linux() {
128+
projects=${@}
129+
for project in ${projects}; do
130+
case ${project} in
131+
cross-project-tests) ;; # tests failing
132+
lldb) ;; # tests failing
133+
openmp) ;; # https://github.com/google/llvm-premerge-checks/issues/410
134+
*)
135+
echo "${project}"
136+
;;
137+
esac
138+
done
139+
}
140+
141+
function exclude-windows() {
142+
projects=${@}
143+
for project in ${projects}; do
144+
case ${project} in
145+
cross-project-tests) ;; # tests failing
146+
compiler-rt) ;; # tests taking too long
147+
openmp) ;; # TODO: having trouble with the Perl installation
148+
libc) ;; # no Windows support
149+
lldb) ;; # tests failing
150+
bolt) ;; # tests are not supported yet
151+
*)
152+
echo "${project}"
153+
;;
154+
esac
155+
done
156+
}
157+
158+
# Prints only projects that are both present in $modified_dirs and the passed
159+
# list.
160+
function keep-modified-projects() {
161+
projects=${@}
162+
for project in ${projects}; do
163+
if echo "$modified_dirs" | grep -q -E "^${project}$"; then
164+
echo "${project}"
165+
fi
166+
done
167+
}
168+
169+
function check-targets() {
170+
projects=${@}
171+
for project in ${projects}; do
172+
case ${project} in
173+
clang-tools-extra)
174+
echo "check-clang-tools"
175+
;;
176+
compiler-rt)
177+
echo "check-all"
178+
;;
179+
cross-project-tests)
180+
echo "check-cross-project"
181+
;;
182+
lldb)
183+
echo "check-all" # TODO: check-lldb may not include all the LLDB tests?
184+
;;
185+
pstl)
186+
echo "check-all"
187+
;;
188+
libclc)
189+
echo "check-all"
190+
;;
191+
*)
192+
echo "check-${project}"
193+
;;
194+
esac
195+
done
196+
}
197+
198+
# Generic pipeline for projects that have not defined custom steps.
199+
#
200+
# Individual projects should instead define the pre-commit CI tests that suits their
201+
# needs while letting them run on the infrastructure provided by LLVM.
202+
203+
# Figure out which projects need to be built on each platform
204+
modified_projects="$(keep-modified-projects ${all_projects})"
205+
echo "modified_projects: $modified_projects"
206+
207+
if [ "${RUNNER_OS}" = "Linux" ]; then
208+
projects_to_test=$(exclude-linux $(compute-projects-to-test ${modified_projects}))
209+
elif [ "${RUNNER_OS}" = "Windows" ]; then
210+
projects_to_test=$(exclude-windows $(compute-projects-to-test ${modified_projects}))
211+
else
212+
echo "Unknown runner OS: $RUNNER_OS"
213+
fi
214+
check_targets=$(check-targets $(remove-unwanted-projects ${projects_to_test}) | sort | uniq)
215+
projects=$(remove-unwanted-projects $(add-dependencies ${projects_to_test}) | sort | uniq)
216+
217+
echo "check-targets=$(echo ${check_targets} | tr ' ' ' ')" >> $GITHUB_OUTPUT
218+
echo "projects=$(echo ${projects} | tr ' ' ';')" >> $GITHUB_OUTPUT
219+
220+
cat $GITHUB_OUTPUT
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: "Windows Precommit Tests"
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
branches:
9+
- main
10+
11+
concurrency:
12+
# Skip intermediate builds: always.
13+
# Cancel intermediate builds: only if it is a pull request build.
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
16+
17+
jobs:
18+
build-llvm-windows:
19+
name: "Build and test LLVM (Windows)"
20+
runs-on: windows-2022
21+
steps:
22+
- name: Setup Windows
23+
uses: llvm/actions/setup-windows@main
24+
with:
25+
arch: amd64
26+
- name: Fetch LLVM sources
27+
uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 2
30+
- name: Setup ccache
31+
uses: hendrikmuhs/ccache-action@v1
32+
with:
33+
max-size: 500M
34+
variant: sccache
35+
key: precommit-windows
36+
- name: Compute projects to test
37+
id: compute-projects
38+
uses: ./.github/workflows/compute-projects-to-test
39+
with:
40+
projects: clang llvm lld
41+
42+
- name: Configure LLVM
43+
shell: bash
44+
if: ${{ steps.compute-projects.outputs.check-targets }}
45+
run: |
46+
cmake -B build -GNinja \
47+
-DCMAKE_BUILD_TYPE=Release \
48+
-DLLVM_ENABLE_PROJECTS="${{ steps.compute-projects.outputs.projects }}" \
49+
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
50+
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
51+
-DLLVM_ENABLE_ASSERTIONS=ON \
52+
-DLLVM_LIT_ARGS="-v --no-progress-bar" \
53+
-S llvm
54+
- name: Build LLVM
55+
if: ${{ steps.compute-projects.outputs.check-targets }}
56+
run: |
57+
ninja -C build test-depends
58+
- name: Check LLVM
59+
if: ${{ steps.compute-projects.outputs.check-targets }}
60+
run: |
61+
ninja -C build "${{ steps.compute-projects.outputs.check-targets }}"

0 commit comments

Comments
 (0)