ci: rework Linux build scripts, allow crosscompiling with whatever is included in Ubuntu 20.04 (which is used on GitHub Actions now) repositories

This commit is contained in:
Alibek Omarov 2024-11-18 16:53:47 +03:00
parent fa272d9d93
commit bfb84a7ac4
5 changed files with 166 additions and 89 deletions

View file

@ -21,6 +21,22 @@ jobs:
- os: ubuntu-20.04 - os: ubuntu-20.04
targetos: linux targetos: linux
targetarch: i386 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 # - os: ubuntu-aarch64-20.04
# targetos: linux # targetos: linux
# targetarch: aarch64 # targetarch: aarch64
@ -52,6 +68,7 @@ jobs:
env: env:
SDL_VERSION: 2.30.3 SDL_VERSION: 2.30.3
GH_CPU_ARCH: ${{ matrix.targetarch }} GH_CPU_ARCH: ${{ matrix.targetarch }}
GH_CROSSCOMPILING: ${{ matrix.cross }}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4

View file

@ -2,46 +2,49 @@
. scripts/lib.sh . 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 APP=xash3d-fwgs
APPDIR=$APP.AppDir APPDIR=$APP.AppDir
APPIMAGE=$APP-$ARCH.AppImage 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 DS=xashds-linux
DSDIR=$DS-$ARCH DSDIR=$DS-$ARCH
DSTARGZ=$DS-$ARCH.tar.gz DSTARGZ=$DS-$ARCH.tar.gz
N=$(nproc)
build_sdl2() build_sdl2()
{ {
cd "$BUILDDIR"/SDL2_src || die 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 # a1ba: let's make something different. Rather than removing features
./configure \ # let's enable everything we can
--disable-render \ mkdir -p build || die
--disable-haptic \ pushd build || die
--disable-power \ cmake ../ -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$BUILDDIR"/SDL2_linux -DCMAKE_C_FLAGS=-O3 -DSDL_STATIC=OFF || die
--disable-filesystem \ ninja install -j$((N+1)) || die
--disable-file \ popd || die
--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=""
} }
build_engine() build_engine()
@ -53,10 +56,14 @@ build_engine()
AMD64="-8" AMD64="-8"
fi fi
if [ "$GH_CROSSCOMPILING" != "true" ]; then
ENABLE_TESTS="--enable-tests"
fi
if [ "$1" = "dedicated" ]; then 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 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 else
die die
fi fi
@ -64,57 +71,43 @@ build_engine()
./waf build || die_configure ./waf build || die_configure
} }
build_appimage() deploy_engine()
{ {
cd "$BUILDDIR" || die cd "$BUILDDIR" || die
./waf install --destdir="$APPDIR" || die ./waf install --destdir="$APPDIR" || die
cp SDL2_linux/lib/libSDL2-2.0.so.0 "$APPDIR/" 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/" cp 3rdparty/vgui_support/vgui-dev/lib/vgui.so "$APPDIR/"
fi fi
}
cat > "$APPDIR"/AppRun << 'EOF' build_appimage()
#!/bin/sh {
deploy_engine
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"
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" wget "https://raw.githubusercontent.com/FWGS/fwgs-artwork/master/xash3d/icon_512.png" -O "$APPDIR/$APP.png"
cat > "$APPDIR/$APP.desktop" <<EOF chmod +x "$APPDIR"/AppRun # Engine launcher & engine launcher script
[Desktop Entry] echo "Contents of AppImage: "
Name=xash3d-fwgs ls -R "$APPDIR"
Icon=xash3d-fwgs ./appimagetool.AppImage "$APPDIR" "artifacts/$APPIMAGE"
Type=Application }
Exec=AppRun
Categories=Game;
EOF
./appimagetool.AppImage "$APPDIR" "$APPIMAGE" build_engine_tarball()
{
deploy_engine
mv "$APPDIR" "$APPDIR2"
tar -czvf "artifacts/$APPTARGZ" "$APPDIR2"
} }
build_dedicated_tarball() build_dedicated_tarball()
{ {
cd "$BUILDDIR" || die cd "$BUILDDIR" || die
./waf install --destdir="$DSDIR" || die
./waf install --destdir=$DSDIR || die tar -czvf "artifacts/$DSTARGZ" "$DSDIR"
tar -czvf $DSTARGZ $DSDIR
} }
mkdir -p artifacts/ mkdir -p artifacts/
@ -122,9 +115,12 @@ mkdir -p artifacts/
rm -rf build # clean-up build directory rm -rf build # clean-up build directory
build_engine dedicated build_engine dedicated
build_dedicated_tarball build_dedicated_tarball
mv $DSTARGZ artifacts/
build_sdl2 build_sdl2
build_engine full # don't rebuild some common parts twice build_engine full # don't rebuild some common parts twice
if [ -x appimagetool.AppImage ]; then
build_appimage build_appimage
mv $APPIMAGE artifacts/ else
build_engine_tarball
fi

View file

@ -1,31 +1,74 @@
#!/bin/bash #!/bin/bash
cd $GITHUB_WORKSPACE . scripts/lib.sh
# TODO: add libpipewire-dev after we migrate from 20.04 cd "$GITHUB_WORKSPACE" || exit 1
if [ "$GH_CPU_ARCH" == "i386" ]; then # "booo, bash feature!", -- posix sh users, probably
sudo dpkg --add-architecture i386 declare -A BASE_BUILD_PACKAGES SDL_BUILD_PACKAGES APPIMAGETOOL
sudo apt update
sudo apt install gcc-multilib g++-multilib libx11-dev:i386 libxext-dev:i386 x11-utils libgl1-mesa-dev libasound-dev libstdc++6:i386 libfuse2:i386 zlib1g:i386 libpulse0:i386 libpulse-dev libjack-dev:i386 libwayland-dev:i386 libxkbcommon-dev:i386 wayland-scanner++
wget "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-i686.AppImage" -O appimagetool.AppImage # bzip2 and opus are added from submodules, freetype replaced by stb_truetype in this build, so it's just compiler toolchain
elif [ "$GH_CPU_ARCH" == "amd64" ]; then BASE_BUILD_PACKAGES[common]="desktop-file-utils"
sudo apt update BASE_BUILD_PACKAGES[amd64]="build-essential"
sudo apt install libx11-dev libxext-dev x11-utils libgl1-mesa-dev libasound-dev libstdc++6 libfuse2 zlib1g libpulse-dev libjack-dev libwayland-dev libxkbcommon-dev wayland-scanner++ BASE_BUILD_PACKAGES[i386]="gcc-multilib g++-multilib"
BASE_BUILD_PACKAGES[arm64]="crossbuild-essential-arm64"
BASE_BUILD_PACKAGES[armhf]="crossbuild-essential-armhf"
BASE_BUILD_PACKAGES[riscv64]="crossbuild-essential-riscv64"
BASE_BUILD_PACKAGES[ppc64el]="crossbuild-essential-ppc64el"
wget "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage" -O appimagetool.AppImage SDL_BUILD_PACKAGES[common]="cmake ninja-build"
elif [ "$GH_CPU_ARCH" == "aarch64" ]; then # TODO: add libpipewire-0.3-dev and libdecor-0-dev after we migrate from 20.04
sudo apt update # TODO: figure out how to install fcitx and ibus dev in cross compile environment on gha
sudo apt install libx11-dev libxext-dev x11-utils libgl1-mesa-dev libasound-dev libstdc++6 libfuse2 zlib1g libpulse-dev libjack-dev libwayland-dev libxkbcommon-dev wayland-scanner++ # In theory, we better run this in limited container. Right now, some preinstalled PHP shit breaks libpcre builds
# and prevents us from installing crosscompiling packages
SDL_BUILD_PACKAGES[amd64]="libasound2-dev libpulse-dev \
libaudio-dev libjack-dev libsndio-dev libsamplerate0-dev libx11-dev libxext-dev \
libxrandr-dev libxcursor-dev libxfixes-dev libxi-dev libxss-dev libwayland-dev \
libxkbcommon-dev libdrm-dev libgbm-dev libgl1-mesa-dev libgles2-mesa-dev \
libegl1-mesa-dev libdbus-1-dev libudev-dev"
SDL_BUILD_PACKAGES[i386]="${SDL_BUILD_PACKAGES[amd64]//-dev/-dev:i386} libjack0:i386" # test
SDL_BUILD_PACKAGES[arm64]=${SDL_BUILD_PACKAGES[amd64]//-dev/-dev:arm64}
SDL_BUILD_PACKAGES[armhf]=${SDL_BUILD_PACKAGES[amd64]//-dev/-dev:armhf}
SDL_BUILD_PACKAGES[riscv64]=${SDL_BUILD_PACKAGES[amd64]//-dev/-dev:riscv64}
SDL_BUILD_PACKAGES[ppc64el]=${SDL_BUILD_PACKAGES[amd64]//-dev/-dev:ppc64el}
wget "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-aarch64.AppImage" -O appimagetool.AppImage APPIMAGETOOL[amd64]=https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage
else APPIMAGETOOL[i386]=https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-i686.AppImage
exit 1
# can't run AppImageTool yet because it's compiled for these platforms natively and don't support cross compilation yet
# uncomment when we will enable qemu-user for tests
# APPIMAGETOOL[arm64]=https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-aarch64.AppImage
# APPIMAGETOOL[armhf]=https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-armhf.AppImage
regenerate_sources_list()
{
# this is evil but to speed up update, specify all repositories manually
sudo rm /etc/apt/sources.list
sudo rm -rf /etc/apt/sources.list.d
for i in focal focal-updates focal-backports focal-security; do
echo "deb [arch=$GH_CPU_ARCH] http://azure.ports.ubuntu.com/ubuntu-ports $i main universe" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=amd64] http://azure.archive.ubuntu.com/ubuntu $i main universe" | sudo tee -a /etc/apt/sources.list
done
}
if [ "$GH_CPU_ARCH" != "amd64" ] && [ -n "$GH_CPU_ARCH" ]; then
if [ "$GH_CPU_ARCH" != "i386" ]; then
regenerate_sources_list
fi
sudo dpkg --add-architecture "$GH_CPU_ARCH"
fi fi
chmod +x appimagetool.AppImage sudo apt update || die
sudo apt install aptitude || die # aptitude is just more reliable at resolving dependencies
wget http://libsdl.org/release/SDL2-$SDL_VERSION.zip -O SDL2.zip # shellcheck disable=SC2086 # splitting is intended here
unzip -q SDL2.zip sudo aptitude install -y ${BASE_BUILD_PACKAGES[common]} ${BASE_BUILD_PACKAGES[$GH_CPU_ARCH]} ${SDL_BUILD_PACKAGES[common]} ${SDL_BUILD_PACKAGES[$GH_CPU_ARCH]} || die
mv SDL2-$SDL_VERSION SDL2_src
if [ -n "${APPIMAGETOOL[$GH_CPU_ARCH]}" ]; then
wget -O appimagetool.AppImage "${APPIMAGETOOL[$GH_CPU_ARCH]}"
chmod +x appimagetool.AppImage
fi
wget "https://github.com/libsdl-org/SDL/releases/download/release-$SDL_VERSION/SDL2-$SDL_VERSION.tar.gz" -qO- | tar -xzf -
mv "SDL2-$SDL_VERSION" SDL2_src

10
scripts/gha/linux/AppRun Normal file
View file

@ -0,0 +1,10 @@
#!/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"
exec $DEBUGGER "${APPDIR}/xash3d" "$@"

View file

@ -0,0 +1,11 @@
[Desktop Entry]
Categories=Game;Shooter;
Comment=Half-Life compatible game engine
Exec=AppRun
Icon=xash3d-fwgs
Keywords=first;person;shooter;multiplayer;half-life;halflife;singleplayer;
Name=Xash3D FWGS
# Doesn't pass validation with old desktop-file-utils
#PrefersNonDefaultGPU=true
Terminal=false
Type=Application