diff --git a/CMakeLists.txt b/CMakeLists.txt index 476957cde11..eaae7bfcead 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -283,8 +283,8 @@ endif() # 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(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 CMAKE_CROSSCOMPILING)) + 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 edf6c3353c9..0deeb045ff9 100755 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -98,7 +98,7 @@ jobWrapper { rlmNode('docker') { getArchive() - buildDockerEnv('testing.Dockerfile').inside { + buildDockerEnv('linux.Dockerfile').inside { echo "Checking code formatting" modifications = sh(returnStdout: true, script: "git clang-format --diff ${targetSHA1}").trim() try { @@ -132,9 +132,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]), @@ -277,7 +277,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' @@ -286,6 +286,10 @@ def doCheckInDocker(Map options = [:]) { environment << 'UNITTEST_ENCRYPT_ALL=1' } + if (options.useToolchain) { + cmakeDefinitions += " -DCMAKE_TOOLCHAIN_FILE=\"${env.WORKSPACE}/tools/cmake/x86_64.toolchain.cmake\"" + } + def buildSteps = { String dockerArgs = "" -> buildEnv.inside(dockerArgs) { withEnv(environment) { @@ -377,7 +381,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') { @@ -405,12 +409,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.toolchain.cmake -DREALM_NO_TESTS=1 -DREALM_VERSION="${gitDescribeVersion}" -G Ninja .. ninja cpack -G TGZ """ @@ -436,7 +440,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 .." @@ -783,7 +787,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 ae9eee6d6e5..212c6af0988 100644 --- a/dependencies.list +++ b/dependencies.list @@ -1,5 +1,5 @@ PACKAGE_NAME=realm-core VERSION=13.10.0 OPENSSL_VERSION=3.0.8 -WIN32_ZLIB_VERSION=1.2.13 +ZLIB_VERSION=1.2.13 MDBREALM_TEST_SERVER_TAG=2023-04-29 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..94fc7a88c23 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 CMAKE_CROSSCOMPILING)) + 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.toolchain.cmake b/tools/cmake/aarch64.toolchain.cmake index da37ac348a0..f19fe88ac31 100644 --- a/tools/cmake/aarch64.toolchain.cmake +++ b/tools/cmake/aarch64.toolchain.cmake @@ -1,16 +1,18 @@ -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_PROCESSOR arm) -set(CMAKE_LIBRARY_ARCHITECTURE aarch64-linux-gnu) +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() -set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) -set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) +set(_TRIPLET "aarch64-unknown-linux-gnu") +file(DOWNLOAD https://static.realm.io/toolchains/v3/${_TRIPLET}.tar.zst ${CMAKE_BINARY_DIR}/${_TRIPLET}.tar.zst + EXPECTED_HASH MD5=a3a14d87f98904c2558b43bbd310f337 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() -set(CMAKE_CXX_FLAGS_INIT "-Wno-psabi") +file(ARCHIVE_EXTRACT INPUT ${CMAKE_BINARY_DIR}/${_TRIPLET}.tar.zst DESTINATION ${CMAKE_BINARY_DIR}) +include("${CMAKE_BINARY_DIR}/${_TRIPLET}/toolchain.cmake") -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) +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++") 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 index bfe7ded2f90..6a9bbf37d92 100644 --- a/tools/cmake/armhf.toolchain.cmake +++ b/tools/cmake/armhf.toolchain.cmake @@ -1,17 +1,18 @@ -set(CMAKE_SYSTEM_NAME Linux) -set(CMAKE_SYSTEM_PROCESSOR arm) +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() -set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc) -set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++) +set(_TRIPLET "armv7-unknown-linux-gnueabihf") +file(DOWNLOAD https://static.realm.io/toolchains/v3/${_TRIPLET}.tar.zst ${CMAKE_BINARY_DIR}/${_TRIPLET}.tar.zst + EXPECTED_HASH MD5=fbf817b1428bb35c93be8e6c15f73d7d 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() -set(CMAKE_CXX_FLAGS_INIT "-Wno-psabi") +file(ARCHIVE_EXTRACT INPUT ${CMAKE_BINARY_DIR}/${_TRIPLET}.tar.zst DESTINATION ${CMAKE_BINARY_DIR}) +include("${CMAKE_BINARY_DIR}/${_TRIPLET}/toolchain.cmake") -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) +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++") 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.toolchain.cmake b/tools/cmake/x86_64.toolchain.cmake new file mode 100644 index 00000000000..0b30663fbef --- /dev/null +++ b/tools/cmake/x86_64.toolchain.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() + +set(_TRIPLET "x86_64-unknown-linux-gnu") +file(DOWNLOAD https://static.realm.io/toolchains/v3/${_TRIPLET}.tar.zst ${CMAKE_BINARY_DIR}/${_TRIPLET}.tar.zst + EXPECTED_HASH MD5=aa99fc16d85adf1bb2f8b63b83542044 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") +unset(CMAKE_CROSSCOMPILING_EMULATOR) + +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++")