conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.12k stars 967 forks source link

[package] grpc/1.54.3: can't cross compile from Debian12 (x86_64) to Linux (armv8) #16801

Open arnk-basyskom opened 1 month ago

arnk-basyskom commented 1 month ago

Description

I looked around and found something that looks wrong. Inside the test_package folder there are all the gernerated CMake files to find the dependencies and the OpenSSL-debug-armv8-data.cmake for example has no libs set:

set(openssl_OpenSSL_Crypto_INCLUDE_DIRS_DEBUG )
set(openssl_OpenSSL_Crypto_LIB_DIRS_DEBUG "${openssl_PACKAGE_FOLDER_DEBUG}/lib")
set(openssl_OpenSSL_Crypto_BIN_DIRS_DEBUG "${openssl_PACKAGE_FOLDER_DEBUG}/bin")
set(openssl_OpenSSL_Crypto_LIBRARY_TYPE_DEBUG SHARED)
set(openssl_OpenSSL_Crypto_IS_HOST_WINDOWS_DEBUG 0)
set(openssl_OpenSSL_Crypto_RES_DIRS_DEBUG )
set(openssl_OpenSSL_Crypto_DEFINITIONS_DEBUG )
set(openssl_OpenSSL_Crypto_OBJECTS_DEBUG )
set(openssl_OpenSSL_Crypto_COMPILE_DEFINITIONS_DEBUG )
set(openssl_OpenSSL_Crypto_COMPILE_OPTIONS_C_DEBUG "")
set(openssl_OpenSSL_Crypto_COMPILE_OPTIONS_CXX_DEBUG "")
set(openssl_OpenSSL_Crypto_LIBS_DEBUG )
set(openssl_OpenSSL_Crypto_SYSTEM_LIBS_DEBUG dl rt pthread)
set(openssl_OpenSSL_Crypto_FRAMEWORK_DIRS_DEBUG )
set(openssl_OpenSSL_Crypto_FRAMEWORKS_DEBUG )
set(openssl_OpenSSL_Crypto_DEPENDENCIES_DEBUG )
set(openssl_OpenSSL_Crypto_SHARED_LINK_FLAGS_DEBUG )
set(openssl_OpenSSL_Crypto_EXE_LINK_FLAGS_DEBUG )
set(openssl_OpenSSL_Crypto_NO_SONAME_MODE_DEBUG FALSE)

For the "openssl_OpenSSL_Crypto_LIBS_DEBUG" I would expect the value "crypto" but it is empty. This is the case for all the generated CMake files.

Package and Environment Details

Conan profile

host profile (linux-aarch64-debug):

[settings]
os=Linux
arch=armv8
compiler=gcc
compiler.version=11
compiler.libcxx=libstdc++11
build_type=Debug

[conf]
tools.cmake.cmaketoolchain:user_toolchain+=/opt/sdk/arm_toolchain.cmake

[buildenv]
AR=aarch64-xilinx-linux-ar
AS=aarch64-xilinx-linux-as
RANLIB=aarch64-xilinx-linux-ranlib
CC=aarch64-xilinx-linux-gcc --sysroot=/opt/sdk/sysroots/cortexa72-cortexa53-xilinx-linux
CXX=aarch64-xilinx-linux-g++ --sysroot=/opt/sdk/sysroots/cortexa72-cortexa53-xilinx-linux
STRIP=aarch64-xilinx-linux-strip
LD=aarch64-xilinx-linux-ld
OBJCOPY=aarch64-xilinx-linux-objcopy
PATH=+(path)/opt/sdk/sysroots/x86_64-petalinux-linux/usr/bin/aarch64-xilinx-linux/

[options]
*:shared=True
grpc/*:codegen=True
grpc/*:cpp_plugin=True
grpc/*:csharp_ext=False
grpc/*:csharp_plugin=False
grpc/*:node_plugin=False
grpc/*:objective_c_plugin=False
grpc/*:php_plugin=False
grpc/*:python_plugin=False
grpc/*:ruby_plugin=False
grpc/*:secure=True
grpc/*:with_libsystemd=False

The arm_toolchain.cmake:

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv8)

set(COMPILER_PATH /opt/sdk/sysroots/x86_64-petalinux-linux/usr/bin/aarch64-xilinx-linux/)
set(SYSROOT /opt/sdk/sysroots/cortexa72-cortexa53-xilinx-linux)

# Specify your cross-compiler and its prefix
set(CMAKE_C_COMPILER ${COMPILER_PATH}/aarch64-xilinx-linux-gcc)
set(CMAKE_CXX_COMPILER ${COMPILER_PATH}/aarch64-xilinx-linux-g++)

# Optionally, specify other flags, include directories, and libraries
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${SYSROOT}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=${SYSROOT}")

build profile (default):

[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=12
os=Linux

Steps to reproduce

conan create recipes/grpc/all --version=1.54.3 -pr:b default -pr:h linux-aarch64-debug

Logs

Click to expand log ``` [2/2] Linking CXX executable test_package FAILED: test_package : && /opt/sdk/sysroots/x86_64-petalinux-linux/usr/bin/aarch64-xilinx-linux//aarch64-xilinx-linux-g++ --sysroot=/opt/sdk/sysroots/cortexa72-cortexa53-xilinx-linux -g CMakeFiles/test_package.dir/test_package.cpp.o -o test_package -L/app/conan2/conf/p/b/grpcbb326f14903b1/p/lib -L/app/conan2/conf/p/b/proto864e689518f89/p/lib -L/app/conan2/conf/p/b/zlibd0b9e959abf3e/p/lib -L/app/conan2/conf/p/b/c-are0492486f98121/p/lib -L/app/conan2/conf/p/b/re2c30f2db103b1c/p/lib -L/app/conan2/conf/p/b/absei8d53f8714273b/p/lib -L/app/conan2/conf/p/b/opens511fa12a95f89/p/lib -Wl,-rpath,/app/conan2/conf/p/b/grpcbb326f14903b1/p/lib:/app/conan2/conf/p/b/proto864e689518f89/p/lib:/app/conan2/conf/p/b/zlibd0b9e959abf3e/p/lib:/app/conan2/conf/p/b/c-are0492486f98121/p/lib:/app/conan2/conf/p/b/re2c30f2db103b1c/p/lib:/app/conan2/conf/p/b/absei8d53f8714273b/p/lib:/app/conan2/conf/p/b/opens511fa12a95f89/p/lib /app/conan2/conf/p/b/grpcbb326f14903b1/p/lib/libgrpc++.so -latomic /app/conan2/conf/p/b/grpcbb326f14903b1/p/lib/libgrpc.so /app/conan2/conf/p/b/grpcbb326f14903b1/p/lib/libaddress_sorting.so /app/conan2/conf/p/b/grpcbb326f14903b1/p/lib/libupb.so /app/conan2/conf/p/b/grpcbb326f14903b1/p/lib/libgpr.so -lm -lrt -ldl -lpthread && : /opt/sdk/sysroots/x86_64-petalinux-linux/usr/libexec/aarch64-xilinx-linux/gcc/aarch64-xilinx-linux/11.2.0/real-ld: warning: libprotobufd.so.32, needed by /app/conan2/conf/p/b/grpcbb326f14903b1/p/lib/libgrpc++.so, not found (try using -rpath or -rpath-link) /opt/sdk/sysroots/x86_64-petalinux-linux/usr/libexec/aarch64-xilinx-linux/gcc/aarch64-xilinx-linux/11.2.0/real-ld: warning: libssl.so.3, needed by /app/conan2/conf/p/b/grpcbb326f14903b1/p/lib/libgrpc++.so, not found (try using -rpath or -rpath-link) /opt/sdk/sysroots/x86_64-petalinux-linux/usr/libexec/aarch64-xilinx-linux/gcc/aarch64-xilinx-linux/11.2.0/real-ld: warning: libcrypto.so.3, needed by /app/conan2/conf/p/b/grpcbb326f14903b1/p/lib/libgrpc++.so, not found (try using -rpath or -rpath-link) [many more] /opt/sdk/sysroots/x86_64-petalinux-linux/usr/libexec/aarch64-xilinx-linux/gcc/aarch64-xilinx-linux/11.2.0/real-ld: /app/conan2/conf/p/b/grpcbb326f14903b1/p/lib/libgrpc.so: undefined reference to `absl::lts_20230125::ByChar::Find(std::basic_string_view >, unsigned long) const' /opt/sdk/sysroots/x86_64-petalinux-linux/usr/libexec/aarch64-xilinx-linux/gcc/aarch64-xilinx-linux/11.2.0/real-ld: /app/conan2/conf/p/b/grpcbb326f14903b1/p/lib/libgrpc.so: undefined reference to `absl::lts_20230125::StatusCodeToString[abi:cxx11](absl::lts_20230125::StatusCode)' /opt/sdk/sysroots/x86_64-petalinux-linux/usr/libexec/aarch64-xilinx-linux/gcc/aarch64-xilinx-linux/11.2.0/real-ld: /app/conan2/conf/p/b/grpcbb326f14903b1/p/lib/libgrpc.so: undefined reference to `SSL_CTX_get_ex_data@OPENSSL_3.0.0' [many more] collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed. ```
jcar87 commented 1 month ago

Hi @arnk-basyskom - thank you for reporting this.

I believe this is a combination of pre-existing issues:

and perhaps the fix here https://github.com/conan-io/conan/pull/13010/files#r1091019217 not working well in the presence of a sysroot.

I'm trying to replicate this case and issue a fix (even if a workaround) - however, from the logs you are posting, the grpc package actually built "successfully" - the issue is linking the test package due to the linker not having -rpath-link set properly. I suspect the fix wouldn't be in either the grpc recipe or the test package, but rather in a toolchain file or similar.

jcar87 commented 1 month ago

Adding the following snippet - needs to happen after Conan has had a chance to set CMAKE_LIBRARY_PATH in the toolchain - will solve the issue.

If this is a Conan problem, it's probably also problematic for native builds, but we may be helped by the linker looking in LD_LIBRARY_PATH for native builds (as per https://linux.die.net/man/1/ld).

Conan knows where all the relevant directories are - and it "should be" safe to just expose them all to the linker for this:

set(rpath_link_flags "")
foreach(_libdir IN LISTS CMAKE_LIBRARY_PATH)
  set(rpath_link_flags "${rpath_link_flags} -Wl,-rpath-link=${_libdir}")
endforeach()

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${rpath_link_flags}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${rpath_link_flags}")

adding this snippet after the call to project() in the grpc test_package does the job - this could go in a toolchain and we can probably consider doing this from Conan when cross-building for Linux.

will transfer this issue to the Conan repository as this is not strictly an issue with the recipe in Conan Center

arnk-basyskom commented 1 month ago

Thank you for your detailed feedback. I will try to test it soon. If you need any information or want me to test something, please let me know

Update: The workaround for the CMakeLists.txt in the test_package also works on my side. I'm still confused why CMake/Conan has every lib thats needed but the generated CMake files don't have the non system libs but the paths.

I would be glad if someone can give me a starting point for debugging this issue, so I can look into it myself.