Skip to content

Commit 0280a6a

Browse files
committed
ci: refactor toolchain setup
The 'toolchain' matrix parameter has been used in a confusing way. The 'version' field was only applicable to LLVM, but there is also a separate 'llvm-version' action parameter spread across the workflows. Now that we want to be able to specify a particular GCC version for kernel build, a refactoring is appropriate. Given that libbpf/ci/setup-build-env action sets up a particular compiler version systemwide, and mixing LLVM versions between kernel and selftests build is an unlikely scenario, it makes sense to simply have gcc_version and llvm_version parameter, fixed within a particular workflow. And so the composite 'toolchain' becomes unnecessary: it's enough to distinguish between gcc and llvm build of the kernel. However 'toolchain' and 'toolchain_full' are still useful variables between the workflows and actions, particularly for identifying build artifacts. Here is what happens now: * DEFAULT_{GCC,LLVM}_VERSION is set in matrix.py * 'toolchain' is replaced with 'kernel_compiler' in the job matrix * test.yml workflow looks at kernel_compiler to construct and pass 'toolchain' and 'toolchain_full' to other workflows * '{gcc,llvm}_version' inputs are used to determine compiler versions for the build setup Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
1 parent ac97755 commit 0280a6a

File tree

7 files changed

+58
-70
lines changed

7 files changed

+58
-70
lines changed

.github/scripts/matrix.py

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
DEFAULT_SELF_HOSTED_RUNNER_TAGS: Final[List[str]] = ["self-hosted", "docker-noble-main"]
1818
DEFAULT_GITHUB_HOSTED_RUNNER: Final[str] = "ubuntu-24.04"
19+
DEFAULT_GCC_VERSION: Final[int] = 13
1920
DEFAULT_LLVM_VERSION: Final[int] = 17
2021

2122
RUNNERS_BUSY_THRESHOLD: Final[float] = 0.8
@@ -36,31 +37,6 @@ class Compiler(str, Enum):
3637
LLVM = "llvm"
3738

3839

39-
@dataclasses.dataclass
40-
class Toolchain:
41-
compiler: Compiler
42-
# This is relevant ONLY for LLVM and should not be required for GCC
43-
version: int
44-
45-
@property
46-
def short_name(self) -> str:
47-
return str(self.compiler.value)
48-
49-
@property
50-
def full_name(self) -> str:
51-
if self.compiler == Compiler.GCC:
52-
return self.short_name
53-
54-
return f"{self.short_name}-{self.version}"
55-
56-
def to_dict(self) -> Dict[str, Union[str, int]]:
57-
return {
58-
"name": self.short_name,
59-
"fullname": self.full_name,
60-
"version": self.version,
61-
}
62-
63-
6440
def query_runners_from_github() -> List[Dict[str, Any]]:
6541
if "GITHUB_TOKEN" not in os.environ:
6642
return []
@@ -150,7 +126,9 @@ def count_by_status(runners: List[Dict[str, Any]]) -> Dict[str, int]:
150126
@dataclasses.dataclass
151127
class BuildConfig:
152128
arch: Arch
153-
toolchain: Toolchain
129+
kernel_compiler: Compiler = Compiler.GCC
130+
gcc_version: int = DEFAULT_GCC_VERSION
131+
llvm_version: int = DEFAULT_LLVM_VERSION
154132
kernel: str = "LATEST"
155133
run_veristat: bool = False
156134
parallel_tests: bool = False
@@ -205,7 +183,7 @@ def tests(self) -> Dict[str, Any]:
205183
if self.arch.value != "s390x":
206184
tests_list.append("test_maps")
207185

208-
if self.toolchain.version >= 18:
186+
if self.llvm_version >= 18:
209187
tests_list.append("test_progs_cpuv4")
210188

211189
# if self.arch in [Arch.X86_64, Arch.AARCH64]:
@@ -224,7 +202,9 @@ def tests(self) -> Dict[str, Any]:
224202
def to_dict(self) -> Dict[str, Any]:
225203
return {
226204
"arch": self.arch.value,
227-
"toolchain": self.toolchain.to_dict(),
205+
"kernel_compiler": self.kernel_compiler.value,
206+
"gcc_version": DEFAULT_GCC_VERSION,
207+
"llvm_version": DEFAULT_LLVM_VERSION,
228208
"kernel": self.kernel,
229209
"run_veristat": self.run_veristat,
230210
"parallel_tests": self.parallel_tests,
@@ -272,27 +252,19 @@ def generate_test_config(test: str) -> Dict[str, Union[str, int]]:
272252
matrix = [
273253
BuildConfig(
274254
arch=Arch.X86_64,
275-
toolchain=Toolchain(compiler=Compiler.GCC, version=DEFAULT_LLVM_VERSION),
276255
run_veristat=True,
277256
parallel_tests=True,
278257
),
279258
BuildConfig(
280259
arch=Arch.X86_64,
281-
toolchain=Toolchain(compiler=Compiler.LLVM, version=DEFAULT_LLVM_VERSION),
282-
build_release=True,
283-
),
284-
BuildConfig(
285-
arch=Arch.X86_64,
286-
toolchain=Toolchain(compiler=Compiler.LLVM, version=18),
260+
kernel_compiler=Compiler.LLVM,
287261
build_release=True,
288262
),
289263
BuildConfig(
290264
arch=Arch.AARCH64,
291-
toolchain=Toolchain(compiler=Compiler.GCC, version=DEFAULT_LLVM_VERSION),
292265
),
293266
BuildConfig(
294267
arch=Arch.S390X,
295-
toolchain=Toolchain(compiler=Compiler.GCC, version=DEFAULT_LLVM_VERSION),
296268
),
297269
]
298270

.github/workflows/gcc-bpf.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ on:
99
arch:
1010
required: true
1111
type: string
12-
llvm-version:
12+
gcc_version:
13+
required: true
14+
type: string
15+
llvm_version:
1316
required: true
1417
type: string
1518
toolchain:
@@ -75,10 +78,11 @@ jobs:
7578
run: zstd -d -T0 vmlinux-${{ inputs.arch }}-${{ inputs.toolchain_full }}.tar.zst --stdout | tar -xf -
7679

7780
- name: Setup build environment
78-
uses: libbpf/ci/setup-build-env@v3
81+
uses: theihor/libbpf-ci/setup-build-env@gcc-14
7982
with:
8083
arch: ${{ inputs.arch }}
81-
llvm-version: ${{ inputs.llvm-version }}
84+
gcc-version: ${{ inputs.gcc_version }}
85+
llvm-version: ${{ inputs.llvm_version }}
8286

8387
- name: Download GCC BPF compiler
8488
shell: bash
@@ -95,6 +99,5 @@ jobs:
9599
with:
96100
arch: ${{ inputs.arch }}
97101
kernel-root: ${{ env.REPO_ROOT }}
98-
llvm-version: ${{ inputs.llvm-version }}
102+
llvm-version: ${{ inputs.llvm_version }}
99103
toolchain: ${{ inputs.toolchain }}
100-

.github/workflows/kernel-build-test.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ on:
2323
required: true
2424
type: string
2525
description: The runners to run the builds on. This is a json string representing an array of labels.
26-
llvm-version:
26+
gcc_version:
2727
required: true
2828
type: string
29-
description: The version of LLVM used to build selftest.... for llvm toolchain, this should match the one from toolchain_full, for gcc it is an arbritrary version we decide to build selftests against.
29+
description: GCC version to install
30+
llvm_version:
31+
required: true
32+
type: string
33+
description: LLVM version to install
3034
kernel:
3135
required: true
3236
type: string
@@ -67,7 +71,8 @@ jobs:
6771
toolchain_full: ${{ inputs.toolchain_full }}
6872
toolchain: ${{ inputs.toolchain }}
6973
runs_on: ${{ inputs.build_runs_on }}
70-
llvm-version: ${{ inputs.llvm-version }}
74+
gcc_version: ${{ inputs.gcc_version }}
75+
llvm_version: ${{ inputs.llvm_version }}
7176
kernel: ${{ inputs.kernel }}
7277
download_sources: ${{ inputs.download_sources }}
7378

@@ -79,7 +84,8 @@ jobs:
7984
toolchain_full: ${{ inputs.toolchain_full }}
8085
toolchain: ${{ inputs.toolchain }}
8186
runs_on: ${{ inputs.build_runs_on }}
82-
llvm-version: ${{ inputs.llvm-version }}
87+
gcc_version: ${{ inputs.gcc_version }}
88+
llvm_version: ${{ inputs.llvm_version }}
8389
kernel: ${{ inputs.kernel }}
8490
download_sources: ${{ inputs.download_sources }}
8591
release: true
@@ -112,7 +118,7 @@ jobs:
112118
contents: read
113119
with:
114120
arch: ${{ inputs.arch }}
115-
toolchain: ${{ inputs.toolchain }}
121+
toolchain_full: ${{ inputs.toolchain_full }}
116122
runs_on: ${{ inputs.runs_on }}
117123

118124
veristat-meta:
@@ -125,7 +131,7 @@ jobs:
125131
contents: read
126132
with:
127133
arch: ${{ inputs.arch }}
128-
toolchain: ${{ inputs.toolchain }}
134+
toolchain_full: ${{ inputs.toolchain_full }}
129135
aws_region: ${{ vars.AWS_REGION }}
130136
runs_on: ${{ inputs.runs_on }}
131137
secrets:
@@ -140,7 +146,8 @@ jobs:
140146
# GCC BPF does not need /dev/kvm, so use the "build" runners
141147
runs_on: ${{ inputs.build_runs_on }}
142148
arch: ${{ inputs.arch }}
143-
llvm-version: ${{ inputs.llvm-version }}
149+
gcc_version: ${{ inputs.gcc_version }}
150+
llvm_version: ${{ inputs.llvm_version }}
144151
toolchain: ${{ inputs.toolchain }}
145152
toolchain_full: ${{ inputs.toolchain_full }}
146153
download_sources: ${{ inputs.download_sources }}

.github/workflows/kernel-build.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ on:
2020
required: true
2121
type: string
2222
description: The runners to run the test on. This is a json string representing an array of labels.
23-
llvm-version:
23+
gcc_version:
2424
required: true
2525
type: string
26-
description: The version of LLVM used to build selftest.... for llvm toolchain, this should match the one from toolchain_full, for gcc it is an arbritrary version we decide to build selftests against.
26+
description: GCC version to install
27+
llvm_version:
28+
required: true
29+
type: string
30+
description: LLVM version to install
2731
kernel:
2832
required: true
2933
type: string
@@ -41,7 +45,7 @@ on:
4145

4246
jobs:
4347
build:
44-
name: build for ${{ inputs.arch }} with ${{ inputs.toolchain_full }}${{ inputs.release && '-O2' || '' }}
48+
name: build kernel and selftests ${{ inputs.release && '-O2' || '' }}
4549
# To run on CodeBuild, runs-on value must correspond to the AWS
4650
# CodeBuild project associated with the kernel-patches webhook
4751
# However matrix.py passes just a 'codebuild' string
@@ -106,10 +110,11 @@ jobs:
106110
repo-root: ${{ env.REPO_ROOT }}
107111

108112
- name: Setup build environment
109-
uses: libbpf/ci/setup-build-env@v3
113+
uses: theihor/libbpf-ci/setup-build-env@gcc-14
110114
with:
111115
arch: ${{ inputs.arch }}
112-
llvm-version: ${{ inputs.llvm-version }}
116+
gcc-version: ${{ inputs.gcc_version }}
117+
llvm-version: ${{ inputs.llvm_version }}
113118
pahole: master
114119

115120
# We have to setup qemu+binfmt in order to enable cross-compation of selftests.
@@ -131,7 +136,7 @@ jobs:
131136
toolchain: ${{ inputs.toolchain }}
132137
kbuild-output: ${{ env.KBUILD_OUTPUT }}
133138
max-make-jobs: 32
134-
llvm-version: ${{ inputs.llvm-version }}
139+
llvm-version: ${{ inputs.llvm_version }}
135140

136141
- name: Build selftests/bpf
137142
uses: libbpf/ci/build-selftests@v3
@@ -141,7 +146,7 @@ jobs:
141146
with:
142147
arch: ${{ inputs.arch }}
143148
kernel-root: ${{ env.KERNEL_ROOT }}
144-
llvm-version: ${{ inputs.llvm-version }}
149+
llvm-version: ${{ inputs.llvm_version }}
145150
toolchain: ${{ inputs.toolchain }}
146151

147152
- if: ${{ env.BUILD_SCHED_EXT_SELFTESTS }}
@@ -152,7 +157,7 @@ jobs:
152157
repo-root: ${{ env.REPO_ROOT }}
153158
arch: ${{ inputs.arch }}
154159
toolchain: ${{ inputs.toolchain }}
155-
llvm-version: ${{ inputs.llvm-version }}
160+
llvm-version: ${{ inputs.llvm_version }}
156161
max-make-jobs: 32
157162

158163
- if: ${{ github.event_name != 'push' }}
@@ -163,7 +168,7 @@ jobs:
163168
toolchain: ${{ inputs.toolchain }}
164169
kbuild-output: ${{ env.KBUILD_OUTPUT }}
165170
max-make-jobs: 32
166-
llvm-version: ${{ inputs.llvm-version }}
171+
llvm-version: ${{ inputs.llvm_version }}
167172
- name: Tar artifacts
168173
id: tar-artifacts
169174
uses: libbpf/ci/tar-artifacts@v3

.github/workflows/test.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
build-and-test:
4545
# Setting name to arch-compiler here to avoid lengthy autogenerated names due to matrix
4646
# e.g build-and-test x86_64-gcc / test (test_progs_parallel, true, 30) / test_progs_parallel on x86_64 with gcc
47-
name: "${{ matrix.arch }}-${{ matrix.toolchain.fullname }}"
47+
name: ${{ matrix.arch }} ${{ matrix.kernel_compiler }}-${{ matrix.kernel_compiler == 'gcc' && matrix.gcc_version || matrix.llvm_version }}
4848
uses: ./.github/workflows/kernel-build-test.yml
4949
needs: [set-matrix]
5050
permissions:
@@ -55,11 +55,12 @@ jobs:
5555
matrix: ${{ fromJSON(needs.set-matrix.outputs.build-matrix) }}
5656
with:
5757
arch: ${{ matrix.arch }}
58-
toolchain_full: ${{ matrix.toolchain.fullname }}
59-
toolchain: ${{ matrix.toolchain.name }}
58+
toolchain: ${{ matrix.kernel_compiler }}
59+
toolchain_full: ${{ matrix.kernel_compiler }}-${{ matrix.kernel_compiler == 'gcc' && matrix.gcc_version || matrix.llvm_version }}
6060
runs_on: ${{ toJSON(matrix.runs_on) }}
6161
build_runs_on: ${{ toJSON(matrix.build_runs_on) }}
62-
llvm-version: ${{ matrix.toolchain.version }}
62+
gcc_version: ${{ matrix.gcc_version }}
63+
llvm_version: ${{ matrix.llvm_version }}
6364
kernel: ${{ matrix.kernel }}
6465
tests: ${{ toJSON(matrix.tests) }}
6566
run_veristat: ${{ matrix.run_veristat }}

.github/workflows/veristat-kernel.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ on:
77
required: true
88
type: string
99
description: The architecture to build against, e.g x86_64, aarch64, s390x...
10-
toolchain:
10+
toolchain_full:
1111
required: true
1212
type: string
13-
description: The toolchain, e.g gcc, llvm
13+
description: Toolchain identifier, such as llvm-20
1414
runs_on:
1515
required: true
1616
type: string
1717
description: The runners to run the test on. This is a json string representing an array of labels.
1818

1919
jobs:
2020
veristat:
21-
name: ${{ inputs.arch }}-${{ inputs.toolchain }} veristat_kernel
21+
name: veristat-kernel
2222
runs-on: ${{ fromJSON(inputs.runs_on) }}
2323
timeout-minutes: 100
2424
permissions:
@@ -29,7 +29,7 @@ jobs:
2929
REPO_ROOT: ${{ github.workspace }}
3030
REPO_PATH: ""
3131
KBUILD_OUTPUT: kbuild-output/
32-
ARCH_AND_TOOL: ${{ inputs.arch }}-${{ inputs.toolchain }}
32+
ARCH_AND_TOOL: ${{ inputs.arch }}-${{ inputs.toolchain_full }}
3333

3434
steps:
3535

.github/workflows/veristat-meta.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ on:
77
required: true
88
type: string
99
description: The architecture to build against, e.g x86_64, aarch64, s390x...
10-
toolchain:
10+
toolchain_full:
1111
required: true
1212
type: string
13-
description: The toolchain, e.g gcc, llvm
13+
description: Toolchain identifier, such as llvm-20
1414
runs_on:
1515
required: true
1616
type: string
@@ -26,7 +26,7 @@ on:
2626

2727
jobs:
2828
veristat:
29-
name: ${{ inputs.arch }}-${{ inputs.toolchain }} veristat_meta
29+
name: veristat-meta
3030
runs-on: ${{ fromJSON(inputs.runs_on) }}
3131
timeout-minutes: 100
3232
permissions:
@@ -37,7 +37,7 @@ jobs:
3737
REPO_ROOT: ${{ github.workspace }}
3838
REPO_PATH: ""
3939
KBUILD_OUTPUT: kbuild-output/
40-
ARCH_AND_TOOL: ${{ inputs.arch }}-${{ inputs.toolchain }}
40+
ARCH_AND_TOOL: ${{ inputs.arch }}-${{ inputs.toolchain_full }}
4141

4242
steps:
4343

0 commit comments

Comments
 (0)