Files @ r28356:5479dee3539c
Branch filter:

Location: cpp/openttd-patchpack/source/.github/workflows/release-linux.yml

Patric Stout
Fix: [CI] patch in SHF_COMPRESSED symbol for our Linux Generic binaries (#11651)
name: Release (Linux)

on:
  workflow_call:
    inputs:
      survey_key:
        required: false
        type: string
        default: ""

jobs:
  linux:
    name: Linux (Generic)

    runs-on: ubuntu-20.04
    container:
      # manylinux2014 is based on CentOS 7, but already has a lot of things
      # installed and preconfigured. It makes it easier to build OpenTTD.
      image: quay.io/pypa/manylinux2014_x86_64
      volumes:
      - /usr/local/share/vcpkg:/vcpkg
      env:
        ImageOS: ${{ env.ImageOS }}
        ImageVersion: ${{ env.ImageVersion }}

    steps:
    - name: Download source
      uses: actions/download-artifact@v3
      with:
        name: internal-source

    - name: Unpack source
      run: |
        tar -xf source.tar.gz --strip-components=1

    # dtolnay/rust-toolchain uses a curl argument (--retry-connrefused) that the curl shipped with our container doesn't support.
    # So we need to do one part ourselves; the action takes over the rest and prepares the setup further.
    - name: Prepare Rust toolchain
      run: |
        curl --proto '=https' --tlsv1.2 --retry 10 --location --silent --show-error --fail "https://sh.rustup.rs" | sh -s -- --default-toolchain none -y
        echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH

    - name: Install Rust toolchain
      uses: dtolnay/rust-toolchain@stable

    - name: Enable Rust cache
      uses: Swatinem/rust-cache@v2

    - name: Prepare cache key
      id: key
      run: |
        echo "image=$ImageOS-$ImageVersion" >> $GITHUB_OUTPUT

    - name: Enable vcpkg cache
      uses: actions/cache@v3
      with:
        path: /vcpkg/installed
        key: ${{ steps.key.outputs.image }}-vcpkg-release-1 # Increase the number whenever dependencies are modified
        restore-keys: |
          ${{ steps.key.outputs.image }}-vcpkg-release

    - name: Install dependencies
      run: |
        echo "::group::Install system dependencies"
        # perl-IPC-Cmd, wget, and zip are needed to run vcpkg.
        # autoconf-archive is needed to build ICU.
        yum install -y \
          autoconf-archive \
          perl-IPC-Cmd \
          wget \
          zip \
          # EOF

        # aclocal looks first in /usr/local/share/aclocal, and if that doesn't
        # exist only looks in /usr/share/aclocal. We have files in both that
        # are important. So copy the latter to the first, and we are good to
        # go.
        cp /usr/share/aclocal/* /usr/local/share/aclocal/
        echo "::endgroup::"

        # The yum variant of fluidsynth depends on all possible audio drivers,
        # like jack, ALSA, pulseaudio, etc. This is not really useful for us,
        # as we route the output of fluidsynth back via our sound driver, and
        # as such do not use these audio driver outputs at all.
        # The vcpkg variant of fluidsynth depends on ALSA. Similar issue here.
        # So instead, we compile fluidsynth ourselves, with as few
        # dependencies as possible. We do it before anything else is installed,
        # to make sure it doesn't pick up on any of the drivers.
        echo "::group::Install fluidsynth"
        wget https://github.com/FluidSynth/fluidsynth/archive/v2.3.3.tar.gz
        tar xf v2.3.3.tar.gz
        (
          cd fluidsynth-2.3.3
          mkdir build
          cd build
          cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/usr
          cmake --build . -j $(nproc)
          cmake --install .
        )

        # The container we use is old enough, that it doesn't know SHF_COMPRESSED.
        # But, breakpad needs this symbol to exist. So we patch it in our system
        # libraries.
        (
          cd /
          patch -p1 < ${GITHUB_WORKSPACE}/os/linux/shf-compressed.patch
        )
        echo "::endgroup::"

        echo "::group::Install audio drivers"
        # These audio libs are to make sure the SDL version of vcpkg adds
        # sound-support; these libraries are not added to the resulting
        # binary, but the headers are used to enable them in SDL.
        yum install -y \
          alsa-lib-devel \
          jack-audio-connection-kit-devel \
          pulseaudio-libs-devel \
          # EOF
        echo "::endgroup::"

        # We use vcpkg for our dependencies, to get more up-to-date version.
        echo "::group::Install vcpkg and dependencies"

        # Make Python3 available for other packages.
        /vcpkg/vcpkg install python3
        ln -sf /vcpkg/installed/x64-linux/tools/python3/python3.[0-9][0-9] /usr/bin/python3

        # SDL2 needs dbus, but dbus default install comes with libsystemd
        # and some of libsystemd deps fail to build on our quite old linux.
        # So just install basic dbus without any extra deps.
        /vcpkg/vcpkg install dbus[core]

        # Now we can install OpenTTD dependencies
        /vcpkg/vcpkg install \
          breakpad \
          curl[http2] \
          fontconfig \
          freetype \
          harfbuzz \
          icu \
          liblzma \
          libpng \
          lzo \
          sdl2 \
          zlib \
          # EOF
        echo "::endgroup::"

        echo "::group::Install breakpad dependencies"
        cargo install dump_syms
        echo "::endgroup::"

    - name: Install GCC problem matcher
      uses: ammaraskar/gcc-problem-matcher@master

    - name: Build
      run: |
        mkdir -p build
        cd build

        echo "::group::CMake"
        cmake ${GITHUB_WORKSPACE} \
          -DCMAKE_TOOLCHAIN_FILE=/vcpkg/scripts/buildsystems/vcpkg.cmake \
          -DCMAKE_BUILD_TYPE=RelWithDebInfo \
          -DOPTION_SURVEY_KEY=${{ inputs.survey_key }} \
          -DOPTION_PACKAGE_DEPENDENCIES=ON \
          # EOF
        echo "::endgroup::"

        echo "::group::Build"
        echo "Running on $(nproc) cores"
        cmake --build . -j $(nproc) --target openttd
        echo "::endgroup::"

    - name: Create breakpad symbols
      run: |
        cd build
        dump_syms ./openttd --inlines --store symbols

    - name: Create bundles
      run: |
        cd ${GITHUB_WORKSPACE}/build
        echo "::group::Run CPack"
        cpack
        echo "::endgroup::"

        echo "::group::Cleanup"
        # Remove the sha256 files CPack generates; we will do this ourself at
        # the end of this workflow.
        rm -f bundles/*.sha256
        echo "::endgroup::"

    - name: Store bundles
      uses: actions/upload-artifact@v3
      with:
        name: openttd-linux-generic
        path: build/bundles
        retention-days: 5

    - name: Store symbols
      uses: actions/upload-artifact@v3
      with:
        name: symbols-linux-generic
        path: build/symbols
        retention-days: 5