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

fix(cmake): added zig workarounds for libelf and grpc cmake modules. #2049

Merged
merged 2 commits into from
Sep 20, 2024
Merged
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
24 changes: 24 additions & 0 deletions cmake/modules/grpc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,29 @@ else()
"${GRPC_SRC}/third_party/abseil-cpp/absl/random/libabsl_random_seed_gen_exception.a"
)

# Make abseil-cpp build compatible with gcc-13 See
# https://patchwork.yoctoproject.org/project/oe/patch/[email protected]/
# TO BE DROPPED once we finally upgrade grpc...
set(GRPC_PATCH_CMD
sh
-c
"sed -i '20s/^/#include <cstdint>/' ${GRPC_SRC}/third_party/abseil-cpp/absl/strings/internal/str_format/extension.h"
)

# 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
${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"
Expand Down Expand Up @@ -223,6 +246,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(
Expand Down
24 changes: 20 additions & 4 deletions cmake/modules/libelf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,31 @@ 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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this since it is already present at the end of the file.

else()
if(BUILD_SHARED_LIBS)
set(LIBELF_LIB_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
Expand Down
Loading