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

@@ -108,30 +108,8 @@ if(YAZE_WITH_GRPC)
${CMAKE_SOURCE_DIR}/third_party/json/include)
target_compile_definitions(yaze_app_core_lib PRIVATE YAZE_WITH_JSON)
# Add proto definitions for ROM service, canvas automation, and test harness
# Test harness proto is needed because widget_discovery_service.h includes it
target_add_protobuf(yaze_app_core_lib
${PROJECT_SOURCE_DIR}/src/protos/rom_service.proto)
target_add_protobuf(yaze_app_core_lib
${PROJECT_SOURCE_DIR}/src/protos/canvas_automation.proto)
target_add_protobuf(yaze_app_core_lib
${PROJECT_SOURCE_DIR}/src/protos/imgui_test_harness.proto)
# Add unified gRPC server (non-test services only)
target_sources(yaze_app_core_lib PRIVATE
${CMAKE_SOURCE_DIR}/src/app/service/unified_grpc_server.cc
${CMAKE_SOURCE_DIR}/src/app/service/unified_grpc_server.h
)
target_link_libraries(yaze_app_core_lib PUBLIC
grpc++
grpc++_reflection
)
# NOTE: Do NOT link protobuf at library level on Windows - causes LNK1241
# Executables will link it with /WHOLEARCHIVE to include internal symbols
if(NOT WIN32 AND YAZE_PROTOBUF_TARGETS)
target_link_libraries(yaze_app_core_lib PUBLIC ${YAZE_PROTOBUF_TARGETS})
endif()
# Link to consolidated gRPC support library
target_link_libraries(yaze_app_core_lib PUBLIC yaze_grpc_support)
message(STATUS " - gRPC ROM service + canvas automation enabled")
endif()
@@ -202,22 +180,7 @@ target_link_libraries(yaze PRIVATE
absl::flags
absl::flags_parse
)
if(YAZE_WITH_GRPC AND YAZE_PROTOBUF_TARGETS)
# On Windows: Use /WHOLEARCHIVE instead of normal linking to include internal symbols
# On Unix: Use normal linking (symbols resolve correctly without whole-archive)
if(MSVC AND YAZE_PROTOBUF_WHOLEARCHIVE_TARGETS)
foreach(_yaze_proto_target IN LISTS YAZE_PROTOBUF_WHOLEARCHIVE_TARGETS)
if(TARGET ${_yaze_proto_target})
get_target_property(_target_type ${_yaze_proto_target} TYPE)
if(_target_type MATCHES ".*_LIBRARY")
target_link_options(yaze PRIVATE /WHOLEARCHIVE:$<TARGET_FILE:${_yaze_proto_target}>)
endif()
endif()
endforeach()
else()
target_link_libraries(yaze PRIVATE ${YAZE_PROTOBUF_TARGETS})
endif()
endif()
# gRPC/protobuf linking is now handled by yaze_grpc_support library
# Link test support library (yaze_editor needs TestManager)
if(TARGET yaze_test_support)