1name: Cross-build Kernel
2
3on:
4  push:
5    branches: [ main, 'stable/13' ]
6  pull_request:
7    branches: [ main ]
8
9jobs:
10  build:
11    name: ${{ matrix.target_arch }} ${{ matrix.os }} (${{ matrix.compiler }})
12    runs-on: ${{ matrix.os }}
13    strategy:
14      fail-fast: false
15      matrix:
16        target_arch: [ amd64, aarch64 ]
17        os: [ ubuntu-20.04, ubuntu-22.04, macos-latest ]
18        include:
19          # TODO: both Ubuntu and macOS have bmake packages, we should try them instead of bootstrapping our own copy.
20          - os: ubuntu-20.04
21            compiler: clang-12
22            cross-bindir: /usr/lib/llvm-12/bin
23            pkgs: bmake libarchive-dev clang-12 lld-12
24          - os: ubuntu-22.04
25            compiler: clang-14
26            cross-bindir: /usr/lib/llvm-14/bin
27            pkgs: bmake libarchive-dev clang-14 lld-14
28          - os: macos-latest
29            compiler: clang-13
30            cross-bindir: /usr/local/opt/llvm@13/bin
31            pkgs: bmake libarchive llvm@13
32          - target_arch: amd64
33            target: amd64
34          - target_arch: aarch64
35            target: arm64
36    steps:
37      - uses: actions/checkout@v2
38      - name: install packages (Ubuntu)
39        if: runner.os == 'Linux'
40        run: |
41          sudo apt-get update --quiet || true
42          sudo apt-get -yq --no-install-suggests --no-install-recommends install ${{ matrix.pkgs }}
43      - name: install packages (macOS)
44        if: runner.os == 'macOS'
45        run: |
46          brew update --quiet || true
47          brew install ${{ matrix.pkgs }} || true
48      - name: create environment
49        run: |
50          echo "GITHUB_WORKSPACE = $GITHUB_WORKSPACE"
51          if [ -n "${{ matrix.cross-bindir }}" ]; then
52            echo "EXTRA_BUILD_ARGS=--cross-bindir=${{ matrix.cross-bindir }}" >> $GITHUB_ENV
53          fi
54          mkdir -p ../build
55          echo "MAKEOBJDIRPREFIX=${PWD%/*}/build" >> $GITHUB_ENV
56          # heh, works on Linux/BSD/macOS ...
57          echo "NPROC=`getconf _NPROCESSORS_ONLN 2>/dev/null || getconf NPROCESSORS_ONLN 2>/dev/null || echo 1`" >> $GITHUB_ENV
58      - name: bootstrap bmake
59        run: ./tools/build/make.py --debug $EXTRA_BUILD_ARGS TARGET=${{ matrix.target }} TARGET_ARCH=${{ matrix.target_arch }} -n
60      - name: make kernel-toolchain
61        run: ./tools/build/make.py --debug $EXTRA_BUILD_ARGS TARGET=${{ matrix.target }} TARGET_ARCH=${{ matrix.target_arch }} kernel-toolchain -s -j$NPROC
62      - name: make buildkernel
63        run: ./tools/build/make.py --debug $EXTRA_BUILD_ARGS TARGET=${{ matrix.target }} TARGET_ARCH=${{ matrix.target_arch }} KERNCONF=GENERIC NO_MODULES=yes buildkernel -s -j$NPROC $EXTRA_MAKE_ARGS
64