From bfb84a7ac4b33529bc3c715bdb508e62416120e6 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 18 Nov 2024 16:53:47 +0300 Subject: [PATCH] ci: rework Linux build scripts, allow crosscompiling with whatever is included in Ubuntu 20.04 (which is used on GitHub Actions now) repositories --- .github/workflows/c-cpp.yml | 17 ++++ scripts/gha/build_linux.sh | 132 +++++++++++++------------- scripts/gha/deps_linux.sh | 85 +++++++++++++---- scripts/gha/linux/AppRun | 10 ++ scripts/gha/linux/xash3d-fwgs.desktop | 11 +++ 5 files changed, 166 insertions(+), 89 deletions(-) create mode 100644 scripts/gha/linux/AppRun create mode 100644 scripts/gha/linux/xash3d-fwgs.desktop diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 921f68e7..94e8ae2f 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -21,6 +21,22 @@ jobs: - os: ubuntu-20.04 targetos: linux targetarch: i386 + - os: ubuntu-20.04 + targetos: linux + targetarch: arm64 + cross: true + - os: ubuntu-20.04 + targetos: linux + targetarch: armhf + cross: true + - os: ubuntu-20.04 + targetos: linux + targetarch: riscv64 + cross: true + - os: ubuntu-20.04 + targetos: linux + targetarch: ppc64el + cross: true # - os: ubuntu-aarch64-20.04 # targetos: linux # targetarch: aarch64 @@ -52,6 +68,7 @@ jobs: env: SDL_VERSION: 2.30.3 GH_CPU_ARCH: ${{ matrix.targetarch }} + GH_CROSSCOMPILING: ${{ matrix.cross }} steps: - name: Checkout uses: actions/checkout@v4 diff --git a/scripts/gha/build_linux.sh b/scripts/gha/build_linux.sh index 75152d56..3c14f065 100755 --- a/scripts/gha/build_linux.sh +++ b/scripts/gha/build_linux.sh @@ -2,46 +2,49 @@ . scripts/lib.sh +# "booo, bash feature!" +declare -A ARCH_TRIPLET CROSS_COMPILE_CC CROSS_COMPILE_CXX +ARCH_TRIPLET[amd64]=x86_64-linux-gnu +ARCH_TRIPLET[i386]=i386-linux-gnu +ARCH_TRIPLET[arm64]=aarch64-linux-gnu +ARCH_TRIPLET[armhf]=arm-linux-gnueabihf +ARCH_TRIPLET[riscv64]=riscv64-linux-gnu +ARCH_TRIPLET[ppc64el]=powerpc64le-linux-gnu +CROSS_COMPILE_CC[amd64]=cc +CROSS_COMPILE_CC[i386]="cc -m32" +CROSS_COMPILE_CXX[amd64]=c++ +CROSS_COMPILE_CXX[i386]="c++ -m32" +for i in arm64 armhf riscv64 ppc64el; do + CROSS_COMPILE_CC[$i]=${ARCH_TRIPLET[$i]}-gcc + CROSS_COMPILE_CXX[$i]=${ARCH_TRIPLET[$i]}-g++ +done +export PKG_CONFIG_PATH=${ARCH_TRIPLET[$GH_CPU_ARCH]} +export CC=${CROSS_COMPILE_CC[$GH_CPU_ARCH]} +export CXX=${CROSS_COMPILE_CXX[$GH_CPU_ARCH]} + APP=xash3d-fwgs APPDIR=$APP.AppDir APPIMAGE=$APP-$ARCH.AppImage +APPDIR2=$APP-linux-$ARCH # FIXME: not conforms to libpublic's build arch strings but in parity with xashds directory name +APPTARGZ=$APP-linux-$ARCH.tar.gz + DS=xashds-linux DSDIR=$DS-$ARCH DSTARGZ=$DS-$ARCH.tar.gz +N=$(nproc) build_sdl2() { cd "$BUILDDIR"/SDL2_src || die - if [ "$ARCH" = "i386" ]; then - export CFLAGS="-msse2 -march=i686 -m32 -ggdb -O2" - export LDFLAGS="-m32" - export PKG_CONFIG_PATH="/usr/lib/i386-linux-gnu/pkgconfig" - fi - # TODO: enable pipewire after we migrate from 20.04 - ./configure \ - --disable-render \ - --disable-haptic \ - --disable-power \ - --disable-filesystem \ - --disable-file \ - --disable-libudev \ - --disable-dbus \ - --disable-ibus \ - --disable-ime \ - --disable-fcitx \ - --enable-alsa-shared \ - --enable-jack-shared \ - --enable-pulseaudio-shared \ - --enable-wayland-shared \ - --enable-x11-shared \ - --prefix / || die # get rid of /usr/local stuff - make -j2 || die - mkdir -p "$BUILDDIR"/SDL2_linux - make install DESTDIR="$BUILDDIR"/SDL2_linux || die - export CFLAGS="" - export LDFLAGS="" + # a1ba: let's make something different. Rather than removing features + # let's enable everything we can + mkdir -p build || die + pushd build || die + cmake ../ -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$BUILDDIR"/SDL2_linux -DCMAKE_C_FLAGS=-O3 -DSDL_STATIC=OFF || die + ninja install -j$((N+1)) || die + popd || die } build_engine() @@ -53,10 +56,14 @@ build_engine() AMD64="-8" fi + if [ "$GH_CROSSCOMPILING" != "true" ]; then + ENABLE_TESTS="--enable-tests" + fi + if [ "$1" = "dedicated" ]; then - ./waf configure -T release -d $AMD64 --enable-tests --enable-lto --enable-bundled-deps || die_configure + ./waf configure $AMD64 $ENABLE_TESTS --enable-lto --enable-bundled-deps -d || die_configure elif [ "$1" = "full" ]; then - ./waf configure --sdl2=SDL2_linux -T release --enable-stb $AMD64 --enable-utils --enable-tests --enable-lto --enable-bundled-deps || die_configure + ./waf configure $AMD64 $ENABLE_TESTS --enable-lto --enable-bundled-deps -s SDL2_linux --enable-stb --enable-utils || die_configure else die fi @@ -64,57 +71,43 @@ build_engine() ./waf build || die_configure } -build_appimage() +deploy_engine() { cd "$BUILDDIR" || die - ./waf install --destdir="$APPDIR" || die - cp SDL2_linux/lib/libSDL2-2.0.so.0 "$APPDIR/" - if [ "$ARCH" = "i386" ]; then + if [ "$GH_CPU_ARCH" = "i386" ]; then cp 3rdparty/vgui_support/vgui-dev/lib/vgui.so "$APPDIR/" fi +} - cat > "$APPDIR"/AppRun << 'EOF' -#!/bin/sh - -if [ "$XASH3D_BASEDIR" = "" ]; then - export XASH3D_BASEDIR=$PWD -fi -echo "Xash3D FWGS installed as AppImage." -echo "Base directory is $XASH3D_BASEDIR. Set XASH3D_BASEDIR environment variable to override this" - -export XASH3D_EXTRAS_PAK1="${APPDIR}"/valve/extras.pk3 -${DEBUGGER} "${APPDIR}"/xash3d "$@" -exit $? -EOF - - chmod +x "$APPDIR"/xash3d "$APPDIR"/AppRun # Engine launcher & engine launcher script - - echo "Contents of AppImage: " - ls -R "$APPDIR" +build_appimage() +{ + deploy_engine + cp scripts/gha/linux/AppRun "$APPDIR/AppRun" + cp scripts/gha/linux/xash3d-fwgs.desktop "$APPDIR/$APP.desktop" wget "https://raw.githubusercontent.com/FWGS/fwgs-artwork/master/xash3d/icon_512.png" -O "$APPDIR/$APP.png" - cat > "$APPDIR/$APP.desktop" <