chore: consolidate gRPC and protobuf linking into a dedicated support library

- Introduced a new `yaze_grpc_support` library to centralize all gRPC and protobuf usage, addressing Windows linker errors and improving build stability.
- Updated CMake configurations across various components to link against the new support library instead of individual protobuf targets, simplifying the linking process.
- Removed legacy whole-archive linking logic, ensuring a cleaner and more maintainable build setup.

Benefits:
- Reduces complexity in CMake files and enhances compatibility across platforms.
- Prevents potential linker errors by consolidating gRPC and protobuf dependencies into a single library.
This commit is contained in:
scawful
2025-10-18 15:58:58 -04:00
parent 8e86c1bbdf
commit 6db7ba4782
15 changed files with 152 additions and 170 deletions

View File

@@ -95,16 +95,7 @@ else()
endif()
endif()
# Filter WHOLEARCHIVE targets to only include libraries (not executables like protoc)
set(YAZE_PROTOBUF_WHOLEARCHIVE_TARGETS)
foreach(_proto_target IN LISTS YAZE_PROTOBUF_TARGETS)
if(TARGET ${_proto_target})
get_target_property(_target_type ${_proto_target} TYPE)
if(_target_type MATCHES ".*_LIBRARY")
list(APPEND YAZE_PROTOBUF_WHOLEARCHIVE_TARGETS ${_proto_target})
endif()
endif()
endforeach()
# WHOLEARCHIVE logic removed - protobuf linking now handled by yaze_grpc_support library
if(YAZE_PROTOBUF_TARGETS)
list(GET YAZE_PROTOBUF_TARGETS 0 YAZE_PROTOBUF_TARGET)

View File

@@ -114,12 +114,20 @@ set(gRPC_MSVC_STATIC_RUNTIME ON CACHE BOOL "" FORCE)
if(APPLE AND CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
set(ABSL_USE_EXTERNAL_GOOGLETEST OFF CACHE BOOL "" FORCE)
set(ABSL_BUILD_TEST_HELPERS OFF CACHE BOOL "" FORCE)
# Disable problematic random targets that use x86-specific instructions
set(ABSL_RANDOM_HWAES_IMPL OFF CACHE BOOL "" FORCE)
set(ABSL_RANDOM_HWAES OFF CACHE BOOL "" FORCE)
# Disable all x86-specific random implementations
set(ABSL_RANDOM_INTERNAL_RANDEN_HWAES_IMPL OFF CACHE BOOL "" FORCE)
set(ABSL_RANDOM_INTERNAL_RANDEN_HWAES OFF CACHE BOOL "" FORCE)
# Force use of portable random implementation
set(ABSL_RANDOM_INTERNAL_PLATFORM_IMPL "portable" CACHE STRING "" FORCE)
endif()
# Declare gRPC version - using latest for all platforms
# v1.75.1 has ARM64 + modern compiler fixes
set(_GRPC_VERSION "v1.75.1")
set(_GRPC_VERSION_REASON "Latest stable - ARM64 macOS + modern Clang/MSVC compatibility")
# Declare gRPC version - using stable version with better protobuf compatibility
# v1.67.1 has good stability and protobuf compatibility
set(_GRPC_VERSION "v1.67.1")
set(_GRPC_VERSION_REASON "Stable version with good protobuf compatibility")
# Windows-specific: Disable BoringSSL ASM to avoid NASM build issues
if(WIN32)
@@ -212,7 +220,15 @@ endif()
# Fix Abseil ARM64 macOS compile flags (remove x86-specific flags)
if(APPLE AND DEFINED CMAKE_OSX_ARCHITECTURES AND CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
foreach(_absl_target IN ITEMS absl_random_internal_randen_hwaes absl_random_internal_randen_hwaes_impl)
# List of all Abseil targets that might have x86-specific flags
set(_absl_targets_with_x86_flags
absl_random_internal_randen_hwaes
absl_random_internal_randen_hwaes_impl
absl_random_internal_randen_hwaes_impl
absl_random_internal_randen_hwaes
)
foreach(_absl_target IN LISTS _absl_targets_with_x86_flags)
if(TARGET ${_absl_target})
get_target_property(_absl_opts ${_absl_target} COMPILE_OPTIONS)
if(_absl_opts AND NOT _absl_opts STREQUAL "NOTFOUND")
@@ -227,12 +243,13 @@ if(APPLE AND DEFINED CMAKE_OSX_ARCHITECTURES AND CMAKE_OSX_ARCHITECTURES STREQUA
set(_absl_skip_next TRUE)
continue()
endif()
if(_absl_opt STREQUAL "-maes" OR _absl_opt STREQUAL "-msse4.1")
if(_absl_opt STREQUAL "-maes" OR _absl_opt STREQUAL "-msse4.1" OR _absl_opt STREQUAL "-msse2")
continue()
endif()
list(APPEND _absl_filtered_opts ${_absl_opt})
endforeach()
set_property(TARGET ${_absl_target} PROPERTY COMPILE_OPTIONS ${_absl_filtered_opts})
message(STATUS "Fixed ARM64 flags for ${_absl_target}")
endif()
endif()
endforeach()

View File

@@ -11,10 +11,10 @@
cmake_minimum_required(VERSION 3.16)
# Option to use vcpkg for gRPC on Windows
option(YAZE_USE_VCPKG_GRPC "Use vcpkg pre-compiled gRPC packages (Windows only)" ON)
# Option to use vcpkg for gRPC on Windows (default OFF for CI reliability)
option(YAZE_USE_VCPKG_GRPC "Use vcpkg pre-compiled gRPC packages (Windows only)" OFF)
if(WIN32 AND YAZE_USE_VCPKG_GRPC)
if(WIN32 AND YAZE_USE_VCPKG_GRPC AND DEFINED CMAKE_TOOLCHAIN_FILE)
message(STATUS "Attempting to use vcpkg gRPC packages for faster Windows builds...")
message(STATUS " Note: If gRPC not in vcpkg.json, will fallback to FetchContent (recommended)")
@@ -170,7 +170,6 @@ if(WIN32 AND YAZE_USE_VCPKG_GRPC)
# Export protobuf targets (vcpkg uses protobuf:: namespace)
set(YAZE_PROTOBUF_TARGETS protobuf::libprotobuf PARENT_SCOPE)
set(YAZE_PROTOBUF_WHOLEARCHIVE_TARGETS protobuf::libprotobuf PARENT_SCOPE)
# Get protobuf include directories for proto generation
get_target_property(_PROTOBUF_INCLUDE_DIRS protobuf::libprotobuf