diff --git a/CHANGELOG.md b/CHANGELOG.md index 63e74c8ced4..3d4a39b2d64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,7 @@ ----------- ### Internals -* None. +* Added CMake toolchains for cross-targeting Linux x86_64, armv7, and aarch64. (PR [#6559](https://github.com/realm/realm-core/pull/6559)) ---------------------------------------------- diff --git a/CMakeLists.txt b/CMakeLists.txt index 834a10b6506..8e94e6a0317 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -297,8 +297,8 @@ endif() # Just use -lz and let Xcode figure it out # Emscripten does provide Zlib, but it doesn't work with find_package and is handled specially if(NOT APPLE AND NOT EMSCRIPTEN AND NOT TARGET ZLIB::ZLIB) - if(WIN32) - realm_acquire_dependency(zlib ${DEP_WIN32_ZLIB_VERSION} ZLIB_CMAKE_INCLUDE_FILE) + if(WIN32 OR (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND REALM_LINUX_TOOLCHAIN)) + realm_acquire_dependency(zlib ${DEP_ZLIB_VERSION} ZLIB_CMAKE_INCLUDE_FILE) include(${ZLIB_CMAKE_INCLUDE_FILE}) elseif(ANDROID) # On Android FindZLIB chooses the static libz over the dynamic one, but this leads to issues diff --git a/Jenkinsfile b/Jenkinsfile index 72b24f36333..49c1a7ba5e7 100755 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -105,9 +105,9 @@ jobWrapper { parallelExecutors = [ buildLinuxRelease : doBuildLinux('Release'), - checkLinuxDebug : doCheckInDocker(buildOptions), + checkLinuxDebug : doCheckInDocker(buildOptions + [useToolchain : true]), checkLinuxDebugEncrypt : doCheckInDocker(buildOptions + [useEncryption : true]), - checkLinuxRelease_4 : doCheckInDocker(buildOptions + [maxBpNodeSize: 4, buildType : 'Release']), + checkLinuxRelease_4 : doCheckInDocker(buildOptions + [maxBpNodeSize: 4, buildType : 'Release', useToolchain : true]), checkLinuxDebug_Sync : doCheckInDocker(buildOptions + [enableSync: true, dumpChangesetTransform: true]), checkLinuxDebugNoEncryp : doCheckInDocker(buildOptions + [enableEncryption: false]), checkMacOsRelease_Sync : doBuildMacOs(buildOptions + [buildType: 'Release', enableSync: true]), @@ -251,7 +251,7 @@ def doCheckInDocker(Map options = [:]) { rlmNode('docker') { getArchive() - def buildEnv = buildDockerEnv('testing.Dockerfile') + def buildEnv = buildDockerEnv('linux.Dockerfile') def environment = environment() environment << 'UNITTEST_XML=unit-test-report.xml' @@ -260,6 +260,12 @@ def doCheckInDocker(Map options = [:]) { environment << 'UNITTEST_ENCRYPT_ALL=1' } + // We don't enable this by default, because using a toolchain with its own sysroot + // prevents CMake from finding system libraries like curl which we use in sync tests. + if (options.useToolchain) { + cmakeDefinitions += " -DCMAKE_TOOLCHAIN_FILE=\"${env.WORKSPACE}/tools/cmake/x86_64-linux-gnu.toolchain.cmake\"" + } + def buildSteps = { String dockerArgs = "" -> buildEnv.inside(dockerArgs) { withEnv(environment) { @@ -351,7 +357,7 @@ def doCheckSanity(Map options = [:]) { "UNITTEST_SUITE_NAME=Linux-${options.buildType}", "TSAN_OPTIONS=\"suppressions=${WORKSPACE}/test/tsan.suppress\"" ] - buildDockerEnv('testing.Dockerfile').inside(privileged) { + buildDockerEnv('linux.Dockerfile').inside(privileged) { withEnv(environment) { try { dir('build-dir') { @@ -379,12 +385,12 @@ def doBuildLinux(String buildType) { rlmNode('docker') { getSourceArchive() - buildDockerEnv('packaging.Dockerfile').inside { + buildDockerEnv('linux.Dockerfile').inside { sh """ rm -rf build-dir mkdir build-dir cd build-dir - cmake -DCMAKE_BUILD_TYPE=${buildType} -DREALM_NO_TESTS=1 -DREALM_VERSION="${gitDescribeVersion}" -G Ninja .. + cmake -DCMAKE_BUILD_TYPE=${buildType} -DCMAKE_TOOLCHAIN_FILE=../tools/cmake/x86_64-linux-gnu.toolchain.cmake -DREALM_NO_TESTS=1 -DREALM_VERSION="${gitDescribeVersion}" -G Ninja .. ninja cpack -G TGZ """ @@ -410,7 +416,7 @@ def doBuildLinuxClang(String buildType) { 'CXX=clang++' ] - buildDockerEnv('testing.Dockerfile').inside { + buildDockerEnv('linux.Dockerfile').inside { withEnv(environment) { dir('build-dir') { sh "cmake -D CMAKE_BUILD_TYPE=${buildType} -DREALM_NO_TESTS=1 -DREALM_VERSION=\"${gitDescribeVersion}\" -G Ninja .." @@ -778,7 +784,7 @@ def doBuildCoverage() { rlmNode('docker') { getArchive() - buildDockerEnv('testing.Dockerfile').inside { + buildDockerEnv('linux.Dockerfile').inside { sh ''' mkdir build cd build diff --git a/dependencies.list b/dependencies.list index 1698fcc23d8..82cfadc920a 100644 --- a/dependencies.list +++ b/dependencies.list @@ -1,5 +1,5 @@ PACKAGE_NAME=realm-core VERSION=13.13.0 OPENSSL_VERSION=3.0.8 -WIN32_ZLIB_VERSION=1.2.13 +ZLIB_VERSION=1.2.13 MDBREALM_TEST_SERVER_TAG=2023-05-05 diff --git a/testing.Dockerfile b/linux.Dockerfile similarity index 100% rename from testing.Dockerfile rename to linux.Dockerfile diff --git a/packaging.Dockerfile b/packaging.Dockerfile deleted file mode 100644 index 28c6ce80128..00000000000 --- a/packaging.Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -# https://github.com/realm/ci/tree/master/realm/docker/build-centos -FROM ghcr.io/realm/ci/build-env-centos:master diff --git a/tools/cmake/RealmConfig.cmake.in b/tools/cmake/RealmConfig.cmake.in index 4b9d0da2a7f..14dc24a17dc 100644 --- a/tools/cmake/RealmConfig.cmake.in +++ b/tools/cmake/RealmConfig.cmake.in @@ -24,8 +24,8 @@ find_dependency(Threads) # so for an iOS build it'll use the path from the Device plaform, which is an error on Simulator. # Just use -lz and let Xcode figure it out if(TARGET Realm::Sync AND NOT APPLE AND NOT TARGET ZLIB::ZLIB) - if(WIN32) - realm_acquire_dependency(zlib @DEP_WIN32_ZLIB_VERSION@ ZLIB_CMAKE_INCLUDE_FILE) + if(WIN32 OR (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND REALM_LINUX_TOOLCHAIN)) + realm_acquire_dependency(zlib @DEP_ZLIB_VERSION@ ZLIB_CMAKE_INCLUDE_FILE) include(${ZLIB_CMAKE_INCLUDE_FILE}) elseif(ANDROID) # On Android FindZLIB chooses the static libz over the dynamic one, but this leads to issues diff --git a/tools/cmake/aarch64-linux-gnu.toolchain.cmake b/tools/cmake/aarch64-linux-gnu.toolchain.cmake new file mode 100644 index 00000000000..c86a4c3f31e --- /dev/null +++ b/tools/cmake/aarch64-linux-gnu.toolchain.cmake @@ -0,0 +1,3 @@ +set(_TRIPLET "aarch64-unknown-linux-gnu") +set(_TOOLCHAIN_MD5 a3a14d87f98904c2558b43bbd310f337) +include("${CMAKE_CURRENT_LIST_DIR}/linux.toolchain.base.cmake") diff --git a/tools/cmake/aarch64.toolchain.cmake b/tools/cmake/aarch64.toolchain.cmake deleted file mode 100644 index da37ac348a0..00000000000 --- a/tools/cmake/aarch64.toolchain.cmake +++ /dev/null @@ -1,16 +0,0 @@ -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_PROCESSOR arm) -set(CMAKE_LIBRARY_ARCHITECTURE aarch64-linux-gnu) - -set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) -set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) - -set(CMAKE_CXX_FLAGS_INIT "-Wno-psabi") - -set(CMAKE_FIND_ROOT_PATH "/usr/${CMAKE_LIBRARY_ARCHITECTURE}") - -set(ENV{PKG_CONFIG_SYSROOT_DIR} "/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}") - -set(THREADS_PTHREAD_ARG -pthread) - -set(REALM_USE_SYSTEM_OPENSSL ON) diff --git a/tools/cmake/android-build-openssl.sh.in b/tools/cmake/android-build-openssl.sh.in deleted file mode 100755 index 7e9db1476ed..00000000000 --- a/tools/cmake/android-build-openssl.sh.in +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/bash - -set -xe - -# Prepare the environment -export SYSTEM=android -export ARCH=arm -export ANDROID_SYSROOT=@ANDROID_SYSROOT@ -export ARCH=@ANDROID_ARCH_NAME@ -export ABI=@ANDROID_ABI@ -if [[ $ABI = "armeabi" ]]; then - export MACHINE=arm -elif [[ $ABI = "armeabi-v7a" ]]; then - export MACHINE=armv7 -else - export MACHINE=$ARCH -fi -export SYSTEM=android -export ANDROID_API=android -export SYSROOT=${ANDROID_SYSROOT} -export NDK_SYSROOT=${ANDROID_SYSROOT} -export ANDROID_NDK_SYSROOT=${ANDROID_SYSROOT} -export ANDROID_DEV=${ANDROID_SYSROOT}/usr -export HOSTCC=gcc -export PATH=$(dirname @CMAKE_C_COMPILER@):${PATH} -export CC=@CMAKE_C_COMPILER@ - -# Only build what we need -./config no-idea \ - no-camellia \ - no-seed \ - no-bf \ - no-cast \ - no-des \ - no-rc2 \ - no-rc4 \ - no-rc5 \ - no-md2 \ - no-md4 \ - no-ripemd \ - no-mdc2 \ - no-rsax \ - no-dsa \ - no-dh \ - no-ec \ - no-ecdsa \ - no-ecdh \ - no-sock \ - no-ssl2 \ - no-ssl3 \ - no-err \ - no-krb5 \ - no-engine \ - no-srtp \ - no-speed \ - no-unit-test \ - -DOPENSSL_NO_SHA512 \ - -DOPENSSL_NO_SHA0 \ - -w \ - -fPIC \ - --openssldir=@PROJECT_BINARY_DIR@/@ABI@ - -# Patch the Makefile in order to: -# 1) change optimization from -O3 to -Os -# 2) remove the -mandroid flag (it messes with make depend) -# 3) allow to add DEPFLAG values from the command line -# 4) use the proper ar command -# 5) use the proper ranlib command -sed -i.backup \ - -e "s/-O3/-Os/g" \ - -e "s/\-mandroid//g" \ - -e "s/DEPFLAG=/DEPFLAG+=/g" \ - -e "s#^AR=.*#AR= @CMAKE_AR@ $(ARFLAGS) r#" \ - -e "s#^RANLIB=.*#RANLIB= @CMAKE_RANLIB@#" \ - Makefile - -# Patch a file removing a function that brings in many unneeded dependencies -sed -i.backup /OPENSSL_cleanse/d crypto/sha/sha256.c - -make depend DEPFLAG=-I@ANDROID_TOOLCHAIN_ROOT@/lib/gcc/@ANDROID_TOOLCHAIN_MACHINE_NAME@/4.9/include -make build_crypto -make build_ssl - -mkdir -p @PROJECT_BINARY_DIR@/openssl/lib -mkdir -p @PROJECT_BINARY_DIR@/openssl/include -cp -RL include/* @PROJECT_BINARY_DIR@/openssl/include -cp libcrypto.a @PROJECT_BINARY_DIR@/openssl/lib -cp libssl.a @PROJECT_BINARY_DIR@/openssl/lib \ No newline at end of file diff --git a/tools/cmake/armhf.toolchain.cmake b/tools/cmake/armhf.toolchain.cmake deleted file mode 100644 index bfe7ded2f90..00000000000 --- a/tools/cmake/armhf.toolchain.cmake +++ /dev/null @@ -1,17 +0,0 @@ -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_PROCESSOR arm) - -set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc) -set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++) - -set(CMAKE_CXX_FLAGS_INIT "-Wno-psabi") - -set(CMAKE_LIBRARY_ARCHITECTURE arm-linux-gnueabihf) - -set(CMAKE_FIND_ROOT_PATH "/usr/${CMAKE_LIBRARY_ARCHITECTURE}") - -set(ENV{PKG_CONFIG_SYSROOT_DIR} "/usr/lib/arm-linux-gnueabihf/") - -set(THREADS_PTHREAD_ARG -pthread) - -set(REALM_USE_SYSTEM_OPENSSL ON) diff --git a/tools/cmake/armv7-linux-gnueabihf.toolchain.cmake b/tools/cmake/armv7-linux-gnueabihf.toolchain.cmake new file mode 100644 index 00000000000..423c44fdcd5 --- /dev/null +++ b/tools/cmake/armv7-linux-gnueabihf.toolchain.cmake @@ -0,0 +1,3 @@ +set(_TRIPLET "armv7-unknown-linux-gnueabihf") +set(_TOOLCHAIN_MD5 fbf817b1428bb35c93be8e6c15f73d7d) +include("${CMAKE_CURRENT_LIST_DIR}/linux.toolchain.base.cmake") diff --git a/tools/cmake/linux.toolchain.base.cmake b/tools/cmake/linux.toolchain.base.cmake new file mode 100644 index 00000000000..962a24541ca --- /dev/null +++ b/tools/cmake/linux.toolchain.base.cmake @@ -0,0 +1,19 @@ +if(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux" OR NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") + message(FATAL_ERROR "This toolchain can only be used on x86_64 Linux.") +endif() + +file(DOWNLOAD https://static.realm.io/toolchains/v3/${_TRIPLET}.tar.zst ${CMAKE_BINARY_DIR}/${_TRIPLET}.tar.zst + EXPECTED_HASH MD5=${_TOOLCHAIN_MD5} STATUS _DOWNLOAD_STATUS) +list(GET _DOWNLOAD_STATUS 0 _DOWNLOAD_STATUS_CODE) +if(NOT ${_DOWNLOAD_STATUS_CODE} EQUAL 0) + message(FATAL_ERROR "Error downloading ${_TRIPLET}.tar.zst: ${_DOWNLOAD_STATUS}") +endif() + +file(ARCHIVE_EXTRACT INPUT ${CMAKE_BINARY_DIR}/${_TRIPLET}.tar.zst DESTINATION ${CMAKE_BINARY_DIR}) +include("${CMAKE_BINARY_DIR}/${_TRIPLET}/toolchain.cmake") + +set(CMAKE_EXE_LINKER_FLAGS_INIT "-Xlinker --exclude-libs=libgcc.a,libstdc++.a -static-libgcc -static-libstdc++") +set(CMAKE_SHARED_LINKER_FLAGS_INIT "-Xlinker --exclude-libs=libgcc.a,libstdc++.a -static-libgcc -static-libstdc++") +set(CMAKE_MODULE_LINKER_FLAGS_INIT "-Xlinker --exclude-libs=libgcc.a,libstdc++.a -static-libgcc -static-libstdc++") + +set(REALM_LINUX_TOOLCHAIN ON) diff --git a/tools/cmake/run_ldconfig.sh b/tools/cmake/run_ldconfig.sh deleted file mode 100644 index 5d40cbbb044..00000000000 --- a/tools/cmake/run_ldconfig.sh +++ /dev/null @@ -1,3 +0,0 @@ -#/bin/bash -echo "Running ldconfig ..." -ldconfig \ No newline at end of file diff --git a/tools/cmake/x86_64-linux-gnu.toolchain.cmake b/tools/cmake/x86_64-linux-gnu.toolchain.cmake new file mode 100644 index 00000000000..8fbdc46792f --- /dev/null +++ b/tools/cmake/x86_64-linux-gnu.toolchain.cmake @@ -0,0 +1,3 @@ +set(_TRIPLET "x86_64-unknown-linux-gnu") +set(_TOOLCHAIN_MD5 aa99fc16d85adf1bb2f8b63b83542044) +include("${CMAKE_CURRENT_LIST_DIR}/linux.toolchain.base.cmake")