|
6 | 6 | jobs:
|
7 | 7 | ci:
|
8 | 8 | runs-on: ubuntu-20.04
|
9 |
| - timeout-minutes: 15 |
| 9 | + timeout-minutes: 20 |
10 | 10 |
|
11 | 11 | strategy:
|
12 | 12 | matrix:
|
13 |
| - mode: [debug, release] |
14 |
| - module: [builtin, loadable] |
15 |
| - outputdir: [src, build] |
| 13 | + arch: [x86_64, arm64] |
| 14 | + toolchain: [gcc, clang, llvm] |
| 15 | + config: [debug, release] |
| 16 | + rustc: [nightly-2021-01-02] |
| 17 | + output: [src] |
| 18 | + include: |
| 19 | + - arch: x86_64 |
| 20 | + toolchain: llvm |
| 21 | + config: release |
| 22 | + rustc: nightly-2021-01-02 |
| 23 | + output: build |
16 | 24 |
|
17 | 25 | steps:
|
18 | 26 | # Setup
|
19 | 27 | - uses: actions/checkout@v2
|
| 28 | + |
| 29 | + - if: matrix.arch == 'x86_64' |
| 30 | + run: | |
| 31 | + echo 'IMAGE_PATH=arch/x86/boot/bzImage' >> $GITHUB_ENV |
| 32 | + echo 'QEMU_ARCH=x86_64' >> $GITHUB_ENV |
| 33 | + echo 'QEMU_MACHINE=pc' >> $GITHUB_ENV |
| 34 | + echo 'QEMU_CPU=Cascadelake-Server' >> $GITHUB_ENV |
| 35 | + echo 'QEMU_APPEND=console=ttyS0' >> $GITHUB_ENV |
| 36 | + - if: matrix.arch == 'arm64' |
| 37 | + run: | |
| 38 | + echo 'MAKE_ARCH=ARCH=arm64' >> $GITHUB_ENV |
| 39 | + echo 'MAKE_CROSS_COMPILE=CROSS_COMPILE=aarch64-linux-gnu-' >> $GITHUB_ENV |
| 40 | + echo 'IMAGE_PATH=arch/arm64/boot/Image.gz' >> $GITHUB_ENV |
| 41 | + echo 'QEMU_ARCH=aarch64' >> $GITHUB_ENV |
| 42 | + echo 'QEMU_MACHINE=virt' >> $GITHUB_ENV |
| 43 | + echo 'QEMU_CPU=cortex-a72' >> $GITHUB_ENV |
| 44 | +
|
| 45 | + - if: matrix.toolchain == 'clang' |
| 46 | + run: echo 'MAKE_TOOLCHAIN=CC=clang-11' >> $GITHUB_ENV |
| 47 | + - if: matrix.toolchain == 'llvm' |
| 48 | + run: echo 'MAKE_TOOLCHAIN=LLVM=1' >> $GITHUB_ENV |
| 49 | + |
| 50 | + - if: matrix.output == 'src' |
| 51 | + run: | |
| 52 | + echo 'BUILD_DIR=.' >> $GITHUB_ENV |
| 53 | + - if: matrix.output == 'build' |
| 54 | + run: | |
| 55 | + echo 'MAKE_OUTPUT=O=build' >> $GITHUB_ENV |
| 56 | + echo 'BUILD_DIR=build' >> $GITHUB_ENV |
| 57 | +
|
20 | 58 | - run: wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
|
21 | 59 | - run: sudo add-apt-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-11 main'
|
22 | 60 | - run: sudo apt-get update -y
|
23 |
| - - run: sudo apt-get install -y clang-11 libelf-dev qemu-system-x86 busybox-static |
24 |
| - - run: rustup default nightly-2021-01-02 |
| 61 | + - run: sudo apt-get install -y llvm-11 clang-11 lld-11 libelf-dev qemu-system-arm qemu-system-x86 gcc-aarch64-linux-gnu |
| 62 | + - run: echo $(llvm-config-11 --bindir) >> $GITHUB_PATH |
| 63 | + - run: rustup default ${{ matrix.rustc }} |
25 | 64 | - run: rustup component add rustfmt
|
26 | 65 | - run: rustup component add rust-src
|
| 66 | + - run: git clone --depth 1 --branch 0.1.38 https://github.com/rust-lang/compiler-builtins.git $(rustc --print sysroot)/lib/rustlib/src/compiler-builtins |
| 67 | + - run: git clone --depth 1 --branch 1_30_1 https://github.com/mirror/busybox |
| 68 | + - run: mv .github/workflows/busybox.config busybox/.config |
| 69 | + - run: cd busybox && make ${{ env.MAKE_CROSS_COMPILE }} -j3 |
27 | 70 |
|
28 | 71 | # Build
|
29 |
| - - run: cp .github/workflows/kernel-${{ matrix.mode }}.config .config |
| 72 | + - run: mv .github/workflows/kernel-${{ matrix.arch }}-${{ matrix.config }}.config .config |
30 | 73 |
|
31 |
| - - if: matrix.module == 'loadable' |
32 |
| - run: sed -i -E 's/^(CONFIG_RUST_EXAMPLE=)(y)$/\1m/g' .config |
| 74 | + - if: matrix.output == 'build' |
| 75 | + run: | |
| 76 | + mkdir ${{ env.BUILD_DIR }} |
| 77 | + mv .config ${{ env.BUILD_DIR }}/.config |
| 78 | + sed -i 's:drivers/:${{ env.BUILD_DIR }}/drivers/:' .github/workflows/qemu-initramfs.desc |
33 | 79 |
|
34 |
| - - if: matrix.outputdir == 'build' |
35 |
| - run: mkdir build && mv .config build/.config |
36 |
| - |
37 |
| - - if: matrix.outputdir == 'src' |
38 |
| - run: make CC=clang-11 LLVM_CONFIG_PATH=llvm-config-11 -j3 |
39 |
| - - if: matrix.outputdir == 'build' |
40 |
| - run: make O=build CC=clang-11 LLVM_CONFIG_PATH=llvm-config-11 -j3 |
| 80 | + - run: make ${{ env.MAKE_ARCH }} ${{ env.MAKE_CROSS_COMPILE }} ${{ env.MAKE_TOOLCHAIN }} ${{ env.MAKE_OUTPUT }} -j3 |
41 | 81 |
|
42 | 82 | # Run
|
43 |
| - - if: matrix.module == 'builtin' |
44 |
| - run: sed -i '/rust_example/d' .github/workflows/qemu-initramfs.desc |
| 83 | + - run: ${{ env.BUILD_DIR }}/usr/gen_init_cpio .github/workflows/qemu-initramfs.desc > qemu-initramfs.img |
45 | 84 |
|
46 |
| - - if: matrix.outputdir == 'build' |
47 |
| - run: sed -i 's:drivers/:build/drivers/:' .github/workflows/qemu-initramfs.desc |
| 85 | + - run: qemu-system-${{ env.QEMU_ARCH }} -kernel ${{ env.BUILD_DIR }}/${{ env.IMAGE_PATH }} -initrd qemu-initramfs.img -M ${{ env.QEMU_MACHINE }} -cpu ${{ env.QEMU_CPU }} -smp 2 -nographic -no-reboot -append '${{ env.QEMU_APPEND }} rust_example.my_i32=123321 rust_example_2.my_i32=234432' | tee qemu-stdout.log |
48 | 86 |
|
49 |
| - - if: matrix.outputdir == 'src' |
50 |
| - run: usr/gen_init_cpio .github/workflows/qemu-initramfs.desc > qemu-initramfs.img |
51 |
| - - if: matrix.outputdir == 'build' |
52 |
| - run: build/usr/gen_init_cpio .github/workflows/qemu-initramfs.desc > qemu-initramfs.img |
| 87 | + # Check |
| 88 | + - run: grep -F '] Rust Example (init)' qemu-stdout.log |
| 89 | + - run: grep -F '] [2] Rust Example (init)' qemu-stdout.log |
| 90 | + - run: grep -F '] [3] Rust Example (init)' qemu-stdout.log |
| 91 | + - run: grep -F '] [4] Rust Example (init)' qemu-stdout.log |
53 | 92 |
|
54 |
| - - if: matrix.outputdir == 'src' |
55 |
| - run: qemu-system-x86_64 -kernel arch/x86/boot/bzImage -initrd qemu-initramfs.img -cpu Cascadelake-Server -smp 2 -nographic -no-reboot -append "console=ttyS0 ${{ matrix.module == 'builtin' && 'rust_example.my_i32=123321' || '' }}" | tee qemu-stdout.log |
56 |
| - - if: matrix.outputdir == 'build' |
57 |
| - run: qemu-system-x86_64 -kernel build/arch/x86/boot/bzImage -initrd qemu-initramfs.img -cpu Cascadelake-Server -smp 2 -nographic -no-reboot -append "console=ttyS0 ${{ matrix.module == 'builtin' && 'rust_example.my_i32=123321' || '' }}" | tee qemu-stdout.log |
| 93 | + - run: "grep -F '] my_i32: 123321' qemu-stdout.log" |
| 94 | + - run: "grep -F '] [2] my_i32: 234432' qemu-stdout.log" |
| 95 | + - run: "grep -F '] [3] my_i32: 345543' qemu-stdout.log" |
| 96 | + - run: "grep -F '] [4] my_i32: 456654' qemu-stdout.log" |
58 | 97 |
|
59 |
| - # Check |
60 |
| - - run: grep -F 'Rust Example (init)' qemu-stdout.log |
61 |
| - - run: "grep 'my_i32: \\+123321' qemu-stdout.log" |
62 |
| - - if: matrix.module == 'loadable' |
63 |
| - run: grep -F 'Rust Example (exit)' qemu-stdout.log |
| 98 | + - run: grep -F '] [3] Rust Example (exit)' qemu-stdout.log |
| 99 | + - run: grep -F '] [4] Rust Example (exit)' qemu-stdout.log |
64 | 100 |
|
65 | 101 | # Report
|
66 |
| - - if: matrix.outputdir == 'src' && matrix.module == 'loadable' |
67 |
| - run: ls -l drivers/char/rust_example/rust_example.ko |
68 |
| - - if: matrix.outputdir == 'build' && matrix.module == 'loadable' |
69 |
| - run: ls -l build/drivers/char/rust_example/rust_example.ko |
70 |
| - |
71 |
| - - if: matrix.outputdir == 'src' |
72 |
| - run: ls -l vmlinux arch/x86/boot/bzImage |
73 |
| - - if: matrix.outputdir == 'build' |
74 |
| - run: ls -l build/vmlinux build/arch/x86/boot/bzImage |
75 |
| - |
76 |
| - - if: matrix.outputdir == 'src' |
77 |
| - run: size vmlinux |
78 |
| - - if: matrix.outputdir == 'build' |
79 |
| - run: size build/vmlinux |
| 102 | + - run: ls -l ${{ env.BUILD_DIR }}/drivers/char/rust_example.o ${{ env.BUILD_DIR }}/drivers/char/rust_example_3.ko ${{ env.BUILD_DIR }}/rust/*.o ${{ env.BUILD_DIR }}/vmlinux ${{ env.BUILD_DIR }}/${{ env.IMAGE_PATH }} |
| 103 | + - run: size ${{ env.BUILD_DIR }}/drivers/char/rust_example.o ${{ env.BUILD_DIR }}/drivers/char/rust_example_3.ko ${{ env.BUILD_DIR }}/rust/*.o ${{ env.BUILD_DIR }}/vmlinux |
0 commit comments