-
Notifications
You must be signed in to change notification settings - Fork 45
417 lines (356 loc) · 19.9 KB
/
ci.yaml
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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
on:
pull_request: {}
schedule:
- cron: '30 11,23 * * *'
# push:
jobs:
ci:
runs-on: [self-hosted]
timeout-minutes: 20
strategy:
matrix:
arch: [arm64] # arm, , ppc64le, riscv64, x86_64
toolchain: [clang, llvm] # gcc
config: [release] # debug
rustc: [1.54.0]
output: [src] # [src, build]
install: [rustup] # [rustup, standalone]
sysroot: [common] # [common, custom]
exclude:
# arm 32-bit gcc not yet supported
- arch: arm
toolchain: gcc
# Exclude `LLVM=1` where not supported.
- arch: ppc64le
toolchain: llvm
- arch: riscv64
toolchain: llvm
# A few independent combinations to avoid exploding the matrix:
# - The other option for `output`.
# - Different releases for `rustc`.
# - The other three (`install`, `sysroot`) combinations
# (they are interrelated, so the cross-product needs to be tested)
# include:
# - arch: arm64
# toolchain: gcc
# config: debug
# rustc: 1.54.0
# output: build
# install: rustup
# sysroot: custom
# - arch: ppc64le
# toolchain: clang
# config: release
# rustc: 1.54.0
# output: build
# install: standalone
# sysroot: common
# - arch: x86_64
# toolchain: llvm
# config: debug
# rustc: 1.54.0
# output: build
# install: standalone
# sysroot: custom
steps:
# Setup: checkout
- uses: actions/checkout@v2
# Setup: Store matrix name
- run: echo 'MATRIX_NAME=${{ matrix.arch }}-${{ matrix.toolchain }}-${{ matrix.config }}' >> $GITHUB_ENV
# Setup: Github cache
- uses: actions/cache@v2
with:
path: ~/.ccache
key: ${{ env.MATRIX_NAME }}-ccache-${{ github.run_id }}
restore-keys: |
${{ env.MATRIX_NAME }}-ccache-
# Setup: variables
- if: matrix.arch == 'x86_64'
run: |
echo 'IMAGE_PATH=arch/x86/boot/bzImage' >> $GITHUB_ENV
echo 'QEMU_ARCH=x86_64' >> $GITHUB_ENV
echo 'QEMU_MACHINE=pc' >> $GITHUB_ENV
echo 'QEMU_CPU=Cascadelake-Server' >> $GITHUB_ENV
echo 'QEMU_APPEND=console=ttyS0' >> $GITHUB_ENV
- if: matrix.arch == 'arm64'
run: |
echo 'MAKE_ARCH=ARCH=arm64' >> $GITHUB_ENV
echo 'MAKE_CROSS_COMPILE=CROSS_COMPILE=aarch64-linux-gnu-' >> $GITHUB_ENV
echo 'IMAGE_PATH=arch/arm64/boot/Image.gz' >> $GITHUB_ENV
echo 'QEMU_ARCH=aarch64' >> $GITHUB_ENV
echo 'QEMU_MACHINE=virt' >> $GITHUB_ENV
echo 'QEMU_CPU=cortex-a72' >> $GITHUB_ENV
- if: matrix.arch == 'ppc64le'
run: |
echo 'MAKE_ARCH=ARCH=powerpc' >> $GITHUB_ENV
echo 'MAKE_CROSS_COMPILE=CROSS_COMPILE=powerpc64le-linux-gnu-' >> $GITHUB_ENV
echo 'IMAGE_PATH=vmlinux' >> $GITHUB_ENV
echo 'QEMU_ARCH=ppc64' >> $GITHUB_ENV
echo 'QEMU_MACHINE=pseries' >> $GITHUB_ENV
echo 'QEMU_CPU=POWER9' >> $GITHUB_ENV
- if: matrix.arch == 'arm'
run: |
echo 'MAKE_ARCH=ARCH=arm' >> $GITHUB_ENV
echo 'MAKE_CROSS_COMPILE=CROSS_COMPILE=arm-linux-gnueabi-' >> $GITHUB_ENV
echo 'IMAGE_PATH=arch/arm/boot/zImage' >> $GITHUB_ENV
echo 'QEMU_ARCH=arm' >> $GITHUB_ENV
echo 'QEMU_MACHINE=virt' >> $GITHUB_ENV
echo 'QEMU_CPU=cortex-a7' >> $GITHUB_ENV
- if: matrix.arch == 'riscv64'
run: |
echo 'MAKE_ARCH=ARCH=riscv' >> $GITHUB_ENV
echo 'MAKE_CROSS_COMPILE=CROSS_COMPILE=riscv64-linux-gnu-' >> $GITHUB_ENV
echo 'IMAGE_PATH=arch/riscv/boot/Image' >> $GITHUB_ENV
echo 'QEMU_ARCH=riscv64' >> $GITHUB_ENV
echo 'QEMU_MACHINE=virt' >> $GITHUB_ENV
echo 'QEMU_CPU=rv64' >> $GITHUB_ENV
echo 'QEMU_ARGS=-bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf' >> $GITHUB_ENV
- if: matrix.toolchain == 'clang'
run: echo 'MAKE_TOOLCHAIN=CC=clang-13' >> $GITHUB_ENV
- if: matrix.toolchain == 'llvm'
run: echo 'MAKE_TOOLCHAIN=LLVM=1' >> $GITHUB_ENV
- if: matrix.output == 'build'
run: |
echo 'MAKE_OUTPUT=O=build' >> $GITHUB_ENV
echo 'BUILD_DIR=build/' >> $GITHUB_ENV
- if: matrix.sysroot == 'custom'
run: |
echo 'RUSTC_SYSROOT=--sysroot=$HOME/sysroot' >> $GITHUB_ENV
echo "MAKE_SYSROOT=KRUSTFLAGS=--sysroot=$HOME/sysroot" >> $GITHUB_ENV
# Setup: custom pre-built binaries folder
- run: |
mkdir bin
echo $(pwd)/bin >> $GITHUB_PATH
# Setup: LLVM
# - run: curl https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
# Retry to be resilient to intermittent network issues
# - run: |
# add-apt-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-12 main' ||
# add-apt-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-12 main' ||
# add-apt-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-12 main'
# - run: apt-get update -y
# - run: apt-get install -y llvm-12 clang-12 lld-12
- run: echo $(llvm-config-13 --bindir) >> $GITHUB_PATH
# Setup: GCC
- if: matrix.arch == 'arm'
run: apt-get install -y gcc-arm-linux-gnueabi lzop
# - if: matrix.arch == 'arm64'
# run: apt-get install -y gcc-aarch64-linux-gnu
- if: matrix.arch == 'ppc64le'
run: apt-get install -y gcc-powerpc64le-linux-gnu
- if: matrix.arch == 'riscv64'
run: apt-get install -y gcc-riscv64-linux-gnu
# Setup OpenSBI
- if: matrix.arch == 'riscv64'
run: apt-get install -y opensbi
# Setup: libelf
# - run: apt-get install -y libelf-dev
# Setup: QEMU
- if: matrix.arch == 'x86_64'
run: apt-get install -y qemu-system-x86
# - if: matrix.arch == 'arm' || matrix.arch == 'arm64'
# run: apt-get install -y qemu-system-arm
- if: matrix.arch == 'ppc64le'
run: apt-get install -y qemu-system-ppc
- if: matrix.arch == 'riscv64'
run: |
curl -o bin/qemu-system-riscv64 https://raw.githubusercontent.com/Rust-for-Linux/ci-bin/master/qemu-6.0.0/bin/qemu-system-riscv64
chmod u+x bin/qemu-system-riscv64
# Setup: rustc
- if: matrix.install == 'rustup'
run: |
rustup default ${{ matrix.rustc }}
rustup component add rustfmt
- if: matrix.install == 'standalone'
run: |
curl https://static.rust-lang.org/dist/rust-${{ matrix.rustc }}-x86_64-unknown-linux-gnu.tar.gz | tar xz
rust-${{ matrix.rustc }}-x86_64-unknown-linux-gnu/install.sh --without=rust-docs --prefix=$HOME/rustc
echo $HOME/rustc/bin >> $GITHUB_PATH
# Setup: rustc native libs
- if: matrix.sysroot == 'custom'
run: |
mkdir $(rustc ${{ env.RUSTC_SYSROOT }} --print sysroot)
ln -s $(rustc --print sysroot)/lib $(rustc ${{ env.RUSTC_SYSROOT }} --print sysroot)/lib
# Setup: rustc source
- if: matrix.install == 'rustup' && matrix.sysroot == 'common'
run: rustup component add rust-src
- if: matrix.install != 'rustup' || matrix.sysroot != 'common'
run: |
git clone -n https://github.com/rust-lang/rust $(rustc ${{ env.RUSTC_SYSROOT }} --print sysroot)/lib/rustlib/src/rust
cd $(rustc ${{ env.RUSTC_SYSROOT }} --print sysroot)/lib/rustlib/src/rust
git checkout $(rustc -vV | grep -F 'commit-hash' | awk '{print $2}')
git submodule update --init library
# Setup: clippy
- run: rustup component add clippy
# Setup: bindgen
# - run: |
# curl -o bin/bindgen https://raw.githubusercontent.com/Rust-for-Linux/ci-bin/master/bindgen-0.56.0/bin/bindgen
# chmod u+x bin/bindgen
# Setup: ccache
- run: |
# apt-get install ccache
echo '/usr/lib/ccache:$PATH' >> $GITHUB_PATH
echo 'CCACHE_COMPRESS=true' >> $GITHUB_ENV
# Setup: Check existing ccache
- run: ccache -s
# Setup: busybox
# - run: git clone --depth 1 -b 1_30_1 https://github.com/mirror/busybox
- run: cp -r /busybox ./
- run: mv .github/workflows/busybox.config busybox/.config
- run: cd busybox && make ${{ env.MAKE_CROSS_COMPILE }} -j3
# Setup: module parameters test
- run: |
cp samples/rust/rust_module_parameters.rs samples/rust/rust_module_parameters_builtin_default.rs
cp samples/rust/rust_module_parameters.rs samples/rust/rust_module_parameters_builtin_custom.rs
cp samples/rust/rust_module_parameters.rs samples/rust/rust_module_parameters_loadable_default.rs
cp samples/rust/rust_module_parameters.rs samples/rust/rust_module_parameters_loadable_custom.rs
sed -i 's:rust_module_parameters:rust_module_parameters_builtin_default:g' samples/rust/rust_module_parameters_builtin_default.rs
sed -i 's:rust_module_parameters:rust_module_parameters_builtin_custom:g' samples/rust/rust_module_parameters_builtin_custom.rs
sed -i 's:rust_module_parameters:rust_module_parameters_loadable_default:g' samples/rust/rust_module_parameters_loadable_default.rs
sed -i 's:rust_module_parameters:rust_module_parameters_loadable_custom:g' samples/rust/rust_module_parameters_loadable_custom.rs
echo 'obj-y += rust_module_parameters_builtin_default.o' >> samples/rust/Makefile
echo 'obj-y += rust_module_parameters_builtin_custom.o' >> samples/rust/Makefile
echo 'obj-m += rust_module_parameters_loadable_default.o' >> samples/rust/Makefile
echo 'obj-m += rust_module_parameters_loadable_custom.o' >> samples/rust/Makefile
# Pre-check
- run: make LLVM=1 rustfmtcheck
# Build
- run: mv .github/workflows/kernel-${{ matrix.arch }}-${{ matrix.config }}.config .config
- if: matrix.output == 'build'
run: |
mkdir ${{ env.BUILD_DIR }}
mv .config ${{ env.BUILD_DIR }}.config
sed -i 's:samples/rust/:${{ env.BUILD_DIR }}samples/rust/:' .github/workflows/qemu-initramfs.desc
- run: make ${{ env.MAKE_ARCH }} ${{ env.MAKE_CROSS_COMPILE }} ${{ env.MAKE_TOOLCHAIN }} ${{ env.MAKE_OUTPUT }} ${{ env.MAKE_SYSROOT }} -j30
# Run
- run: ${{ env.BUILD_DIR }}usr/gen_init_cpio .github/workflows/qemu-initramfs.desc > qemu-initramfs.img
- run: |
qemu-system-${{ env.QEMU_ARCH }} \
${{ env.QEMU_ARGS }} \
-kernel ${{ env.BUILD_DIR }}${{ env.IMAGE_PATH }} \
-initrd qemu-initramfs.img \
-M ${{ env.QEMU_MACHINE }} \
-cpu ${{ env.QEMU_CPU }} \
-smp 1 \
-nographic \
-vga none \
-no-reboot \
-append '${{ env.QEMU_APPEND }} \
rust_module_parameters_builtin_custom.my_bool=n \
rust_module_parameters_builtin_custom.my_i32=345543 \
rust_module_parameters_builtin_custom.my_str=🦀mod \
rust_module_parameters_builtin_custom.my_usize=84 \
rust_module_parameters_builtin_custom.my_array=1,2,3 \
' \
| sed s:$'\r'$:: \
| tee qemu-stdout.log
# The kernel should not be generating any warnings
- run: |
! grep -v 'at mm/debug_vm_pgtable.c:' qemu-stdout.log | grep '] WARNING:'
# Check
- run: |
grep '] rust_minimal: Rust minimal sample (init)$' qemu-stdout.log
grep '] rust_minimal: Am I built-in? false$' qemu-stdout.log
grep '] rust_minimal: My message is on the heap!$' qemu-stdout.log
grep '] rust_minimal: Rust minimal sample (exit)$' qemu-stdout.log
- run: |
grep '] rust_print: Rust printing macros sample (init)$' qemu-stdout.log
grep '] rust_print: Emergency message (level 0) without args$' qemu-stdout.log
grep '] rust_print: Alert message (level 1) without args$' qemu-stdout.log
grep '] rust_print: Critical message (level 2) without args$' qemu-stdout.log
grep '] rust_print: Error message (level 3) without args$' qemu-stdout.log
grep '] rust_print: Warning message (level 4) without args$' qemu-stdout.log
grep '] rust_print: Notice message (level 5) without args$' qemu-stdout.log
grep '] rust_print: Info message (level 6) without args$' qemu-stdout.log
grep '] rust_print: A line that is continued without args$' qemu-stdout.log
grep '] rust_print: Emergency message (level 0) with args$' qemu-stdout.log
grep '] rust_print: Alert message (level 1) with args$' qemu-stdout.log
grep '] rust_print: Critical message (level 2) with args$' qemu-stdout.log
grep '] rust_print: Error message (level 3) with args$' qemu-stdout.log
grep '] rust_print: Warning message (level 4) with args$' qemu-stdout.log
grep '] rust_print: Notice message (level 5) with args$' qemu-stdout.log
grep '] rust_print: Info message (level 6) with args$' qemu-stdout.log
grep '] rust_print: A line that is continued with args$' qemu-stdout.log
grep '] rust_print: Rust printing macros sample (exit)$' qemu-stdout.log
- run: |
grep '] rust_module_parameters_builtin_default: Rust module parameters sample (init)' qemu-stdout.log
grep '] rust_module_parameters_builtin_default: my_bool: true$' qemu-stdout.log
grep '] rust_module_parameters_builtin_default: my_i32: 42$' qemu-stdout.log
grep '] rust_module_parameters_builtin_default: my_str: default str val$' qemu-stdout.log
grep '] rust_module_parameters_builtin_default: my_usize: 42$' qemu-stdout.log
grep '] rust_module_parameters_builtin_default: my_array: \[0, 1]$' qemu-stdout.log
grep '] rust_module_parameters_builtin_custom: Rust module parameters sample (init)$' qemu-stdout.log
grep '] rust_module_parameters_builtin_custom: my_bool: false$' qemu-stdout.log
grep '] rust_module_parameters_builtin_custom: my_i32: 345543$' qemu-stdout.log
grep '] rust_module_parameters_builtin_custom: my_str: 🦀mod$' qemu-stdout.log
grep '] rust_module_parameters_builtin_custom: my_usize: 84$' qemu-stdout.log
grep '] rust_module_parameters_builtin_custom: my_array: \[1, 2, 3]$' qemu-stdout.log
grep '] rust_module_parameters_loadable_default: Rust module parameters sample (init)$' qemu-stdout.log
grep '] rust_module_parameters_loadable_default: my_bool: true$' qemu-stdout.log
grep '] rust_module_parameters_loadable_default: my_i32: 42$' qemu-stdout.log
grep '] rust_module_parameters_loadable_default: my_str: default str val$' qemu-stdout.log
grep '] rust_module_parameters_loadable_default: my_usize: 42$' qemu-stdout.log
grep '] rust_module_parameters_loadable_default: my_array: \[0, 1]$' qemu-stdout.log
grep '] rust_module_parameters_loadable_default: Rust module parameters sample (exit)$' qemu-stdout.log
grep '] rust_module_parameters_loadable_custom: Rust module parameters sample (init)$' qemu-stdout.log
grep '] rust_module_parameters_loadable_custom: my_bool: false$' qemu-stdout.log
grep '] rust_module_parameters_loadable_custom: my_i32: 345543$' qemu-stdout.log
grep '] rust_module_parameters_loadable_custom: my_str: 🦀mod$' qemu-stdout.log
grep '] rust_module_parameters_loadable_custom: my_usize: 84$' qemu-stdout.log
grep '] rust_module_parameters_loadable_custom: my_array: \[1, 2, 3]$' qemu-stdout.log
grep '] rust_module_parameters_loadable_custom: Rust module parameters sample (exit)$' qemu-stdout.log
grep '] rust_module_parameters: Rust module parameters sample (init)$' qemu-stdout.log
grep '] rust_module_parameters: my_bool: true$' qemu-stdout.log
grep '] rust_module_parameters: my_i32: 42$' qemu-stdout.log
grep '] rust_module_parameters: my_str: default str val$' qemu-stdout.log
grep '] rust_module_parameters: my_usize: 42$' qemu-stdout.log
grep '] rust_module_parameters: my_array: \[0, 1]$' qemu-stdout.log
grep '] rust_module_parameters: Rust module parameters sample (exit)$' qemu-stdout.log
- run: |
grep '] rust_sync: Rust synchronisation primitives sample (init)$' qemu-stdout.log
grep '] rust_sync: Value: 10$' qemu-stdout.log
grep '] rust_sync: Rust synchronisation primitives sample (exit)$' qemu-stdout.log
- run: |
grep '] rust_chrdev: Rust character device sample (init)$' qemu-stdout.log
grep '] rust_chrdev: Rust character device sample (exit)$' qemu-stdout.log
- run: |
grep '] rust_miscdev: Rust miscellaneous device sample (init)$' qemu-stdout.log
grep '] rust_miscdev: Rust miscellaneous device sample (exit)$' qemu-stdout.log
- run: |
grep '] rust_stack_probing: Rust stack probing sample (init)$' qemu-stdout.log
grep '] rust_stack_probing: Large array has length: 514$' qemu-stdout.log
grep '] rust_stack_probing: Rust stack probing sample (exit)$' qemu-stdout.log
- run: |
grep '] rust_semaphore: Rust semaphore sample (init)$' qemu-stdout.log
grep '] rust_semaphore: Rust semaphore sample (exit)$' qemu-stdout.log
- run: |
grep '] rust_semaphore_c: Rust semaphore sample (in C, for comparison) (init)$' qemu-stdout.log
grep '] rust_semaphore_c: Rust semaphore sample (in C, for comparison) (exit)$' qemu-stdout.log
# Report
- run: |
ls -l \
${{ env.BUILD_DIR }}samples/rust/*.o \
${{ env.BUILD_DIR }}samples/rust/*.ko \
${{ env.BUILD_DIR }}drivers/android/rust_binder.o \
${{ env.BUILD_DIR }}rust/*.o \
${{ env.BUILD_DIR }}vmlinux \
${{ env.BUILD_DIR }}${{ env.IMAGE_PATH }}
size \
${{ env.BUILD_DIR }}samples/rust/*.o \
${{ env.BUILD_DIR }}samples/rust/*.ko \
${{ env.BUILD_DIR }}drivers/android/rust_binder.o \
${{ env.BUILD_DIR }}rust/*.o \
${{ env.BUILD_DIR }}vmlinux
# # Clippy
# - run: make ${{ env.MAKE_ARCH }} ${{ env.MAKE_CROSS_COMPILE }} ${{ env.MAKE_TOOLCHAIN }} ${{ env.MAKE_OUTPUT }} ${{ env.MAKE_SYSROOT }} -j3 CLIPPY=1
# # Docs
# - run: make ${{ env.MAKE_ARCH }} ${{ env.MAKE_CROSS_COMPILE }} ${{ env.MAKE_TOOLCHAIN }} ${{ env.MAKE_OUTPUT }} ${{ env.MAKE_SYSROOT }} -j3 rustdoc
# # Tests
# - run: make ${{ env.MAKE_ARCH }} ${{ env.MAKE_CROSS_COMPILE }} ${{ env.MAKE_TOOLCHAIN }} ${{ env.MAKE_OUTPUT }} ${{ env.MAKE_SYSROOT }} -j3 rusttest
# # Formatting
# - run: make ${{ env.MAKE_ARCH }} ${{ env.MAKE_CROSS_COMPILE }} ${{ env.MAKE_TOOLCHAIN }} ${{ env.MAKE_OUTPUT }} ${{ env.MAKE_SYSROOT }} -j3 rustfmtcheck
# View changes to ccache
- run: ccache -s
concurrency:
group: ${{ github.head_ref || github.ref_name }}
cancel-in-progress: true