summaryrefslogtreecommitdiff
path: root/.github/workflows/test-builds-on-distros.yml
blob: c509a59a572e02af912f74522ab1705078df25dc (plain)
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
name: test-builds-on-distros
on:
  workflow_dispatch:    # by request
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
jobs:
  setup:
    runs-on: ubuntu-latest
    outputs:
      distros: ${{ steps.set-matrix.outputs.distros }}
    steps:
    - name: Resolve distro images
      id: set-matrix
      uses: actions/github-script@v9
      with:
        script: |
          const today = new Date().toISOString().slice(0, 10);
          const fetchJson = async (url) => {
            const res = await fetch(url);
            if (!res.ok) throw new Error(`${url} -> ${res.status}`);
            return res.json();
          };

          // All non-EOL Ubuntu LTS releases.
          const ubuntuCycles = await fetchJson('https://endoflife.date/api/ubuntu.json');
          const ubuntu = ubuntuCycles
            .filter(c => c.lts === true && c.eol > today)
            .map(c => ({ image: `ubuntu:${c.cycle}`, packageManager: 'apt' }));

          // All non-EOL Fedora releases.
          const fedoraCycles = await fetchJson('https://endoflife.date/api/fedora.json');
          const fedora = fedoraCycles
            .filter(c => c.eol > today)
            .map(c => ({ image: `fedora:${c.cycle}`, packageManager: 'dnf' }));

          // Rolling.
          const arch = [{ image: 'archlinux:base', packageManager: 'pacman' }];

          // Rolling Tumbleweed and all non-EOL Leap releases.
          const leapCycles = await fetchJson('https://endoflife.date/api/opensuse.json');
          const opensuse = [
            { image: 'opensuse/tumbleweed:latest', packageManager: 'zypper' },
            ...leapCycles
              .filter(c => c.eol > today)
              .map(c => ({ image: `opensuse/leap:${c.cycle}`, packageManager: 'zypper' })),
          ];

          // Previous, current, and next Debian releases.
          const debian = ['oldstable', 'stable', 'testing']
            .map(t => ({ image: `debian:${t}`, packageManager: 'apt' }));

          const distros = [...ubuntu, ...fedora, ...arch, ...opensuse, ...debian];
          core.info(`Resolved distros: ${JSON.stringify(distros)}`);
          core.setOutput('distros', JSON.stringify(distros));
  build:
    needs: setup
    name: build (${{ matrix.distro.image }}, ${{ matrix.cc }})
    strategy:
      fail-fast: false
      matrix:
        distro: ${{ fromJSON(needs.setup.outputs.distros) }}
        cc: ["gcc", "clang"]
        include:
        - cxx: g++
          cc: gcc
        - cxx: clang++
          cc: clang
    runs-on: ubuntu-latest
    container:
      image: ${{ matrix.distro.image }}
    steps:
    - name: Bootstrap git
      run: |
        case "${{ matrix.distro.packageManager }}" in
          apt)    apt-get update && apt-get -y install git ;;
          dnf)    dnf -y install git ;;
          pacman) pacman -Sy --noconfirm git ;;
          zypper) zypper --non-interactive in git ;;
        esac
    - uses: actions/checkout@v7
      with:
        submodules: true
    - name: Install dependencies (pacman)
      if: ${{ matrix.distro.packageManager == 'pacman' }}
      run: |
        pacman -Syu --noconfirm
        pacman -S --noconfirm ${{ matrix.cc }} $(cat linux-build-deps/pacman.txt)
    - name: Install dependencies (dnf)
      if: ${{ matrix.distro.packageManager == 'dnf' }}
      run: |
        dnf -y upgrade
        dnf -y install ${{ matrix.cc }} ${{ (matrix.cxx == 'g++' && 'gcc-c++') || '' }} $(cat linux-build-deps/dnf.txt)
    - name: Install dependencies (apt)
      if: ${{ matrix.distro.packageManager == 'apt' }}
      run: |
        apt-get update
        apt-get -y full-upgrade
        apt-get -y install ${{ matrix.cc }} ${{ (matrix.cxx == 'g++' && 'g++') || '' }} $(cat linux-build-deps/apt.txt)
    - name: Install dependencies (zypper)
      if: ${{ matrix.distro.packageManager == 'zypper' }}
      run: |
        zypper --non-interactive dup
        zypper --non-interactive in ${{ matrix.cc }} ${{ (matrix.cxx == 'g++' && 'gcc-c++') || '' }} ${{ matrix.cc == 'clang' && 'libstdc++-devel' || '' }} $(cat linux-build-deps/zypper.txt)
    - name: Verify compiler version
      id: verify-compiler
      uses: ./.github/actions/verify-compiler
      with:
        compiler: ${{ matrix.cc }}
        packageManager: ${{ matrix.distro.packageManager }}
    - name: Install newer compiler
      if: ${{ steps.verify-compiler.outputs.needs_install == 'true' }}
      uses: ./.github/actions/install-newer-compiler
      with:
        compiler: ${{ matrix.cc }}
        version: ${{ steps.verify-compiler.outputs.version }}
        available_in_distro: ${{ steps.verify-compiler.outputs.available_in_distro }}
        packageManager: ${{ matrix.distro.packageManager }}
    - name: Verify/update cmake
      run: |
        ver_le() { [ "$(printf '%s\n%s\n' "$1" "$2" | sort -V | head -1)" = "$1" ]; }
        required=$(grep -m1 -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' CMakeLists.txt)
        installed=$(cmake --version | grep -m1 -oE '[0-9]+\.[0-9]+(\.[0-9]+)?')
        echo "cmake required: $required  installed: $installed"
        if ver_le "$required" "$installed"; then
          echo "ok"
        else
          case "${{ matrix.distro.packageManager }}" in
            apt)    DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends pipx ;;
            dnf)    dnf -y install pipx ;;
            pacman) pacman -S --noconfirm python-pipx ;;
            zypper) zypper --non-interactive in python3-pipx ;;
          esac
          pipx install cmake
          echo "$HOME/.local/bin" >> "$GITHUB_PATH"
        fi
    - name: Verify/update tinyxml2
      id: tinyxml2-check
      if: ${{ matrix.distro.packageManager == 'apt' }}
      run: |
        if find /usr -iname 'tinyxml2*config.cmake' 2>/dev/null | grep -q .; then
          echo "ok"
          echo "needs_install=false" >> "$GITHUB_OUTPUT"
        else
          apt-get remove -y libtinyxml2-dev
          apt-get install -y curl
          echo "needs_install=true" >> "$GITHUB_OUTPUT"
        fi
    - uses: ./.github/actions/install-tinyxml2
      if: ${{ steps.tinyxml2-check.outputs.needs_install == 'true' }}
    - name: Verify/update SDL2_net
      id: sdl2-net-check
      if: ${{ matrix.distro.packageManager == 'apt' }}
      run: |
        if find /usr -iname 'sdl2_net*config.cmake' 2>/dev/null | grep -q .; then
          echo "ok"
          echo "needs_install=false" >> "$GITHUB_OUTPUT"
        else
          apt-get install -y curl
          echo "needs_install=true" >> "$GITHUB_OUTPUT"
        fi
    - uses: ./.github/actions/install-sdl2-net
      if: ${{ steps.sdl2-net-check.outputs.needs_install == 'true' }}
    # https://github.com/fmtlib/fmt/issues/4807
    - name: Check fmt/clang consteval compat
      id: fmt-check
      shell: bash
      run: |
        cat > /tmp/fmt-consteval-test.cpp <<'EOF'
        #include <fmt/format.h>
        int main() { auto s = fmt::format(FMT_STRING("{}"), 42); return 0; }
        EOF
        if "$CXX" -std=c++20 -c /tmp/fmt-consteval-test.cpp -o /tmp/fmt-consteval-test.o; then
          echo "ok — fmt/clang consteval compatible"
          echo "needs_workaround=false" >> "$GITHUB_OUTPUT"
        else
          echo "incompatible — applying workaround"
          echo "needs_workaround=true" >> "$GITHUB_OUTPUT"
        fi
      env:
        CXX: ${{ steps.verify-compiler.outputs.cxx }}
    - name: Build SoH
      run: |
        export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
        cmake --no-warn-unused-cli -H. -Bbuild-cmake -GNinja -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_REMOTE_CONTROL=1 ${EXTRA_CMAKE_FLAGS}
        cmake --build build-cmake --config Release -j3
      env:
        CC: ${{ steps.verify-compiler.outputs.cc }}
        CXX: ${{ steps.verify-compiler.outputs.cxx }}
        # https://github.com/fmtlib/fmt/issues/4807
        EXTRA_CMAKE_FLAGS: ${{ steps.fmt-check.outputs.needs_workaround == 'true' && '-DCMAKE_CXX_FLAGS=-DFMT_CONSTEVAL=constexpr' || '' }}
  build-nix:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v7
      with:
        submodules: true
    - uses: cachix/install-nix-action@v31
    - name: Build SoH in nix dev shell
      run: |
        nix develop ./linux-build-deps -c bash -c '
          cmake --no-warn-unused-cli -H. -Bbuild-cmake -GNinja -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_REMOTE_CONTROL=1
          cmake --build build-cmake --config Release -j3
        '