From a036f8971fb61ca781fb67978f4d5045f0923e35 Mon Sep 17 00:00:00 2001 From: "Paul Walker (baconpaul)" Date: Sat, 4 Sep 2021 13:43:03 -0400 Subject: [PATCH] Cross Compiling is back! (for aarch64) --- README.md | 10 ++++-- azure-pipelines.yml | 9 ++++- ...arch64-ubuntu-crosscompile-toolchain.cmake | 34 +++++++++++++++++++ libs/LuaJitLib/CMakeLists.txt | 15 ++++++-- 4 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 cmake/linux-aarch64-ubuntu-crosscompile-toolchain.cmake diff --git a/README.md b/README.md index 708fd48575f..7955ee7144a 100644 --- a/README.md +++ b/README.md @@ -253,8 +253,14 @@ cmake -Bbuild -DLINUX_ON_ARM=True cmake --build build --config Release --target surge-staged-assets ``` -Cross-compiling should also work, but we've not tried it in this cycle. If you get it to work with one of the -CMake toolchain files in CMake, we would welcome a pull request to this documentation with information. +### Cross Compiling for aarch64 + +To cross compile for aarch64 us the cmake linux toolchain for aarch4, as shown in the azure pipeline here. + +``` +cmake -Bignore/xc64 -DCMAKE_TOOLCHAIN_FILE=cmake/linux-aarch64-ubuntu-crosscompile-toolchain.cmake -DCMAKE_BUILD_TYPE=DEBUG -GNinja +cmake --build ignore/xc64 --config Debug --target surge-headless +``` # Setting up for Your OS diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 811e517583a..87755b308f9 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -60,7 +60,7 @@ jobs: linux-codequality: imageName: 'ubuntu-20.04' isLinux: True - aptGetExtras: "clang" + aptGetExtras: "" cmakeArguments: "-GNinja -DCMAKE_BUILD_TYPE=Debug" cmakeTarget: "code-quality-pipeline-checks" cmakeConfig: "Debug" @@ -78,6 +78,13 @@ jobs: cmakeArguments: "-GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++" cmakeTarget: "surge-xt_Standalone" cmakeConfig: "Debug" + linux-aarm64-cross-headless: + imageName: 'ubuntu-18.04' + isLinux: True + aptGetExtras: "g++-aarch64-linux-gnu gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu libc6-armel-cross libc6-dev-armel-cross binutils-arm-linux-gnueabi" + cmakeArguments: "-GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=cmake/linux-aarch64-ubuntu-crosscompile-toolchain.cmake" + cmakeTarget: "surge-headless" + cmakeConfig: "Debug" linux-juce-targets: imageName: 'ubuntu-18.04' isLinux: True diff --git a/cmake/linux-aarch64-ubuntu-crosscompile-toolchain.cmake b/cmake/linux-aarch64-ubuntu-crosscompile-toolchain.cmake new file mode 100644 index 00000000000..1f0a64c14f6 --- /dev/null +++ b/cmake/linux-aarch64-ubuntu-crosscompile-toolchain.cmake @@ -0,0 +1,34 @@ +# +# This Toolchain is set up for a set of defaults which works on ubuntu-20 cross compile +# to headless. Feel free to add a different toolchain config and then jut send us +# a pull request for different circumstances. +# +# If you make a toolchain in addition to the standard toolchain stuff, also +# set LINUX_ON_ARM to True and export LINUX_ON_ARM_COMPILE_OPTIONS +# +# sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu + +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR aarch64) + +set(LINUX_ON_ARM True) +set(FLAGS + -march=armv8-a + -Wno-psabi + -flax-vector-conversions #FIXME - remove this + ) +string(REPLACE ";" " " FLAGS "${FLAGS}") +set(CMAKE_C_FLAGS_INIT "${FLAGS}" CACHE STRING "" FORCE) +set(CMAKE_CXX_FLAGS_INIT "${FLAGS}" CACHE STRING "" FORCE) + +set(CMAKE_SYSROOT /usr/bin) +set(CMAKE_STAGING_PREFIX /home/devel/stage) + +set(tools /usr) +set(CMAKE_C_COMPILER ${tools}/bin/aarch64-linux-gnu-gcc) +set(CMAKE_CXX_COMPILER ${tools}/bin/aarch64-linux-gnu-g++) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) diff --git a/libs/LuaJitLib/CMakeLists.txt b/libs/LuaJitLib/CMakeLists.txt index e920a0383c2..5492ad1d84a 100644 --- a/libs/LuaJitLib/CMakeLists.txt +++ b/libs/LuaJitLib/CMakeLists.txt @@ -70,7 +70,7 @@ else() list(TRANSFORM ARG_LIBS PREPEND -l) add_custom_command(TARGET ${name} COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/$ - COMMAND ${LUAJIT_HOSTCC} -m${LUAJIT_BITNESS} -o ${CMAKE_CURRENT_BINARY_DIR}/$/${name} ${ARG_COMPILE_DEFINITIONS} ${ARG_INCLUDE_DIRECTORIES} ${ARG_LIBS} ${ARG_SOURCES} + COMMAND ${LUAJIT_HOSTCC} -m${LUAJIT_BITNESS} -o ${CMAKE_CURRENT_BINARY_DIR}/$/${name} ${ARG_COMPILE_DEFINITIONS} ${ARG_INCLUDE_DIRECTORIES} ${ARG_SOURCES} ${ARG_LIBS} ) else() add_executable(${name} ${ARG_SOURCES}) @@ -92,6 +92,7 @@ else() endif() set(fname ${CMAKE_CURRENT_BINARY_DIR}/LuaJITCheckHostLibraryExists_${variable}) file(WRITE ${fname}.c "extern int ${func}(void); int main(void) { return ${func}(); }\n") + message(STATUS ${LUAJIT_HOSTCC} -m${LUAJIT_BITNESS} -o ${fname} -l${lib} ${fname}.c) execute_process(COMMAND ${LUAJIT_HOSTCC} -m${LUAJIT_BITNESS} -o ${fname} -l${lib} ${fname}.c RESULT_VARIABLE status OUTPUT_QUIET @@ -180,10 +181,13 @@ else() ENDIF(DL_LIBRARY) CHECK_FUNCTION_EXISTS(dlopen LUA_USE_DLOPEN) IF(NOT LUA_USE_DLOPEN) - MESSAGE(FATAL_ERROR "Cannot compile a useful lua. + MESSAGE(ERROR "Cannot compile a useful lua. Function dlopen() seems not to be supported on your platform. Apparently you are not on a Windows platform as well. - So lua has no way to deal with shared libraries!") + So lua has no way to deal with shared libraries! + + You can safely ignore this if cross compiling on linux to arm tho +") ENDIF(NOT LUA_USE_DLOPEN) ENDIF(NOT WIN32) @@ -300,6 +304,11 @@ else() IF(MINILUA_USE_LIBM) set(MINILUA_LIBS m) ENDIF() + if (LINUX_ON_ARM) + message(STATUS "Forcing minilua libm on LINUX_ON_ARM" ) + list( APPEND MINILUA_LIBS m ) + endif() + luajit_add_host_executable(minilua SOURCES ${LUAJIT_DIR}/src/host/minilua.c COMPILE_DEFINITIONS ${TARGET_ARCH}