|
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: [2021-01-02] |
| 17 | + output: [src] # [src, build] |
| 18 | + install: [rustup] # [rustup, standalone] |
| 19 | + sysroot: [common] # [common, custom] |
| 20 | + |
| 21 | + # A few independent combinations to avoid exploding the matrix: |
| 22 | + # - The other option for `output`. |
| 23 | + # - Different nightlies for `rustc`. |
| 24 | + # - The other three (`install`, `sysroot`) combinations |
| 25 | + # (they are interrelated, so the cross-product needs to be tested) |
| 26 | + include: |
| 27 | + - arch: x86_64 |
| 28 | + toolchain: gcc |
| 29 | + config: debug |
| 30 | + rustc: 2021-01-09 |
| 31 | + output: build |
| 32 | + install: rustup |
| 33 | + sysroot: custom |
| 34 | + |
| 35 | + - arch: arm64 |
| 36 | + toolchain: clang |
| 37 | + config: release |
| 38 | + rustc: 2021-01-16 |
| 39 | + output: build |
| 40 | + install: standalone |
| 41 | + sysroot: common |
| 42 | + |
| 43 | + - arch: x86_64 |
| 44 | + toolchain: llvm |
| 45 | + config: debug |
| 46 | + rustc: 2021-01-19 |
| 47 | + output: build |
| 48 | + install: standalone |
| 49 | + sysroot: custom |
16 | 50 |
|
17 | 51 | steps:
|
18 |
| - # Setup |
| 52 | + # Setup: checkout |
19 | 53 | - uses: actions/checkout@v2
|
20 |
| - - run: wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - |
| 54 | + |
| 55 | + # Setup: variables |
| 56 | + - if: matrix.arch == 'x86_64' |
| 57 | + run: | |
| 58 | + echo 'IMAGE_PATH=arch/x86/boot/bzImage' >> $GITHUB_ENV |
| 59 | + echo 'QEMU_ARCH=x86_64' >> $GITHUB_ENV |
| 60 | + echo 'QEMU_MACHINE=pc' >> $GITHUB_ENV |
| 61 | + echo 'QEMU_CPU=Cascadelake-Server' >> $GITHUB_ENV |
| 62 | + echo 'QEMU_APPEND=console=ttyS0' >> $GITHUB_ENV |
| 63 | + - if: matrix.arch == 'arm64' |
| 64 | + run: | |
| 65 | + echo 'MAKE_ARCH=ARCH=arm64' >> $GITHUB_ENV |
| 66 | + echo 'MAKE_CROSS_COMPILE=CROSS_COMPILE=aarch64-linux-gnu-' >> $GITHUB_ENV |
| 67 | + echo 'IMAGE_PATH=arch/arm64/boot/Image.gz' >> $GITHUB_ENV |
| 68 | + echo 'QEMU_ARCH=aarch64' >> $GITHUB_ENV |
| 69 | + echo 'QEMU_MACHINE=virt' >> $GITHUB_ENV |
| 70 | + echo 'QEMU_CPU=cortex-a72' >> $GITHUB_ENV |
| 71 | +
|
| 72 | + - if: matrix.toolchain == 'clang' |
| 73 | + run: echo 'MAKE_TOOLCHAIN=CC=clang-11' >> $GITHUB_ENV |
| 74 | + - if: matrix.toolchain == 'llvm' |
| 75 | + run: echo 'MAKE_TOOLCHAIN=LLVM=1' >> $GITHUB_ENV |
| 76 | + |
| 77 | + - if: matrix.output == 'build' |
| 78 | + run: | |
| 79 | + echo 'MAKE_OUTPUT=O=build' >> $GITHUB_ENV |
| 80 | + echo 'BUILD_DIR=build/' >> $GITHUB_ENV |
| 81 | +
|
| 82 | + - if: matrix.sysroot == 'custom' |
| 83 | + run: | |
| 84 | + echo 'RUSTC_SYSROOT=--sysroot=$HOME/sysroot' >> $GITHUB_ENV |
| 85 | + echo "MAKE_SYSROOT=KRUSTCFLAGS=--sysroot=$HOME/sysroot" >> $GITHUB_ENV |
| 86 | +
|
| 87 | + # Setup: LLVM |
| 88 | + - run: curl https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - |
21 | 89 | - run: sudo add-apt-repository 'deb http://apt.llvm.org/focal/ llvm-toolchain-focal-11 main'
|
22 | 90 | - 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 |
25 |
| - - run: rustup component add rustfmt |
26 |
| - - run: rustup component add rust-src |
| 91 | + - run: sudo apt-get install -y llvm-11 clang-11 lld-11 |
| 92 | + - run: echo $(llvm-config-11 --bindir) >> $GITHUB_PATH |
27 | 93 |
|
28 |
| - # Build |
29 |
| - - run: cp .github/workflows/kernel-${{ matrix.mode }}.config .config |
| 94 | + # Setup: GCC |
| 95 | + - if: matrix.arch == 'arm64' |
| 96 | + run: sudo apt-get install -y gcc-aarch64-linux-gnu |
30 | 97 |
|
31 |
| - - if: matrix.module == 'loadable' |
32 |
| - run: sed -i -E 's/^(CONFIG_RUST_EXAMPLE=)(y)$/\1m/g' .config |
| 98 | + # Setup: libelf |
| 99 | + - run: sudo apt-get install -y libelf-dev |
33 | 100 |
|
34 |
| - - if: matrix.outputdir == 'build' |
35 |
| - run: mkdir build && mv .config build/.config |
| 101 | + # Setup: QEMU |
| 102 | + - if: matrix.arch == 'x86_64' |
| 103 | + run: sudo apt-get install -y qemu-system-x86 |
| 104 | + - if: matrix.arch == 'arm64' |
| 105 | + run: sudo apt-get install -y qemu-system-arm |
36 | 106 |
|
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 |
| 107 | + # Setup: rustc |
| 108 | + - if: matrix.install == 'rustup' |
| 109 | + run: | |
| 110 | + rustup default nightly-${{ matrix.rustc }} |
| 111 | + rustup component add rustfmt |
| 112 | + - if: matrix.install == 'standalone' |
| 113 | + run: | |
| 114 | + curl https://static.rust-lang.org/dist/${{ matrix.rustc }}/rust-nightly-x86_64-unknown-linux-gnu.tar.gz | tar xz |
| 115 | + rust-nightly-x86_64-unknown-linux-gnu/install.sh --without=rust-docs --prefix=$HOME/rustc |
| 116 | + echo $HOME/rustc/bin >> $GITHUB_PATH |
41 | 117 |
|
42 |
| - # Run |
43 |
| - - if: matrix.module == 'builtin' |
44 |
| - run: sed -i '/rust_example/d' .github/workflows/qemu-initramfs.desc |
| 118 | + # Setup: rustc native libs |
| 119 | + - if: matrix.sysroot == 'custom' |
| 120 | + run: | |
| 121 | + mkdir $(rustc ${{ env.RUSTC_SYSROOT }} --print sysroot) |
| 122 | + ln -s $(rustc --print sysroot)/lib $(rustc ${{ env.RUSTC_SYSROOT }} --print sysroot)/lib |
45 | 123 |
|
46 |
| - - if: matrix.outputdir == 'build' |
47 |
| - run: sed -i 's:drivers/:build/drivers/:' .github/workflows/qemu-initramfs.desc |
| 124 | + # Setup: rustc source |
| 125 | + - if: matrix.install == 'rustup' && matrix.sysroot == 'common' |
| 126 | + run: rustup component add rust-src |
| 127 | + - if: matrix.install != 'rustup' || matrix.sysroot != 'common' |
| 128 | + run: | |
| 129 | + git clone -n https://github.com/rust-lang/rust $(rustc ${{ env.RUSTC_SYSROOT }} --print sysroot)/lib/rustlib/src/rust |
| 130 | + cd $(rustc ${{ env.RUSTC_SYSROOT }} --print sysroot)/lib/rustlib/src/rust |
| 131 | + git checkout $(rustc -vV | grep -F 'commit-hash' | awk '{print $2}') |
| 132 | + git submodule update --init library |
48 | 133 |
|
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 |
| 134 | + # Setup: compiler-builtins source |
| 135 | + - run: git clone --depth 1 -b 0.1.39 https://github.com/rust-lang/compiler-builtins.git $(rustc ${{ env.RUSTC_SYSROOT }} --print sysroot)/lib/rustlib/src/compiler-builtins |
53 | 136 |
|
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 |
| 137 | + # Setup: bindgen |
| 138 | + - run: cargo install --version 0.56.0 bindgen |
| 139 | + |
| 140 | + # Setup: busybox |
| 141 | + - run: git clone --depth 1 -b 1_30_1 https://github.com/mirror/busybox |
| 142 | + - run: mv .github/workflows/busybox.config busybox/.config |
| 143 | + - run: cd busybox && make ${{ env.MAKE_CROSS_COMPILE }} -j3 |
| 144 | + |
| 145 | + # Build |
| 146 | + - run: mv .github/workflows/kernel-${{ matrix.arch }}-${{ matrix.config }}.config .config |
| 147 | + |
| 148 | + - if: matrix.output == 'build' |
| 149 | + run: | |
| 150 | + mkdir ${{ env.BUILD_DIR }} |
| 151 | + mv .config ${{ env.BUILD_DIR }}.config |
| 152 | + sed -i 's:drivers/:${{ env.BUILD_DIR }}drivers/:' .github/workflows/qemu-initramfs.desc |
| 153 | +
|
| 154 | + - run: make ${{ env.MAKE_ARCH }} ${{ env.MAKE_CROSS_COMPILE }} ${{ env.MAKE_TOOLCHAIN }} ${{ env.MAKE_OUTPUT }} ${{ env.MAKE_SYSROOT }} -j3 |
| 155 | + |
| 156 | + # Run |
| 157 | + - run: ${{ env.BUILD_DIR }}usr/gen_init_cpio .github/workflows/qemu-initramfs.desc > qemu-initramfs.img |
| 158 | + |
| 159 | + - 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 |
58 | 160 |
|
59 | 161 | # 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 |
| 162 | + - run: grep -F '] Rust Example (init)' qemu-stdout.log |
| 163 | + - run: grep -F '] [2] Rust Example (init)' qemu-stdout.log |
| 164 | + - run: grep -F '] [3] Rust Example (init)' qemu-stdout.log |
| 165 | + - run: grep -F '] [4] Rust Example (init)' qemu-stdout.log |
| 166 | + |
| 167 | + - run: "grep -F '] my_i32: 123321' qemu-stdout.log" |
| 168 | + - run: "grep -F '] [2] my_i32: 234432' qemu-stdout.log" |
| 169 | + - run: "grep -F '] [3] my_i32: 345543' qemu-stdout.log" |
| 170 | + - run: "grep -F '] [4] my_i32: 456654' qemu-stdout.log" |
| 171 | + |
| 172 | + - run: grep -F '] [3] Rust Example (exit)' qemu-stdout.log |
| 173 | + - run: grep -F '] [4] Rust Example (exit)' qemu-stdout.log |
64 | 174 |
|
65 | 175 | # 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 |
| 176 | + - 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 }} |
| 177 | + - 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