From b1d81e860fcb5dd65fb6bab8d9669a556c6746d9 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Thu, 24 Jun 2021 12:40:34 -0400 Subject: [PATCH] Compile For ARM64 --- CMakeLists.txt | 12 ++++-- ...hf-toolchain.cmake => arm-toolchain.cmake} | 0 cmake/arm64-toolchain.cmake | 10 +++++ debian/client-arm64 | 7 +++ debian/server-arm64 | 7 +++ scripts/build.sh | 43 +++++++++++++++++++ scripts/install-dependencies.sh | 6 ++- 7 files changed, 81 insertions(+), 4 deletions(-) rename cmake/{armhf-toolchain.cmake => arm-toolchain.cmake} (100%) create mode 100644 cmake/arm64-toolchain.cmake create mode 100644 debian/client-arm64 create mode 100644 debian/server-arm64 diff --git a/CMakeLists.txt b/CMakeLists.txt index 064e0a8e0..eb3d23766 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,12 +24,18 @@ else() endif() # Use Clang By Default -set(CMAKE_C_COMPILER clang) -set(CMAKE_CXX_COMPILER clang++) +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) + if(NOT DEFINED CMAKE_C_COMPILER) + set(CMAKE_C_COMPILER clang) + endif() + if(NOT DEFINED CMAKE_CXX_COMPILER) + set(CMAKE_CXX_COMPILER clang++) + endif() +endif() # Setup ARM Cross Compilation if(USE_ARM32_TOOLCHAIN) - include(cmake/armhf-toolchain.cmake) + include(cmake/arm-toolchain.cmake) endif() # Use LLD When Using Clang diff --git a/cmake/armhf-toolchain.cmake b/cmake/arm-toolchain.cmake similarity index 100% rename from cmake/armhf-toolchain.cmake rename to cmake/arm-toolchain.cmake diff --git a/cmake/arm64-toolchain.cmake b/cmake/arm64-toolchain.cmake new file mode 100644 index 000000000..5f39b83d9 --- /dev/null +++ b/cmake/arm64-toolchain.cmake @@ -0,0 +1,10 @@ +# Compile For ARM64 +if(NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64_be" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "armv8b" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "armv8l")) + # Use ARM64 Cross-Compiler + set(TARGET "aarch64-linux-gnu") + set(CMAKE_C_COMPILER "${TARGET}-gcc") + set(CMAKE_CXX_COMPILER "${TARGET}-g++") + set(CMAKE_FIND_ROOT_PATH "/usr/${TARGET}" "/usr/lib/${TARGET}") +endif() +set(CMAKE_SYSTEM_NAME "Linux") +set(CMAKE_SYSTEM_PROCESSOR "aarch64") diff --git a/debian/client-arm64 b/debian/client-arm64 new file mode 100644 index 000000000..c22112271 --- /dev/null +++ b/debian/client-arm64 @@ -0,0 +1,7 @@ +Package: minecraft-pi-reborn-client +Version: ${VERSION} +Maintainer: TheBrokenRail +Description: Fun with Blocks +Homepage: https://www.minecraft.net/en-us/edition/pi +Architecture: arm64 +Depends: zenity, libgles1, libegl1, libglfw3 | libglfw3-wayland, libfreeimage3, libc6-armhf-cross, libstdc++6-armhf-cross diff --git a/debian/server-arm64 b/debian/server-arm64 new file mode 100644 index 000000000..971ccad2b --- /dev/null +++ b/debian/server-arm64 @@ -0,0 +1,7 @@ +Package: minecraft-pi-reborn-server +Version: ${VERSION} +Maintainer: TheBrokenRail +Description: Fun with Blocks +Homepage: https://www.minecraft.net/en-us/edition/pi +Architecture: arm64 +Depends: libc6-armhf-cross, libstdc++6-armhf-cross diff --git a/scripts/build.sh b/scripts/build.sh index 9229abf28..fd1b68984 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -46,6 +46,44 @@ native_build() { cd ../../ } +# Build For ARM64 +arm64_build() { + # Create Build Dir + rm -rf build/$1-arm64 + mkdir -p build/$1-arm64 + cd build/$1-arm64 + + # Create Prefix + local prefix="$(cd ../../; pwd)/out/$1-arm64" + rm -rf "${prefix}" + mkdir -p "${prefix}" + + # Prepare + local extra_arg='-DMCPI_USE_MEDIA_LAYER_PROXY=ON' + if [ "$1" = "server" ]; then + extra_arg='-DMCPI_SERVER_MODE=ON' + fi + + # Build ARM Components + mkdir arm + cd arm + cmake -DMCPI_BUILD_MODE=arm "${extra_arg}" ../../.. + make -j$(nproc) + make install DESTDIR="${prefix}" + cd ../ + + # Build Native Components + mkdir native + cd native + cmake -DCMAKE_TOOLCHAIN_FILE="$(cd ../../../; pwd)/cmake/arm64-toolchain.cmake" -DMCPI_BUILD_MODE=native "${extra_arg}" ../../.. + make -j$(nproc) + make install DESTDIR="${prefix}" + cd ../ + + # Exit + cd ../../ +} + # Build For ARM arm_build() { # Create Build Dir @@ -79,6 +117,11 @@ rm -rf out # Build native_build client native_build server +if [ ! -z "${ARM_PACKAGES_SUPPORTED}" ]; then + # Requires ARM Versions Of GLFW And FreeImage + arm64_build client +fi +arm64_build server if [ ! -z "${ARM_PACKAGES_SUPPORTED}" ]; then # Requires ARM Versions Of GLFW And FreeImage arm_build client diff --git a/scripts/install-dependencies.sh b/scripts/install-dependencies.sh index f2c666f82..958842ff9 100755 --- a/scripts/install-dependencies.sh +++ b/scripts/install-dependencies.sh @@ -11,6 +11,7 @@ fi # Add ARM Repository if [ ! -z "${ARM_PACKAGES_SUPPORTED}" ]; then sudo dpkg --add-architecture armhf + sudo dpkg --add-architecture arm64 fi # Update APT @@ -29,12 +30,15 @@ sudo apt-get install --no-install-recommends -y \ libglfw3 libglfw3-dev \ libfreeimage3 libfreeimage-dev \ crossbuild-essential-armhf \ + crossbuild-essential-arm64 \ qemu-user-static # Install ARM Dependencies if [ ! -z "${ARM_PACKAGES_SUPPORTED}" ]; then sudo apt-get install --no-install-recommends -y \ libglfw3:armhf libglfw3-dev:armhf \ - libfreeimage3:armhf + libfreeimage3:armhf \ + libglfw3:arm64 libglfw3-dev:arm64 \ + libfreeimage3:arm64 fi