diff --git a/cmake/modules/grpc.cmake b/cmake/modules/grpc.cmake index d802901d45e..5d94468dfee 100644 --- a/cmake/modules/grpc.cmake +++ b/cmake/modules/grpc.cmake @@ -156,7 +156,17 @@ else() "${GRPC_SRC}/third_party/abseil-cpp/absl/random/libabsl_random_internal_platform.a" "${GRPC_SRC}/third_party/abseil-cpp/absl/random/libabsl_random_seed_gen_exception.a" ) - + + set(GRPC_PATCH_CMD "") + # Zig workaround: + # Add a PATCH_COMMAND to grpc cmake + ## to fixup emitted -march by abseil-cpp cmake module, + ## making it use a name understood by zig for arm64. + ## See https://github.com/abseil/abseil-cpp/blob/master/absl/copts/GENERATED_AbseilCopts.cmake#L226. + if (CMAKE_C_COMPILER MATCHES "zig") + message(STATUS "Enabling zig workaround for abseil-cpp") + set(GRPC_PATCH_CMD sh -c "sed -i 's/armv8-a/cortex_a57/g' ${GRPC_SRC}/third_party/abseil-cpp/absl/copts/GENERATED_AbseilCopts.cmake") + endif() ExternalProject_Add(grpc PREFIX "${PROJECT_BINARY_DIR}/grpc-prefix" DEPENDS openssl protobuf c-ares zlib re2 @@ -205,6 +215,7 @@ else() # Keep installation files into the local ${GRPC_INSTALL_DIR} # since here is the case when we are embedding gRPC UPDATE_COMMAND "" + PATCH_COMMAND ${GRPC_PATCH_CMD} INSTALL_COMMAND DESTDIR= ${CMAKE_MAKE_PROGRAM} install ) install(FILES ${GRPC_MAIN_LIBS} DESTINATION "${CMAKE_INSTALL_LIBDIR}/${LIBS_PACKAGE_NAME}" diff --git a/cmake/modules/libelf.cmake b/cmake/modules/libelf.cmake index 1b7311f7337..d5e8000bcec 100644 --- a/cmake/modules/libelf.cmake +++ b/cmake/modules/libelf.cmake @@ -24,15 +24,29 @@ elseif(NOT USE_BUNDLED_LIBELF) else() set(LIBELF_LIB_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX}) endif() - find_library(LIBELF_LIB NAMES libelf${LIBELF_LIB_SUFFIX}) + # Zig workaround: + # since it won't look up in /usr/lib/..., add an HINT + if (CMAKE_C_COMPILER MATCHES "zig") + find_library(LIBELF_LIB NAMES libelf${LIBELF_LIB_SUFFIX} HINTS /usr/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/) + else() + find_library(LIBELF_LIB NAMES libelf${LIBELF_LIB_SUFFIX}) + endif() if(LIBELF_LIB) + # Zig workaround: + # avoid include whole /usr/include because it would + # include also system glibc headers breaking the build since + # we are targeting the build against our boostrapped zig. + if (CMAKE_C_COMPILER MATCHES "zig") + message(STATUS "Enabling zig workaround for libelf") + configure_file(${LIBELF_INCLUDE}/libelf.h libelf/libelf.h COPYONLY) + configure_file(${LIBELF_INCLUDE}/elf.h libelf/elf.h COPYONLY) + configure_file(${LIBELF_INCLUDE}/gelf.h libelf/gelf.h COPYONLY) + set(LIBELF_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/libelf) + endif() message(STATUS "Found LIBELF: include: ${LIBELF_INCLUDE}, lib: ${LIBELF_LIB}") else() message(FATAL_ERROR "Couldn't find system libelf") endif() - # We add a custom target, in this way we can always depend on `libelf` - # without distinguishing between "bundled" and "not-bundled" case - add_custom_target(libelf) else() if(BUILD_SHARED_LIBS) set(LIBELF_LIB_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})