From 6dbc352e154e35b648e2fa976c185c3542ba8a73 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sat, 27 Sep 2025 23:22:39 -0400 Subject: [PATCH] Improve cross-compilation support for Linux builds Enhanced CMake toolchain files for aarch64 and x86_64 to better support cross-compilation, including improved root paths, pkg-config configuration, and OpenSSL hints. Updated linux_build.sh to refine dependency installation for cross-compiling, ensure ca-certificates are installed early, and improve handling of Ubuntu sources for both native and cross architectures, supporting new and old sources formats. --- .dockerignore | 1 - cmake/toolchains/aarch64-linux-gnu.cmake | 30 ++++++++++- cmake/toolchains/x86_64-linux-gnu.cmake | 24 ++++++++- scripts/linux_build.sh | 67 ++++++++++++++---------- 4 files changed, 91 insertions(+), 31 deletions(-) diff --git a/.dockerignore b/.dockerignore index d848043e..4d1a6fc1 100644 --- a/.dockerignore +++ b/.dockerignore @@ -26,7 +26,6 @@ third-party/build-deps/dist/FreeBSD* third-party/build-deps/dist/Windows* # ignore non Linux third-party submodules -third-party/libdisplaydevice third-party/TPCircularBuffer # ignore artifacts diff --git a/cmake/toolchains/aarch64-linux-gnu.cmake b/cmake/toolchains/aarch64-linux-gnu.cmake index 2a1aca88..a9f34ef1 100644 --- a/cmake/toolchains/aarch64-linux-gnu.cmake +++ b/cmake/toolchains/aarch64-linux-gnu.cmake @@ -21,7 +21,35 @@ set(CMAKE_CXX_COMPILER ${CMAKE_C_COMPILER_TARGET}-g++${LINUX_GCC_VERSION}) set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER_TARGET}-gcc${LINUX_GCC_VERSION}) # Here is the target environment located -set(CMAKE_FIND_ROOT_PATH /usr/${CMAKE_C_COMPILER_TARGET}) +set(CMAKE_FIND_ROOT_PATH + /usr/${CMAKE_C_COMPILER_TARGET} + /usr/lib/${CMAKE_C_COMPILER_TARGET} + /usr/include/${CMAKE_C_COMPILER_TARGET} +) + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +# OpenSSL hints for cross-compilation +set(OPENSSL_ROOT_DIR /usr/${CMAKE_C_COMPILER_TARGET}) +set(OPENSSL_INCLUDE_DIR /usr/include/${CMAKE_C_COMPILER_TARGET}) +set(OPENSSL_CRYPTO_LIBRARY /usr/lib/${CMAKE_C_COMPILER_TARGET}/libcrypto.so) +set(OPENSSL_SSL_LIBRARY /usr/lib/${CMAKE_C_COMPILER_TARGET}/libssl.so) + +# Configure pkg-config for cross-compilation +set(ENV{PKG_CONFIG_PATH} "/usr/lib/${CMAKE_C_COMPILER_TARGET}/pkgconfig") +set(ENV{PKG_CONFIG_LIBDIR} "/usr/lib/${CMAKE_C_COMPILER_TARGET}/pkgconfig:/usr/share/pkgconfig") +set(ENV{PKG_CONFIG_SYSROOT_DIR} "/") + +# Use the cross-compilation pkg-config if available +find_program(PKG_CONFIG_EXECUTABLE NAMES ${CMAKE_C_COMPILER_TARGET}-pkg-config pkg-config) +if(PKG_CONFIG_EXECUTABLE) + set(PKG_CONFIG_EXECUTABLE ${PKG_CONFIG_EXECUTABLE}) +endif() # Packaging set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}") diff --git a/cmake/toolchains/x86_64-linux-gnu.cmake b/cmake/toolchains/x86_64-linux-gnu.cmake index 41acf168..7dc24e33 100644 --- a/cmake/toolchains/x86_64-linux-gnu.cmake +++ b/cmake/toolchains/x86_64-linux-gnu.cmake @@ -21,7 +21,29 @@ set(CMAKE_CXX_COMPILER ${CMAKE_C_COMPILER_TARGET}-g++${LINUX_GCC_VERSION}) set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER_TARGET}-gcc${LINUX_GCC_VERSION}) # Here is the target environment located -set(CMAKE_FIND_ROOT_PATH /usr/${CMAKE_C_COMPILER_TARGET}) +set(CMAKE_FIND_ROOT_PATH + /usr/${CMAKE_C_COMPILER_TARGET} + /usr/lib/${CMAKE_C_COMPILER_TARGET} + /usr/include/${CMAKE_C_COMPILER_TARGET} +) + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +# Configure pkg-config for cross-compilation +set(ENV{PKG_CONFIG_PATH} "/usr/lib/${CMAKE_C_COMPILER_TARGET}/pkgconfig") +set(ENV{PKG_CONFIG_LIBDIR} "/usr/lib/${CMAKE_C_COMPILER_TARGET}/pkgconfig:/usr/share/pkgconfig") +set(ENV{PKG_CONFIG_SYSROOT_DIR} "/") + +# Use the cross-compilation pkg-config if available +find_program(PKG_CONFIG_EXECUTABLE NAMES ${CMAKE_C_COMPILER_TARGET}-pkg-config pkg-config) +if(PKG_CONFIG_EXECUTABLE) + set(PKG_CONFIG_EXECUTABLE ${PKG_CONFIG_EXECUTABLE}) +endif() # Packaging set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}") diff --git a/scripts/linux_build.sh b/scripts/linux_build.sh index d5a8111c..ef12e8e6 100755 --- a/scripts/linux_build.sh +++ b/scripts/linux_build.sh @@ -232,13 +232,6 @@ function add_arch_deps() { } function add_debian_based_deps() { - # If cross-compiling, we need the cross toolchain - if [ "$cross_compile" == 1 ] && [ -n "$target_arch" ]; then - dependencies+=( - "crossbuild-essential-${target_arch}" - ) - fi - dependencies+=( "appstream" "appstream-util" @@ -257,12 +250,13 @@ function add_debian_based_deps() { "xvfb" # necessary for headless unit testing ) - # Add GCC for the target architecture + if [ "$cross_compile" == 1 ] && [ -n "$target_arch" ]; then - dependencies+=("gcc-${gcc_version}") - dependencies+=("g++-${gcc_version}") # Cross-compile specific library packages with architecture suffix dependencies+=( + "crossbuild-essential-${target_arch}" + "gcc-${gcc_version}-aarch64-linux-gnu" + "g++-${gcc_version}-aarch64-linux-gnu" "libcap-dev:${target_arch}" # KMS "libcurl4-openssl-dev:${target_arch}" "libdrm-dev:${target_arch}" # KMS @@ -511,6 +505,11 @@ function update_ubuntu_sources() { return fi + # Install ca-certificates first to avoid SSL issues + echo "Installing ca-certificates for HTTPS repositories..." + ${sudo_cmd} apt-get update || true # Allow this to fail initially + ${sudo_cmd} apt-get install -y ca-certificates || true + # Use existing distribution detection variables local dist_name local ubuntu_version @@ -527,8 +526,10 @@ function update_ubuntu_sources() { echo "Detected Ubuntu version: $ubuntu_version" echo "Detected Ubuntu major version: $ubuntu_major_version" - # Determine mirror URL - local mirror="https://ports.ubuntu.com/ubuntu-ports" + # Determine mirror URLs + local main_mirror="http://archive.ubuntu.com/ubuntu" + local ports_mirror="http://ports.ubuntu.com/ubuntu-ports" + local security_mirror="http://security.ubuntu.com/ubuntu" # Add target architecture echo "Adding architecture: $target_arch" @@ -556,24 +557,34 @@ function update_ubuntu_sources() { # Update sources based on Ubuntu version if [[ $ubuntu_major_version -ge 24 ]]; then # Ubuntu 24.04+ uses the new .sources format - local extra_sources - extra_sources=$(cat < /dev/null + echo "$new_sources" | ${sudo_cmd} tee "$source_file" > /dev/null else # Ubuntu 22.04 and earlier use the traditional sources.list format # Fix original sources to specify amd64 architecture @@ -582,16 +593,16 @@ VAREOF # Add cross-compilation sources local extra_sources extra_sources=$(cat < /dev/null