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

Fixes to get cross compilation working with c++20 #572

Closed
wants to merge 7 commits into from
Closed
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ set(CMAKE_C_STANDARD 11)
option(BUILD_ENTERPRISE "Set whether or not to build enterprise edition" OFF)
option(CODE_COVERAGE_ENABLED "Set whether or not code coverage report should be generated" OFF)
option(STRIP_SYMBOLS "Set whether or not the private symbols will be stripped" OFF)
option(CBL_C_BUILD_TESTS "If enabled, build the test suite as well" ON)

if(CODE_COVERAGE_ENABLED)
message("Code coverage enabled, forcing sanitizers off")
Expand Down
24 changes: 12 additions & 12 deletions cmake/Toolchain-cross-base.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ else()
set(SYSROOT_PATH "$ENV{ROOTFS}")
endif()

message(STATUS "Using sysroot path: ${SYSROOT_PATH}")
message(STATUS "Using external deps lib path: ${SYSROOT_PATH}")

set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_SYSROOT "${SYSROOT_PATH}")
#set(CMAKE_SYSROOT "${SYSROOT_PATH}")
set(CMAKE_FIND_ROOT_PATH "${SYSROOT_PATH}")
set(CMAKE_SYSTEM_NAME "Linux")

Expand All @@ -22,21 +22,21 @@ set(TOOLCHAIN_NM "${CMAKE_LIBRARY_ARCHITECTURE}-nm")
set(CMAKE_C_COMPILER ${TOOLCHAIN_CC})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_CXX})

set(LIB_DIRS
"${SYSROOT_PATH}/lib/${CMAKE_LIBRARY_ARCHITECTURE}"
"${SYSROOT_PATH}/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}"
)
#set(LIB_DIRS
# "${SYSROOT_PATH}/lib/${CMAKE_LIBRARY_ARCHITECTURE}"
# "${SYSROOT_PATH}/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}"
#)

set(COMMON_FLAGS "-I${SYSROOT_PATH}/usr/include -I${SYSROOT_PATH}/usr/include/${CMAKE_LIBRARY_ARCHITECTURE}")
FOREACH(LIB ${LIB_DIRS})
set(COMMON_FLAGS "${COMMON_FLAGS} -L${LIB} -Wl,-rpath-link,${LIB}")
ENDFOREACH()
#set(COMMON_FLAGS "-I${SYSROOT_PATH}/usr/include -I${SYSROOT_PATH}/usr/include/${CMAKE_LIBRARY_ARCHITECTURE}")
#FOREACH(LIB ${LIB_DIRS})
# set(COMMON_FLAGS "${COMMON_FLAGS} -L${LIB} -Wl,-rpath-link,${LIB}")
#ENDFOREACH()

set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};${SYSROOT_PATH}/usr/lib/${TOOLCHAIN_HOST}")
#set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};${SYSROOT_PATH}/usr/lib/${TOOLCHAIN_HOST}")
set(CMAKE_C_FLAGS "${COMMON_FLAGS}" CACHE STRING "")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "")

set(CMAKE_FIND_ROOT_PATH "${CMAKE_INSTALL_PREFIX};${CMAKE_PREFIX_PATH};${CMAKE_SYSROOT}")
#set(CMAKE_FIND_ROOT_PATH "${CMAKE_INSTALL_PREFIX};${CMAKE_PREFIX_PATH};${SYSROOT_PATH}")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
Expand Down
29 changes: 15 additions & 14 deletions jenkins/ci_cross_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,19 @@ def check_toolchain(name: str):
with tarfile.open('toolchain.tar.gz', 'r:gz') as tar:
safe_extract(tar, tmpdir, members=tar_extract_callback(tar))

outer_dir = tmppath / os.listdir(tmpdir)[0]
files_to_move = outer_dir.glob("**/*")
for file in files_to_move:
relative = file.relative_to(outer_dir)
os.makedirs(tmppath / relative.parent, 0o755, True)
shutil.move(str(file), tmppath / relative.parent)

os.rmdir(outer_dir)
if len(os.listdir(tmpdir)) == 1:
# The toolchain was packaged with a top level directory
# (i.e. usually with the same name as the tar.gz so foo.tar.gz -> foo/everything)
# but I don't want that, so remove it so that all the folders are in root
outer_dir = tmppath / os.listdir(tmpdir)[0]
files_to_move = outer_dir.glob("**/*")
for file in files_to_move:
relative = file.relative_to(outer_dir)
os.makedirs(tmppath / relative.parent, 0o755, True)
shutil.move(str(file), tmppath / relative.parent)

os.rmdir(outer_dir)

os.remove("toolchain.tar.gz")
if not toolchain_path.exists():
shutil.move(tmpdir, toolchain_path)
Expand Down Expand Up @@ -196,14 +201,10 @@ def check_sysroot(name: str):

os.environ['ROOTFS'] = str(sysroot_path)
cmake_args=['cmake', '..', f'-DEDITION={args.edition}', f'-DCMAKE_INSTALL_PREFIX={os.getcwd()}/libcblite-{args.version}',
'-DCMAKE_BUILD_TYPE=MinSizeRel', f'-DCMAKE_TOOLCHAIN_FILE={args.toolchain}']
if args.build_os == "raspbian9" or args.build_os == "debian9-x86_64":
cmake_args.append('-DCBL_STATIC_CXX=ON')
elif args.build_os == "raspios10-arm64":
cmake_args.append('-D64_BIT=ON')
'-DCMAKE_BUILD_TYPE=MinSizeRel', f'-DCMAKE_TOOLCHAIN_FILE={args.toolchain}', '-DCBL_STATIC_CXX=ON', '-DCBL_C_BUILD_TESTS=OFF']

subprocess.run(cmake_args, check=True)
subprocess.run(['make', '-j8'], check=True)
subprocess.run(['make', '-j8', 'cblite'], check=True)

print(f"==== Stripping binary using {args.strip_prefix}strip")
subprocess.run([str(workspace_path / 'couchbase-lite-c' / 'jenkins' / 'strip.sh'), project_dir,
Expand Down
34 changes: 9 additions & 25 deletions jenkins/cross_manifest.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
{
"raspbian9": {
"toolchain": "http://downloads.build.couchbase.com/mobile/toolchains/cross-gcc-9.3.0-pi_2-3.tar.gz",
"sysroot": "debian-stretch-armhf.tar.gz"
"debian11-armhf": {
"toolchain": "http://downloads.build.couchbase.com/mobile/toolchains/arm_gcc-12.3_glibc-2.31.tar.gz",
"sysroot": "debian-bookworm-armhf.tar.gz"
},
"debian9-x86_64": {
"toolchain": "",
"sysroot": "debian-stretch-x64.tar.gz"
"debian11-arm64": {
"toolchain": "http://downloads.build.couchbase.com/mobile/toolchains/aarch64_gcc-12.3_glibc-2.31.tar.gz",
"sysroot": "debian-bookworm-arm64.tar.gz"
},
"raspios10-armhf": {
"toolchain": "https://sourceforge.net/projects/raspberry-pi-cross-compilers/files/Raspberry%20Pi%20GCC%20Cross-Compiler%20Toolchains/Buster/GCC%208.3.0/Raspberry%20Pi%202%2C%203/cross-gcc-8.3.0-pi_2-3.tar.gz/download",
"sysroot": "debian-buster-armhf.tar.gz"
},
"raspios10-arm64": {
"toolchain": "https://sourceforge.net/projects/raspberry-pi-cross-compilers/files/Bonus%20Raspberry%20Pi%20GCC%2064-Bit%20Toolchains/Raspberry%20Pi%20GCC%2064-Bit%20Cross-Compiler%20Toolchains/Buster/GCC%208.3.0/cross-gcc-8.3.0-pi_64.tar.gz/download",
"sysroot": "debian-buster-arm64.tar.gz"
},
"ubuntu20.04-armhf": {
"toolchain": "",
"sysroot": "ubuntu-focal-armhf.tar.gz"
},
"ubuntu20.04-arm64": {
"toolchain": "",
"sysroot": "ubuntu-focal-arm64.tar.gz"
},
"ubuntu20.04-x86_64": {
"toolchain": "",
"sysroot": "ubuntu-focal-x64.tar.gz"
"debian11-x86_64": {
"toolchain": "http://downloads.build.couchbase.com/mobile/toolchains/x86_64_gcc-12.3_glibc-2.31.tar.gz",
"sysroot": "debian-bookworm-x64.tar.gz"
}
}
34 changes: 14 additions & 20 deletions jenkins/linux-package-config.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
{
"build_arch_config": {
"amd64": {
"build_os": "debian9-x86_64",
"build_os": "debian11-x86_64",
"strip_prefix": "x86_64-linux-gnu-",
"toolchain": "Toolchain-cross-x64",
"target_osname": "linux-x86_64",
"target_debs": [ "debian9", "debian10", "debian11", "debian12", "ubuntu20.04", "ubuntu22.04" ]
"target_debs": [ "debian11", "debian12", "ubuntu22.04", "ubuntu24.04" ]
},
"arm64": {
"build_os": "raspios10-arm64",
"build_os": "debian11-arm64",
"strip_prefix": "aarch64-linux-gnu-",
"toolchain": "Toolchain-pi64",
"toolchain": "Toolchain-cross-arm64",
"target_osname": "linux-arm64",
"target_debs": [ "debian10", "debian11", "debian12", "ubuntu20.04", "ubuntu22.04" ]
"target_debs": [ "debian11", "debian12", "ubuntu22.04", "ubuntu24.04" ]
},
"armhf": {
"build_os": "raspbian9",
"build_os": "debian11-armhf",
"strip_prefix": "arm-linux-gnueabihf-",
"toolchain": "Toolchain-pi",
"toolchain": "Toolchain-cross-armhf",
"target_osname": "linux-armhf",
"target_debs": [ "debian9", "debian10", "debian11", "debian12", "ubuntu20.04", "ubuntu22.04" ]
"target_debs": [ "debian11", "debian12", "ubuntu22.04", "ubuntu24.04" ]
}
},
"package_distro_config": {
"debian9": {
"extra_deps": "libicu57"
},
"debian10": {
"extra_deps": "libicu63,libstdc++6"
},
"debian11": {
"extra_deps": "libicu67,libstdc++6"
"extra_deps": "libicu67"
},
"debian12": {
"extra_deps": "libicu72,libstdc++6"
},
"ubuntu20.04": {
"extra_deps": "libicu66,libstdc++6"
"extra_deps": "libicu72"
},
"ubuntu22.04": {
"extra_deps": "libicu70,libstdc++6"
"extra_deps": "libicu70"
},
"ubuntu24.04": {
"extra_deps": "libicu74"
}
}
}
9 changes: 5 additions & 4 deletions jenkins/strip.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash -e

PREFIX=""
WORKING_DIR="${1}"
Expand All @@ -7,16 +7,17 @@ if [[ $# > 1 ]]; then
PREFIX="${2}"
fi

resolved_file=$(basename $(readlink -f libcblite.so))
pushd $WORKING_DIR
COMMAND="${PREFIX}objcopy --only-keep-debug libcblite.so tmp"
COMMAND="${PREFIX}objcopy --only-keep-debug $resolved_file tmp"
eval ${COMMAND}
COMMAND="find . -name \"*.a\" | xargs ${PREFIX}strip --strip-unneeded"
eval ${COMMAND}
rm libcblite.so*
mv tmp libcblite.so.sym
make -j8 cblite
COMMAND="${PREFIX}strip --strip-unneeded libcblite.so"
COMMAND="${PREFIX}strip --strip-unneeded $resolved_file"
eval ${COMMAND}
COMMAND="${PREFIX}objcopy --add-gnu-debuglink=libcblite.so.sym libcblite.so"
COMMAND="${PREFIX}objcopy --add-gnu-debuglink=libcblite.so.sym $resolved_file"
eval ${COMMAND}
popd
Loading
Loading