backend-infra-engineer: Release v0.3.3 snapshot
This commit is contained in:
147
cmake/grpc.cmake
147
cmake/grpc.cmake
@@ -5,25 +5,6 @@ set(CMAKE_POLICY_DEFAULT_CMP0074 NEW)
|
||||
# Include FetchContent module
|
||||
include(FetchContent)
|
||||
|
||||
# Try Windows-optimized path first
|
||||
if(WIN32)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/grpc_windows.cmake)
|
||||
if(YAZE_GRPC_CONFIGURED)
|
||||
# Validate that grpc_windows.cmake properly exported required targets/variables
|
||||
if(NOT COMMAND target_add_protobuf)
|
||||
message(FATAL_ERROR "grpc_windows.cmake did not define target_add_protobuf function")
|
||||
endif()
|
||||
if(NOT DEFINED ABSL_TARGETS OR NOT ABSL_TARGETS)
|
||||
message(FATAL_ERROR "grpc_windows.cmake did not export ABSL_TARGETS")
|
||||
endif()
|
||||
if(NOT DEFINED YAZE_PROTOBUF_TARGETS OR NOT YAZE_PROTOBUF_TARGETS)
|
||||
message(FATAL_ERROR "grpc_windows.cmake did not export YAZE_PROTOBUF_TARGETS")
|
||||
endif()
|
||||
message(STATUS "✓ Windows vcpkg gRPC configuration validated")
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Set minimum CMake version for subprojects (fixes c-ares compatibility)
|
||||
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
|
||||
|
||||
@@ -32,44 +13,19 @@ set(FETCHCONTENT_QUIET OFF)
|
||||
# CRITICAL: Prevent CMake from finding system-installed protobuf/abseil
|
||||
# This ensures gRPC uses its own bundled versions
|
||||
set(CMAKE_DISABLE_FIND_PACKAGE_Protobuf TRUE)
|
||||
set(CMAKE_DISABLE_FIND_PACKAGE_gRPC TRUE)
|
||||
set(CMAKE_DISABLE_FIND_PACKAGE_absl TRUE)
|
||||
set(CMAKE_DISABLE_FIND_PACKAGE_gRPC TRUE)
|
||||
|
||||
# Also prevent pkg-config from finding system packages
|
||||
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH FALSE)
|
||||
|
||||
# Add compiler flags for modern compiler compatibility
|
||||
# These flags are scoped to gRPC and its dependencies only
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
# Clang 15+ compatibility for gRPC
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=missing-template-arg-list-after-template-kw")
|
||||
add_compile_definitions(_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS)
|
||||
elseif(MSVC)
|
||||
# MSVC/Visual Studio compatibility for gRPC templates
|
||||
# v1.67.1 fixes most issues, but these flags help with large template instantiations
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") # Large object files
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-") # Standards conformance
|
||||
|
||||
# Suppress common gRPC warnings on MSVC (don't use add_compile_options to avoid affecting user code)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4244")
|
||||
|
||||
# Increase template instantiation depth for complex promise chains (MSVC 2019+)
|
||||
if(MSVC_VERSION GREATER_EQUAL 1920)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /constexpr:depth2048")
|
||||
endif()
|
||||
|
||||
# Prevent Windows macro pollution in protobuf-generated headers
|
||||
add_compile_definitions(
|
||||
WIN32_LEAN_AND_MEAN # Exclude rarely-used Windows headers
|
||||
NOMINMAX # Don't define min/max macros
|
||||
NOGDI # Exclude GDI (prevents DWORD and other macro conflicts)
|
||||
)
|
||||
endif()
|
||||
|
||||
# Save YAZE's C++ standard and temporarily set to C++17 for gRPC
|
||||
set(_SAVED_CMAKE_CXX_STANDARD ${CMAKE_CXX_STANDARD})
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
# ZLIB is provided by gRPC module (gRPC_ZLIB_PROVIDER="module")
|
||||
# find_package(ZLIB REQUIRED) not needed - gRPC bundles its own ZLIB
|
||||
|
||||
# Configure gRPC build options before fetching
|
||||
set(gRPC_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(gRPC_BUILD_CODEGEN ON CACHE BOOL "" FORCE)
|
||||
@@ -81,16 +37,15 @@ set(gRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN OFF CACHE BOOL "" FORCE)
|
||||
set(gRPC_BUILD_GRPC_PHP_PLUGIN OFF CACHE BOOL "" FORCE)
|
||||
set(gRPC_BUILD_GRPC_PYTHON_PLUGIN OFF CACHE BOOL "" FORCE)
|
||||
set(gRPC_BUILD_GRPC_RUBY_PLUGIN OFF CACHE BOOL "" FORCE)
|
||||
# Disable C++ reflection support (avoids extra proto generation)
|
||||
set(gRPC_BUILD_REFLECTION OFF CACHE BOOL "" FORCE)
|
||||
set(gRPC_BUILD_GRPC_REFLECTION OFF CACHE BOOL "" FORCE)
|
||||
set(gRPC_BUILD_GRPC_CPP_REFLECTION OFF CACHE BOOL "" FORCE)
|
||||
set(gRPC_BUILD_GRPCPP_REFLECTION OFF CACHE BOOL "" FORCE)
|
||||
|
||||
set(gRPC_BENCHMARK_PROVIDER "none" CACHE STRING "" FORCE)
|
||||
set(gRPC_ZLIB_PROVIDER "module" CACHE STRING "" FORCE)
|
||||
|
||||
# Skip install rule generation inside gRPC's dependency graph. This avoids
|
||||
# configure-time checks that require every transitive dependency (like Abseil
|
||||
# compatibility shims) to participate in install export sets, which we do not
|
||||
# need for the editor builds.
|
||||
set(CMAKE_SKIP_INSTALL_RULES ON CACHE BOOL "" FORCE)
|
||||
|
||||
# Let gRPC fetch and build its own protobuf and abseil
|
||||
set(gRPC_PROTOBUF_PROVIDER "module" CACHE STRING "" FORCE)
|
||||
set(gRPC_ABSL_PROVIDER "module" CACHE STRING "" FORCE)
|
||||
@@ -101,32 +56,27 @@ set(protobuf_BUILD_CONFORMANCE OFF CACHE BOOL "" FORCE)
|
||||
set(protobuf_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
|
||||
set(protobuf_BUILD_PROTOC_BINARIES ON CACHE BOOL "" FORCE)
|
||||
set(protobuf_WITH_ZLIB ON CACHE BOOL "" FORCE)
|
||||
set(protobuf_MSVC_STATIC_RUNTIME ON CACHE BOOL "" FORCE)
|
||||
|
||||
# Abseil configuration
|
||||
set(ABSL_PROPAGATE_CXX_STD ON CACHE BOOL "" FORCE)
|
||||
set(ABSL_ENABLE_INSTALL ON CACHE BOOL "" FORCE)
|
||||
set(ABSL_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
set(ABSL_BUILD_TESTING OFF CACHE BOOL "" FORCE)
|
||||
set(ABSL_MSVC_STATIC_RUNTIME ON CACHE BOOL "" FORCE)
|
||||
set(gRPC_MSVC_STATIC_RUNTIME ON CACHE BOOL "" FORCE)
|
||||
|
||||
# Disable x86-specific optimizations for ARM64 macOS builds
|
||||
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)
|
||||
endif()
|
||||
# Additional protobuf settings to avoid export conflicts
|
||||
set(protobuf_BUILD_LIBPROTOC ON CACHE BOOL "" FORCE)
|
||||
set(protobuf_BUILD_LIBPROTOBUF ON CACHE BOOL "" FORCE)
|
||||
set(protobuf_BUILD_LIBPROTOBUF_LITE ON CACHE BOOL "" FORCE)
|
||||
set(protobuf_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
|
||||
set(utf8_range_BUILD_TESTS OFF CACHE BOOL "" FORCE)
|
||||
set(utf8_range_INSTALL OFF CACHE BOOL "" FORCE)
|
||||
|
||||
# Declare gRPC with platform-specific versions
|
||||
# - macOS/Linux: v1.75.1 (has ARM64 + modern Clang fixes)
|
||||
# - Windows: v1.75.1 (better NASM/clang-cl support than v1.67.1)
|
||||
set(_GRPC_VERSION "v1.75.1")
|
||||
if(WIN32)
|
||||
set(_GRPC_VERSION_REASON "Windows clang-cl + MSVC compatibility")
|
||||
# Disable BoringSSL ASM to avoid NASM build issues on Windows
|
||||
# ASM optimizations cause NASM flag conflicts with clang-cl
|
||||
set(OPENSSL_NO_ASM ON CACHE BOOL "" FORCE)
|
||||
message(STATUS "Disabling BoringSSL ASM optimizations for Windows build compatibility")
|
||||
if(WIN32 AND MSVC)
|
||||
set(_GRPC_VERSION "v1.67.1")
|
||||
set(_GRPC_VERSION_REASON "MSVC-compatible, avoids linker regressions")
|
||||
else()
|
||||
set(_GRPC_VERSION "v1.75.1")
|
||||
set(_GRPC_VERSION_REASON "ARM64 macOS + modern Clang compatibility")
|
||||
endif()
|
||||
|
||||
@@ -146,9 +96,23 @@ FetchContent_Declare(
|
||||
set(_SAVED_CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH})
|
||||
set(CMAKE_PREFIX_PATH "")
|
||||
|
||||
# Some toolchain presets set CMAKE_CROSSCOMPILING even when building for the
|
||||
# host (macOS arm64). gRPC treats that as a signal to locate host-side protoc
|
||||
# binaries via find_program, which fails since we rely on the bundled targets.
|
||||
# Suppress the flag when the host and target platforms match so the generator
|
||||
# expressions remain intact.
|
||||
set(_SAVED_CMAKE_CROSSCOMPILING ${CMAKE_CROSSCOMPILING})
|
||||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL CMAKE_SYSTEM_NAME
|
||||
AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL CMAKE_SYSTEM_PROCESSOR)
|
||||
set(CMAKE_CROSSCOMPILING FALSE)
|
||||
endif()
|
||||
|
||||
# Download and build in isolation
|
||||
FetchContent_MakeAvailable(grpc)
|
||||
|
||||
# Restore cross-compiling flag
|
||||
set(CMAKE_CROSSCOMPILING ${_SAVED_CMAKE_CROSSCOMPILING})
|
||||
|
||||
# Restore CMAKE_PREFIX_PATH
|
||||
set(CMAKE_PREFIX_PATH ${_SAVED_CMAKE_PREFIX_PATH})
|
||||
|
||||
@@ -163,14 +127,15 @@ if(NOT TARGET grpc_cpp_plugin)
|
||||
message(FATAL_ERROR "Can not find target grpc_cpp_plugin")
|
||||
endif()
|
||||
|
||||
set(_gRPC_PROTOBUF_PROTOC_EXECUTABLE $<TARGET_FILE:protoc>)
|
||||
set(_gRPC_CPP_PLUGIN $<TARGET_FILE:grpc_cpp_plugin>)
|
||||
set(_gRPC_PROTO_GENS_DIR ${CMAKE_BINARY_DIR}/gens)
|
||||
file(REMOVE_RECURSE ${_gRPC_PROTO_GENS_DIR})
|
||||
file(MAKE_DIRECTORY ${_gRPC_PROTO_GENS_DIR})
|
||||
|
||||
get_target_property(_PROTOBUF_INCLUDE_DIRS libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
|
||||
list(GET _PROTOBUF_INCLUDE_DIRS 0 _gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR)
|
||||
|
||||
message(STATUS "gRPC setup complete")
|
||||
|
||||
# Export Abseil targets from gRPC's bundled abseil for use by the rest of the project
|
||||
# This ensures version compatibility between gRPC and our project
|
||||
# Note: Order matters for some linkers - put base libraries first
|
||||
@@ -213,36 +178,6 @@ endif()
|
||||
|
||||
# ABSL_TARGETS is now available to the rest of the project via include()
|
||||
|
||||
# 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)
|
||||
if(TARGET ${_absl_target})
|
||||
get_target_property(_absl_opts ${_absl_target} COMPILE_OPTIONS)
|
||||
if(_absl_opts AND NOT _absl_opts STREQUAL "NOTFOUND")
|
||||
set(_absl_filtered_opts)
|
||||
set(_absl_skip_next FALSE)
|
||||
foreach(_absl_opt IN LISTS _absl_opts)
|
||||
if(_absl_skip_next)
|
||||
set(_absl_skip_next FALSE)
|
||||
continue()
|
||||
endif()
|
||||
if(_absl_opt STREQUAL "-Xarch_x86_64")
|
||||
set(_absl_skip_next TRUE)
|
||||
continue()
|
||||
endif()
|
||||
if(_absl_opt STREQUAL "-maes" OR _absl_opt STREQUAL "-msse4.1")
|
||||
continue()
|
||||
endif()
|
||||
list(APPEND _absl_filtered_opts ${_absl_opt})
|
||||
endforeach()
|
||||
set_property(TARGET ${_absl_target} PROPERTY COMPILE_OPTIONS ${_absl_filtered_opts})
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
message(STATUS "gRPC setup complete (includes bundled Abseil)")
|
||||
|
||||
function(target_add_protobuf target)
|
||||
if(NOT TARGET ${target})
|
||||
message(FATAL_ERROR "Target ${target} doesn't exist")
|
||||
@@ -270,10 +205,10 @@ function(target_add_protobuf target)
|
||||
"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}_mock.grpc.pb.h"
|
||||
"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.cc"
|
||||
"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.h"
|
||||
COMMAND ${_gRPC_PROTOBUF_PROTOC_EXECUTABLE}
|
||||
COMMAND $<TARGET_FILE:protoc>
|
||||
ARGS --grpc_out=generate_mock_code=true:${_gRPC_PROTO_GENS_DIR}
|
||||
--cpp_out=${_gRPC_PROTO_GENS_DIR}
|
||||
--plugin=protoc-gen-grpc=${_gRPC_CPP_PLUGIN}
|
||||
--plugin=protoc-gen-grpc=$<TARGET_FILE:grpc_cpp_plugin>
|
||||
${_protobuf_include_path}
|
||||
${REL_FIL}
|
||||
DEPENDS ${ABS_FIL} protoc grpc_cpp_plugin
|
||||
|
||||
Reference in New Issue
Block a user