-
Notifications
You must be signed in to change notification settings - Fork 0
324 lines (280 loc) · 12 KB
/
ci.yml
File metadata and controls
324 lines (280 loc) · 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
# ── Native build + test ───────────────────────────────────────
native:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake g++-13 ccache
- name: Restore ccache
uses: actions/cache@v4
with:
path: ~/.ccache
key: ccache-native-${{ runner.os }}-${{ github.sha }}
restore-keys: ccache-native-${{ runner.os }}-
- name: Configure (Debug)
run: cmake -B build -DCMAKE_CXX_COMPILER=g++-13 -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
env:
CCACHE_MAXSIZE: 256M
- name: Build
run: cmake --build build -j $(nproc)
- name: Unit tests
run: ctest --test-dir build --output-on-failure --verbose -j $(nproc)
- name: Integration tests
run: bash tests/integration/run_all.sh
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: native-test-results
path: build/Testing/
# ── Release build with size report ───────────────────────────
release-size:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake g++-13 ccache
- name: Restore ccache
uses: actions/cache@v4
with:
path: ~/.ccache
key: ccache-release-${{ runner.os }}-${{ github.sha }}
restore-keys: ccache-release-${{ runner.os }}-
- name: Configure (Release, -Os)
run: >
cmake -B build-release
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_CXX_COMPILER=g++-13
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-DCFBOX_OPTIMIZE_FOR_SIZE=ON
env:
CCACHE_MAXSIZE: 256M
- name: Build
run: cmake --build build-release -j $(nproc)
- name: Measure binary size
run: |
echo "=== -Os Release (dynamic) ==="
size build-release/cfbox
strip -o /tmp/cfbox-stripped build-release/cfbox
echo "Stripped size: $(wc -c < /tmp/cfbox-stripped) bytes"
- name: Upload release binary
uses: actions/upload-artifact@v4
with:
name: cfbox-x86_64-release
path: /tmp/cfbox-stripped
# ── Cross-compilation (aarch64 + armhf) ──────────────────────
cross-compile:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- target: aarch64
toolchain: Toolchain-aarch64.cmake
compiler_pkg: gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
strip: aarch64-linux-gnu-strip
- target: armhf
toolchain: Toolchain-armhf.cmake
compiler_pkg: ""
strip: arm-none-linux-gnueabihf-strip
steps:
- uses: actions/checkout@v4
- name: Install cross-compiler (aarch64)
if: matrix.target == 'aarch64'
run: |
sudo apt-get update
sudo apt-get install -y cmake ${{ matrix.compiler_pkg }} ccache
- name: Install cross-compiler (armhf)
if: matrix.target == 'armhf'
run: |
sudo apt-get update
sudo apt-get install -y ccache
curl -L -o /tmp/arm-toolchain.tar.xz \
https://developer.arm.com/-/media/Files/downloads/gnu/15.2.rel1/binrel/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz
sudo tar -xJf /tmp/arm-toolchain.tar.xz -C /opt
sudo ln -s /opt/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-linux-gnueabihf /opt/arm-gnu-toolchain
echo "/opt/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-linux-gnueabihf/bin" >> "$GITHUB_PATH"
- name: Restore ccache
uses: actions/cache@v4
with:
path: ~/.ccache
key: ccache-cross-${{ matrix.target }}-${{ github.sha }}
restore-keys: ccache-cross-${{ matrix.target }}-
- name: Cross-compile (dynamic, -Os)
run: |
cmake -B build-${{ matrix.target }} \
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/${{ matrix.toolchain }} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCFBOX_OPTIMIZE_FOR_SIZE=ON
cmake --build build-${{ matrix.target }} -j $(nproc)
- name: Verify target binary
run: |
file build-${{ matrix.target }}/cfbox
size build-${{ matrix.target }}/cfbox
${{ matrix.strip }} -o /tmp/cfbox-${{ matrix.target }}-stripped build-${{ matrix.target }}/cfbox
echo "Stripped size: $(wc -c < /tmp/cfbox-${{ matrix.target }}-stripped) bytes"
- name: Cross-compile (static)
run: |
cmake -B build-${{ matrix.target }}-static \
-DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/${{ matrix.toolchain }} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DCFBOX_OPTIMIZE_FOR_SIZE=ON \
-DCFBOX_STATIC_LINK=ON
cmake --build build-${{ matrix.target }}-static -j $(nproc)
- name: Verify static binary
run: |
file build-${{ matrix.target }}-static/cfbox
size build-${{ matrix.target }}-static/cfbox
- name: Upload static binary
uses: actions/upload-artifact@v4
with:
name: cfbox-${{ matrix.target }}-static
path: build-${{ matrix.target }}-static/cfbox
# ── QEMU user-mode emulation tests ──────────────────────────────
qemu-user-test:
needs: cross-compile
runs-on: ubuntu-latest
strategy:
matrix:
target: [aarch64, armhf]
steps:
- uses: actions/checkout@v4
- name: Install QEMU user-mode
run: sudo apt-get update && sudo apt-get install -y qemu-user-static
- name: Download static binary
uses: actions/download-artifact@v4
with:
name: cfbox-${{ matrix.target }}-static
path: build-${{ matrix.target }}-static
- name: Make binary executable
run: chmod +x build-${{ matrix.target }}-static/cfbox
- name: Smoke test
run: |
if [[ "${{ matrix.target }}" == "armhf" ]]; then
QEMU_BIN=qemu-arm-static
else
QEMU_BIN=qemu-${{ matrix.target }}-static
fi
$QEMU_BIN build-${{ matrix.target }}-static/cfbox --list
$QEMU_BIN build-${{ matrix.target }}-static/cfbox echo "Hello from ${{ matrix.target }}"
- name: Integration tests under QEMU
run: |
if [[ "${{ matrix.target }}" == "armhf" ]]; then
QEMU_BIN=qemu-arm-static
else
QEMU_BIN=qemu-${{ matrix.target }}-static
fi
# Create a wrapper script so test scripts work without modification
wrapper="$(mktemp /tmp/cfbox-qemu-wrapper-XXXXXX.sh)"
echo "#!/bin/sh" > "$wrapper"
echo "exec $QEMU_BIN $(pwd)/build-${{ matrix.target }}-static/cfbox \"\$@\"" >> "$wrapper"
chmod +x "$wrapper"
CFBOX="$wrapper" bash tests/integration/run_all.sh
# ── QEMU system-mode emulation tests ─────
qemu-system-test:
needs: cross-compile
runs-on: ubuntu-latest
strategy:
matrix:
target: [aarch64, armhf]
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y qemu-system-arm qemu-user-static cpio flex bison libelf-dev
- name: Install aarch64 cross-compiler
if: matrix.target == 'aarch64'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Install armhf cross-compiler
if: matrix.target == 'armhf'
run: |
curl -L -o /tmp/arm-toolchain.tar.xz \
https://developer.arm.com/-/media/Files/downloads/gnu/15.2.rel1/binrel/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz
sudo tar -xJf /tmp/arm-toolchain.tar.xz -C /opt
sudo ln -s /opt/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-linux-gnueabihf /opt/arm-gnu-toolchain
echo "/opt/arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-linux-gnueabihf/bin" >> "$GITHUB_PATH"
- name: Download static binary
uses: actions/download-artifact@v4
with:
name: cfbox-${{ matrix.target }}-static
path: build-${{ matrix.target }}-static
- name: Make binary executable
run: chmod +x build-${{ matrix.target }}-static/cfbox
- name: Determine kernel config
id: kernel
run: |
if [[ "${{ matrix.target }}" == "aarch64" ]]; then
echo "arch=arm64" >> "$GITHUB_OUTPUT"
echo "image=arch/arm64/boot/Image" >> "$GITHUB_OUTPUT"
echo "defconfig=allnoconfig" >> "$GITHUB_OUTPUT"
echo "cross=aarch64-linux-gnu-" >> "$GITHUB_OUTPUT"
echo "extra_config=configs/qemu-virt-aarch64.config" >> "$GITHUB_OUTPUT"
else
echo "arch=arm" >> "$GITHUB_OUTPUT"
echo "image=arch/arm/boot/zImage" >> "$GITHUB_OUTPUT"
echo "defconfig=vexpress_defconfig" >> "$GITHUB_OUTPUT"
echo "cross=arm-none-linux-gnueabihf-" >> "$GITHUB_OUTPUT"
echo "extra_config=" >> "$GITHUB_OUTPUT"
fi
- name: Restore Linux kernel cache
id: cache-kernel
uses: actions/cache/restore@v4
with:
path: |
third_party/linux/${{ steps.kernel.outputs.image }}
third_party/linux/.config
${{ matrix.target == 'armhf' && 'third_party/linux/arch/arm/boot/dts/arm/vexpress-v2p-ca9.dtb' || '' }}
key: linux-kernel-${{ matrix.target }}-${{ hashFiles('third_party/linux/Makefile') }}-${{ steps.kernel.outputs.defconfig }}
- name: Build Linux kernel
if: steps.cache-kernel.outputs.cache-hit != 'true'
run: |
cd third_party/linux
make ARCH=${{ steps.kernel.outputs.arch }} CROSS_COMPILE=${{ steps.kernel.outputs.cross }} ${{ steps.kernel.outputs.defconfig }}
if [[ -n "${{ steps.kernel.outputs.extra_config }}" ]]; then
while IFS='=' read -r key val; do
[[ -z "$key" || "$key" =~ ^# ]] && continue
./scripts/config --enable "$key"
done < "${{ github.workspace }}/${{ steps.kernel.outputs.extra_config }}"
make ARCH=${{ steps.kernel.outputs.arch }} CROSS_COMPILE=${{ steps.kernel.outputs.cross }} olddefconfig
fi
make ARCH=${{ steps.kernel.outputs.arch }} CROSS_COMPILE=${{ steps.kernel.outputs.cross }} -j$(nproc)
- name: Save Linux kernel cache
if: steps.cache-kernel.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: |
third_party/linux/${{ steps.kernel.outputs.image }}
third_party/linux/.config
${{ matrix.target == 'armhf' && 'third_party/linux/arch/arm/boot/dts/arm/vexpress-v2p-ca9.dtb' || '' }}
key: linux-kernel-${{ matrix.target }}-${{ hashFiles('third_party/linux/Makefile') }}-${{ steps.kernel.outputs.defconfig }}
- name: Build initramfs (CFBox only, no busybox)
run: |
bash scripts/build_initramfs.sh \
--arch ${{ matrix.target }} \
--cfbox build-${{ matrix.target }}-static/cfbox \
--output build/${{ matrix.target }}-initramfs.cpio
- name: Run QEMU system-mode test
run: |
bash scripts/qemu_system_test.sh \
--arch ${{ matrix.target }} \
--kernel third_party/linux/${{ steps.kernel.outputs.image }} \
--initramfs build/${{ matrix.target }}-initramfs.cpio \
--timeout 120