Skip to content

Commit

Permalink
Use cross-compilers instead of CentOS image
Browse files Browse the repository at this point in the history
  • Loading branch information
fealebenpae committed May 8, 2023
1 parent 7b9ab24 commit d29efd9
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 134 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]),
Expand Down Expand Up @@ -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'
Expand All @@ -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) {
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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
"""
Expand All @@ -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 .."
Expand Down Expand Up @@ -783,7 +787,7 @@ def doBuildCoverage() {
rlmNode('docker') {
getArchive()

buildDockerEnv('testing.Dockerfile').inside {
buildDockerEnv('linux.Dockerfile').inside {
sh '''
mkdir build
cd build
Expand Down
2 changes: 1 addition & 1 deletion dependencies.list
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
2 changes: 0 additions & 2 deletions packaging.Dockerfile

This file was deleted.

4 changes: 2 additions & 2 deletions tools/cmake/RealmConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 15 additions & 13 deletions tools/cmake/aarch64.toolchain.cmake
Original file line number Diff line number Diff line change
@@ -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++")
88 changes: 0 additions & 88 deletions tools/cmake/android-build-openssl.sh.in

This file was deleted.

29 changes: 15 additions & 14 deletions tools/cmake/armhf.toolchain.cmake
Original file line number Diff line number Diff line change
@@ -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++")
3 changes: 0 additions & 3 deletions tools/cmake/run_ldconfig.sh

This file was deleted.

19 changes: 19 additions & 0 deletions tools/cmake/x86_64.toolchain.cmake
Original file line number Diff line number Diff line change
@@ -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++")

0 comments on commit d29efd9

Please sign in to comment.