Skip to content

Commit

Permalink
Add incomplete support for building for ARM arch
Browse files Browse the repository at this point in the history
  • Loading branch information
botder committed Apr 14, 2022
1 parent a529423 commit 8fc9004
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 0 deletions.
37 changes: 37 additions & 0 deletions 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
55 changes: 55 additions & 0 deletions 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
23 changes: 23 additions & 0 deletions premake5.lua
Expand Up @@ -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"}

Expand Down
7 changes: 7 additions & 0 deletions 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
21 changes: 21 additions & 0 deletions 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
3 changes: 3 additions & 0 deletions vendor/cryptopp/premake5.lua
Expand Up @@ -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",
Expand Down

0 comments on commit 8fc9004

Please sign in to comment.