diff --git a/Dockerfile.arm b/Dockerfile.arm new file mode 100644 index 0000000000..1fb76d6804 --- /dev/null +++ b/Dockerfile.arm @@ -0,0 +1,37 @@ +FROM jetbrains/teamcity-minimal-agent:latest + +# Set to 1 to configure this image as Teamcity build agent +# Default value is 0 (manual build) +ENV AS_BUILDAGENT=0 + +# Set this to the target arm architecture: arm64 or armhf +ENV BUILD_ARCHITECTURE=arm64 + +# Set this to the target build configuration +ENV BUILD_CONFIG=release + +# This is important for using apt-get +USER root + +# Add architecture support for armhf and arm64 +COPY utils/arm-cross-compile-sources.list /etc/apt/sources.list.d/ + +RUN sed -i 's/deb http/deb \[arch=amd64,i386\] http/' /etc/apt/sources.list && \ + dpkg --add-architecture arm64 && \ + dpkg --add-architecture armhf && \ + apt-get update && \ + apt-get install -y make git \ + gcc-10-arm-linux-gnueabihf g++-10-arm-linux-gnueabihf \ + libncursesw5:armhf libncursesw5-dev:armhf \ + gcc-10-aarch64-linux-gnu g++-10-aarch64-linux-gnu \ + libncursesw5:arm64 libncursesw5-dev:arm64 libmysqlclient-dev:arm64 + +# Set build directory +VOLUME /build +WORKDIR /build + +# Copy entrypoint script +COPY utils/docker-entrypoint-arm.sh /docker-entrypoint.sh + +# Set entrypoint +ENTRYPOINT bash /docker-entrypoint.sh diff --git a/linux-build-arm.sh b/linux-build-arm.sh new file mode 100644 index 0000000000..fab877d522 --- /dev/null +++ b/linux-build-arm.sh @@ -0,0 +1,55 @@ +#!/bin/bash -e + +BUILD_ARCHITECTURE=arm64 +BUILD_CONFIG=release +NUM_CORES=$(grep -c ^processor /proc/cpuinfo) + +while [ $# -gt 0 ]; do + case "$1" in + --arch=*) + BUILD_ARCHITECTURE="${1#*=}" + ;; + --config=*) + BUILD_CONFIG="${1#*=}" + ;; + *) + printf "Error: Invalid argument: $1\n" + exit 1 + esac + shift +done + +echo "BUILD_ARCHITECTURE = $BUILD_ARCHITECTURE" +echo "BUILD_CONFIG = $BUILD_CONFIG" + +case $BUILD_ARCHITECTURE in + arm64) + GCC_PREFIX=aarch64-linux-gnu- + ;; + armhf) + GCC_PREFIX=arm-linux-gnueabihf- + ;; + *) + printf "Error: Invalid build architecture\n" + exit 1 +esac + +echo "GCC_PREFIX = $GCC_PREFIX" + +# Clean old build files +rm -Rf Build/ +rm -Rf Bin/ + +# Generate makefiles +utils/premake5 --arch=$BUILD_ARCHITECTURE --gccprefix=$GCC_PREFIX gmake + +# Remove -m32, -m64, -msse2 from *FLAGS +sed -i '/FLAGS +=/ s/-m32//i;/FLAGS +=/ s/-msse2//i;/FLAGS +=/ s/-m64//i' Build/*.make + +# Build! +make -C Build/ -j $NUM_CORES \ + AR=/bin/${GCC_PREFIX}ar \ + CC=/bin/${GCC_PREFIX}gcc-10 \ + CXX=/bin/${GCC_PREFIX}g++-10 \ + config=debug_x64 \ + all diff --git a/premake5.lua b/premake5.lua index 59de731d89..19c7971bd1 100644 --- a/premake5.lua +++ b/premake5.lua @@ -15,6 +15,29 @@ else end GLIBC_COMPAT = os.getenv("GLIBC_COMPAT") == "true" +-- Cross-building options +newoption { + trigger = "arch", + value = "ARCHITECTURE", + description = "Choose a particular target architecture for building", + allowed = { + { "host", "Host architecture" }, + { "armhf", "ARM hard-float" }, + { "arm64", "64-bit ARM" } + }, + default = "host" +} + +newoption { + trigger = "gccprefix", + value = "PREFIX", + description = "Prefix to be prepended to commands used by the GCC toolchain (for cross-building)" +} + +if _OPTIONS["gccprefix"] then + gccprefix(_OPTIONS["gccprefix"]) +end + workspace "MTASA" configurations {"Debug", "Release", "Nightly"} diff --git a/utils/arm-cross-compile-sources.list b/utils/arm-cross-compile-sources.list new file mode 100644 index 0000000000..92bd6a61b8 --- /dev/null +++ b/utils/arm-cross-compile-sources.list @@ -0,0 +1,7 @@ +deb [arch=armhf,arm64] http://ports.ubuntu.com/ focal main restricted +deb [arch=armhf,arm64] http://ports.ubuntu.com/ focal-updates main restricted +deb [arch=armhf,arm64] http://ports.ubuntu.com/ focal universe +deb [arch=armhf,arm64] http://ports.ubuntu.com/ focal-updates universe +deb [arch=armhf,arm64] http://ports.ubuntu.com/ focal multiverse +deb [arch=armhf,arm64] http://ports.ubuntu.com/ focal-updates multiverse +deb [arch=armhf,arm64] http://ports.ubuntu.com/ focal-backports main restricted universe multiverse diff --git a/utils/docker-entrypoint-arm.sh b/utils/docker-entrypoint-arm.sh new file mode 100644 index 0000000000..695c9ab3e6 --- /dev/null +++ b/utils/docker-entrypoint-arm.sh @@ -0,0 +1,21 @@ +#!/bin/bash -e + +# If configured as a build agent, we start the TeamCity agent +if [[ $AS_BUILDAGENT = "1" ]]; then + # https://github.com/JetBrains/teamcity-docker-minimal-agent/blob/master/Dockerfile#L17 + exec /run-services.sh +fi + +# Manually invoke build process +umask 000 +if [ ! -f ./premake5.lua ]; then + git clone --depth=1 https://github.com/multitheftauto/mtasa-blue.git . +fi + +# Set the default build target +if [ -z "$BUILD_CONFIG" ]; then + BUILD_CONFIG=release +fi + +# Start manual building +./linux-build-arm.sh --arch=$BUILD_ARCHITECTURE --config=$BUILD_CONFIG diff --git a/vendor/cryptopp/premake5.lua b/vendor/cryptopp/premake5.lua index 68c5730f4e..89a2efc808 100644 --- a/vendor/cryptopp/premake5.lua +++ b/vendor/cryptopp/premake5.lua @@ -206,6 +206,9 @@ project "cryptopp" filter "system:macosx" defines {"CRYPTOPP_DISABLE_ASM"} + filter { "options:arch=arm*" } + defines { "CRYPTOPP_DISABLE_ASM" } + filter "platforms:x64" files { "x64dll.asm",