Upload
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
# Cross-compiling build environment for betterserver.
|
||||
# Runs on any x86_64 Docker host and produces every supported target:
|
||||
#
|
||||
# Windows x64 / x86 mingw-w64 (GCC)
|
||||
# Windows arm64 / arm llvm-mingw (Clang; Debian's mingw has no ARM)
|
||||
# Linux x64 / x86 GCC
|
||||
# Linux arm64 / arm GCC cross toolchains
|
||||
#
|
||||
# Every shipped binary is statically linked, so nothing has to be installed on
|
||||
# the machines that run them.
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
build-essential \
|
||||
cmake \
|
||||
ninja-build \
|
||||
mingw-w64 \
|
||||
crossbuild-essential-arm64 \
|
||||
crossbuild-essential-armhf \
|
||||
crossbuild-essential-i386 \
|
||||
ca-certificates \
|
||||
curl \
|
||||
xz-utils \
|
||||
file \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# mingw's default "win32" thread model has no pthreads and no C11 <threads.h>.
|
||||
# The posix variant provides both, which this codebase needs.
|
||||
RUN for p in x86_64-w64-mingw32 i686-w64-mingw32; do \
|
||||
update-alternatives --set $p-gcc /usr/bin/$p-gcc-posix; \
|
||||
update-alternatives --set $p-g++ /usr/bin/$p-g++-posix; \
|
||||
done
|
||||
|
||||
# llvm-mingw adds the aarch64/armv7 Windows targets that mingw-w64 lacks.
|
||||
# Pinned so the image is reproducible.
|
||||
ARG LLVM_MINGW_VERSION=20260922
|
||||
RUN curl -fsSL -o /tmp/llvm-mingw.tar.xz \
|
||||
"https://github.com/mstorsjo/llvm-mingw/releases/download/${LLVM_MINGW_VERSION}/llvm-mingw-${LLVM_MINGW_VERSION}-ucrt-ubuntu-22.04-x86_64.tar.xz" \
|
||||
&& mkdir -p /opt/llvm-mingw \
|
||||
&& tar -xf /tmp/llvm-mingw.tar.xz -C /opt/llvm-mingw --strip-components=1 \
|
||||
&& rm /tmp/llvm-mingw.tar.xz
|
||||
|
||||
ENV PATH="/opt/llvm-mingw/bin:${PATH}"
|
||||
|
||||
WORKDIR /src
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env bash
|
||||
# Runs INSIDE the betterserver-build container.
|
||||
# Builds the requested targets from /src and drops the artifacts in /out.
|
||||
set -euo pipefail
|
||||
|
||||
SRC=/src
|
||||
OUT=/out
|
||||
BUILD_TYPE="${BUILD_TYPE:-Release}"
|
||||
JOBS="$(nproc)"
|
||||
|
||||
ALL_TARGETS=(windows-x64 windows-x86 windows-arm64 windows-arm
|
||||
linux-x64 linux-x86 linux-arm64 linux-arm)
|
||||
|
||||
targets=("$@")
|
||||
if [ ${#targets[@]} -eq 0 ]; then
|
||||
targets=(windows-x64 linux-arm64)
|
||||
fi
|
||||
|
||||
# "all" anywhere in the list expands to every target.
|
||||
expanded=()
|
||||
for t in "${targets[@]}"; do
|
||||
if [ "$t" = "all" ]; then
|
||||
expanded+=("${ALL_TARGETS[@]}")
|
||||
else
|
||||
expanded+=("$t")
|
||||
fi
|
||||
done
|
||||
targets=("${expanded[@]}")
|
||||
|
||||
failed=()
|
||||
|
||||
build_one() {
|
||||
local name="$1" toolchain="$2" artifact="$3" outname="$4"
|
||||
shift 4
|
||||
local extra=("$@")
|
||||
local dir="/build/$name"
|
||||
|
||||
echo ""
|
||||
echo "=============================================================="
|
||||
echo " Building $name ($BUILD_TYPE)"
|
||||
echo "=============================================================="
|
||||
|
||||
mkdir -p /build
|
||||
rm -rf "$dir"
|
||||
if ! cmake -S "$SRC" -B "$dir" -G Ninja \
|
||||
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
|
||||
${toolchain:+-DCMAKE_TOOLCHAIN_FILE="$toolchain"} \
|
||||
-DBUILD_UI=OFF \
|
||||
-DDYLIB=OFF \
|
||||
"${extra[@]}" \
|
||||
> "$dir.log" 2>&1
|
||||
then
|
||||
echo " CONFIGURE FAILED:"
|
||||
tail -25 "$dir.log" | sed 's/^/ /'
|
||||
failed+=("$name")
|
||||
return 0
|
||||
fi
|
||||
|
||||
if ! cmake --build "$dir" -j "$JOBS" >> "$dir.log" 2>&1; then
|
||||
echo " BUILD FAILED:"
|
||||
grep -E "error|FAILED" "$dir.log" | head -15 | sed 's/^/ /'
|
||||
failed+=("$name")
|
||||
return 0
|
||||
fi
|
||||
|
||||
mkdir -p "$OUT"
|
||||
cp "$dir/disasterserver/$artifact" "$OUT/$outname"
|
||||
echo " -> $outname"
|
||||
file -b "$OUT/$outname" | cut -c1-96 | sed 's/^/ /'
|
||||
}
|
||||
|
||||
for t in "${targets[@]}"; do
|
||||
case "$t" in
|
||||
windows-x64)
|
||||
build_one "$t" "$SRC/docker/toolchain-mingw64.cmake" \
|
||||
DisasterServer.exe betterserver-windows-x64.exe ;;
|
||||
windows-x86)
|
||||
build_one "$t" "$SRC/docker/toolchain-mingw32.cmake" \
|
||||
DisasterServer.exe betterserver-windows-x86.exe ;;
|
||||
windows-arm64)
|
||||
build_one "$t" "$SRC/docker/toolchain-mingw-arm64.cmake" \
|
||||
DisasterServer.exe betterserver-windows-arm64.exe ;;
|
||||
windows-arm)
|
||||
build_one "$t" "$SRC/docker/toolchain-mingw-armv7.cmake" \
|
||||
DisasterServer.exe betterserver-windows-arm.exe ;;
|
||||
linux-x64)
|
||||
build_one "$t" "" \
|
||||
DisasterServer betterserver-linux-x64 \
|
||||
"-DCMAKE_EXE_LINKER_FLAGS=-static" ;;
|
||||
linux-x86)
|
||||
build_one "$t" "$SRC/docker/toolchain-i686-linux.cmake" \
|
||||
DisasterServer betterserver-linux-x86 ;;
|
||||
linux-arm64)
|
||||
build_one "$t" "$SRC/docker/toolchain-aarch64.cmake" \
|
||||
DisasterServer betterserver-linux-arm64 ;;
|
||||
linux-arm)
|
||||
build_one "$t" "$SRC/docker/toolchain-armhf.cmake" \
|
||||
DisasterServer betterserver-linux-arm ;;
|
||||
*)
|
||||
echo "Unknown target: $t" >&2
|
||||
echo "Valid: ${ALL_TARGETS[*]} all" >&2
|
||||
exit 2 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "=============================================================="
|
||||
echo " Done. Artifacts in dist/:"
|
||||
echo "=============================================================="
|
||||
ls -lh "$OUT" 2>/dev/null | tail -n +2 | awk '{printf " %-38s %s\n", $9, $5}'
|
||||
|
||||
if [ ${#failed[@]} -gt 0 ]; then
|
||||
echo ""
|
||||
echo " FAILED TARGETS: ${failed[*]}"
|
||||
exit 1
|
||||
fi
|
||||
@@ -0,0 +1,17 @@
|
||||
# Cross-compile to Linux aarch64 (ARM64).
|
||||
# Links statically so the result runs on any ARM64 distro regardless of its
|
||||
# glibc version. This is safe here because the server never resolves hostnames
|
||||
# (it binds ENET_HOST_ANY), so it does not need glibc's dynamic NSS plugins.
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(CMAKE_SYSTEM_PROCESSOR aarch64)
|
||||
|
||||
set(TOOLCHAIN_PREFIX aarch64-linux-gnu)
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS_INIT "-static")
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
@@ -0,0 +1,16 @@
|
||||
# Cross-compile to Linux ARM 32-bit (armv7 hard-float).
|
||||
# Static, like the other Linux targets: the server never resolves hostnames,
|
||||
# so it does not need glibc's dynamic NSS plugins.
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(CMAKE_SYSTEM_PROCESSOR arm)
|
||||
|
||||
set(TOOLCHAIN_PREFIX arm-linux-gnueabihf)
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS_INIT "-static")
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
@@ -0,0 +1,14 @@
|
||||
# Cross-compile to Linux x86 32-bit.
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(CMAKE_SYSTEM_PROCESSOR i686)
|
||||
|
||||
set(TOOLCHAIN_PREFIX i686-linux-gnu)
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS_INIT "-static")
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
@@ -0,0 +1,17 @@
|
||||
# Cross-compile to Windows ARM64 with llvm-mingw (clang + lld).
|
||||
# Debian's gcc mingw-w64 only targets x86, so ARM Windows uses llvm-mingw.
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(CMAKE_SYSTEM_PROCESSOR aarch64)
|
||||
|
||||
set(TOOLCHAIN_PREFIX aarch64-w64-mingw32)
|
||||
set(LLVM_MINGW /opt/llvm-mingw)
|
||||
set(CMAKE_C_COMPILER ${LLVM_MINGW}/bin/${TOOLCHAIN_PREFIX}-clang)
|
||||
set(CMAKE_CXX_COMPILER ${LLVM_MINGW}/bin/${TOOLCHAIN_PREFIX}-clang++)
|
||||
set(CMAKE_RC_COMPILER ${LLVM_MINGW}/bin/${TOOLCHAIN_PREFIX}-windres)
|
||||
set(CMAKE_AR ${LLVM_MINGW}/bin/llvm-ar)
|
||||
set(CMAKE_RANLIB ${LLVM_MINGW}/bin/llvm-ranlib)
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH ${LLVM_MINGW}/${TOOLCHAIN_PREFIX})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
@@ -0,0 +1,17 @@
|
||||
# Cross-compile to Windows ARM (32-bit ARMv7) with llvm-mingw (clang + lld).
|
||||
# Debian's gcc mingw-w64 only targets x86, so ARM Windows uses llvm-mingw.
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(CMAKE_SYSTEM_PROCESSOR arm)
|
||||
|
||||
set(TOOLCHAIN_PREFIX armv7-w64-mingw32)
|
||||
set(LLVM_MINGW /opt/llvm-mingw)
|
||||
set(CMAKE_C_COMPILER ${LLVM_MINGW}/bin/${TOOLCHAIN_PREFIX}-clang)
|
||||
set(CMAKE_CXX_COMPILER ${LLVM_MINGW}/bin/${TOOLCHAIN_PREFIX}-clang++)
|
||||
set(CMAKE_RC_COMPILER ${LLVM_MINGW}/bin/${TOOLCHAIN_PREFIX}-windres)
|
||||
set(CMAKE_AR ${LLVM_MINGW}/bin/llvm-ar)
|
||||
set(CMAKE_RANLIB ${LLVM_MINGW}/bin/llvm-ranlib)
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH ${LLVM_MINGW}/${TOOLCHAIN_PREFIX})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
@@ -0,0 +1,14 @@
|
||||
# Cross-compile to Windows ARM64 with llvm-mingw (Debian's mingw-w64 has no
|
||||
# ARM target, so this toolchain comes from the LLVM-MinGW distribution).
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(CMAKE_SYSTEM_PROCESSOR aarch64)
|
||||
|
||||
set(TOOLCHAIN_PREFIX aarch64-w64-mingw32)
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
|
||||
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH /opt/llvm-mingw/${TOOLCHAIN_PREFIX})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
@@ -0,0 +1,14 @@
|
||||
# Cross-compile to Windows ARM 32-bit with llvm-mingw (Debian's mingw-w64 has no
|
||||
# ARM target, so this toolchain comes from the LLVM-MinGW distribution).
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(CMAKE_SYSTEM_PROCESSOR armv7)
|
||||
|
||||
set(TOOLCHAIN_PREFIX armv7-w64-mingw32)
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
|
||||
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH /opt/llvm-mingw/${TOOLCHAIN_PREFIX})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
@@ -0,0 +1,13 @@
|
||||
# Cross-compile to Windows 32-bit (i686) with mingw-w64.
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(CMAKE_SYSTEM_PROCESSOR x86)
|
||||
|
||||
set(TOOLCHAIN_PREFIX i686-w64-mingw32)
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc-posix)
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++-posix)
|
||||
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
@@ -0,0 +1,13 @@
|
||||
# Cross-compile to Windows x86_64 with mingw-w64.
|
||||
set(CMAKE_SYSTEM_NAME Windows)
|
||||
set(CMAKE_SYSTEM_PROCESSOR x86_64)
|
||||
|
||||
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc-posix)
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++-posix)
|
||||
set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
|
||||
|
||||
set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
Reference in New Issue
Block a user