Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross Compiling is back! (for aarch64) #4989

Merged
merged 1 commit into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
34 changes: 34 additions & 0 deletions cmake/linux-aarch64-ubuntu-crosscompile-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 12 additions & 3 deletions libs/LuaJitLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}/$<CONFIG>
COMMAND ${LUAJIT_HOSTCC} -m${LUAJIT_BITNESS} -o ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${name} ${ARG_COMPILE_DEFINITIONS} ${ARG_INCLUDE_DIRECTORIES} ${ARG_LIBS} ${ARG_SOURCES}
COMMAND ${LUAJIT_HOSTCC} -m${LUAJIT_BITNESS} -o ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/${name} ${ARG_COMPILE_DEFINITIONS} ${ARG_INCLUDE_DIRECTORIES} ${ARG_SOURCES} ${ARG_LIBS}
)
else()
add_executable(${name} ${ARG_SOURCES})
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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}
Expand Down