From d40ac3372fd441312d79af75828fc8f952ac6cae Mon Sep 17 00:00:00 2001 From: scawful Date: Sun, 12 Oct 2025 07:16:47 -0400 Subject: [PATCH] feat(cmake): enhance OpenSSL linking and whole-archive options for Windows - Updated CMake configurations to conditionally link OpenSSL only when gRPC is not enabled, preventing duplicate symbol errors. - Added support for whole-archive linking of protobuf on Windows across core, net, agent, and z3ed components to ensure all symbols are included. - Improved status messages to reflect the use of gRPC's OpenSSL when applicable. Benefits: - Enhanced compatibility and stability of the build process across different platforms and configurations. --- src/app/core/core_library.cmake | 5 +++++ src/app/net/net_library.cmake | 26 +++++++++++++++++------- src/cli/agent.cmake | 35 ++++++++++++++++++++++++--------- src/cli/z3ed.cmake | 5 +++++ 4 files changed, 55 insertions(+), 16 deletions(-) diff --git a/src/app/core/core_library.cmake b/src/app/core/core_library.cmake index 96e54129..1be51b74 100644 --- a/src/app/core/core_library.cmake +++ b/src/app/core/core_library.cmake @@ -151,6 +151,11 @@ if(YAZE_WITH_GRPC) libprotobuf ) + # On Windows, force whole-archive linking for protobuf to ensure all symbols are included + if(MSVC) + target_link_options(yaze_core_lib PUBLIC /WHOLEARCHIVE:libprotobuf) + endif() + message(STATUS " - gRPC test harness + ROM service enabled") endif() diff --git a/src/app/net/net_library.cmake b/src/app/net/net_library.cmake index 4f37d610..a491afbd 100644 --- a/src/app/net/net_library.cmake +++ b/src/app/net/net_library.cmake @@ -52,14 +52,21 @@ if(YAZE_WITH_JSON) find_package(Threads REQUIRED) target_link_libraries(yaze_net PUBLIC Threads::Threads) - # Add OpenSSL for HTTPS/WSS support (optional but recommended) - find_package(OpenSSL QUIET) - if(OpenSSL_FOUND) - target_link_libraries(yaze_net PUBLIC OpenSSL::SSL OpenSSL::Crypto) - target_compile_definitions(yaze_net PUBLIC CPPHTTPLIB_OPENSSL_SUPPORT) - message(STATUS " - WebSocket with SSL/TLS support enabled") + # Only link OpenSSL if gRPC is NOT enabled (to avoid duplicate symbol errors) + # When gRPC is enabled, it brings its own OpenSSL which we'll use instead + if(NOT YAZE_WITH_GRPC) + find_package(OpenSSL QUIET) + if(OpenSSL_FOUND) + target_link_libraries(yaze_net PUBLIC OpenSSL::SSL OpenSSL::Crypto) + target_compile_definitions(yaze_net PUBLIC CPPHTTPLIB_OPENSSL_SUPPORT) + message(STATUS " - WebSocket with SSL/TLS support enabled") + else() + message(STATUS " - WebSocket without SSL/TLS (OpenSSL not found)") + endif() else() - message(STATUS " - WebSocket without SSL/TLS (OpenSSL not found)") + # When gRPC is enabled, still enable OpenSSL features but use gRPC's OpenSSL + target_compile_definitions(yaze_net PUBLIC CPPHTTPLIB_OPENSSL_SUPPORT) + message(STATUS " - WebSocket with SSL/TLS support enabled via gRPC's OpenSSL") endif() # Windows-specific socket library @@ -79,6 +86,11 @@ if(YAZE_WITH_GRPC) libprotobuf ) + # On Windows, force whole-archive linking for protobuf to ensure all symbols are included + if(MSVC) + target_link_options(yaze_net PUBLIC /WHOLEARCHIVE:libprotobuf) + endif() + message(STATUS " - gRPC ROM service enabled") endif() diff --git a/src/cli/agent.cmake b/src/cli/agent.cmake index bbec6ca8..665667c4 100644 --- a/src/cli/agent.cmake +++ b/src/cli/agent.cmake @@ -110,20 +110,32 @@ if(YAZE_WITH_JSON) target_link_libraries(yaze_agent PUBLIC nlohmann_json::nlohmann_json) target_compile_definitions(yaze_agent PUBLIC YAZE_WITH_JSON) - find_package(OpenSSL) - if(OpenSSL_FOUND) - target_compile_definitions(yaze_agent PUBLIC CPPHTTPLIB_OPENSSL_SUPPORT) - target_link_libraries(yaze_agent PUBLIC OpenSSL::SSL OpenSSL::Crypto) + # Only link OpenSSL if gRPC is NOT enabled (to avoid duplicate symbol errors) + # When gRPC is enabled, it brings its own OpenSSL which we'll use instead + if(NOT YAZE_WITH_GRPC) + find_package(OpenSSL) + if(OpenSSL_FOUND) + target_compile_definitions(yaze_agent PUBLIC CPPHTTPLIB_OPENSSL_SUPPORT) + target_link_libraries(yaze_agent PUBLIC OpenSSL::SSL OpenSSL::Crypto) + if(APPLE) + target_compile_definitions(yaze_agent PUBLIC CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) + target_link_libraries(yaze_agent PUBLIC "-framework CoreFoundation" "-framework Security") + endif() + + message(STATUS "✓ SSL/HTTPS support enabled for yaze_agent (Gemini + HTTPS)") + else() + message(WARNING "OpenSSL not found - Gemini HTTPS features disabled (Ollama still works)") + message(STATUS " Install OpenSSL to enable Gemini: brew install openssl (macOS) or apt-get install libssl-dev (Linux)") + endif() + else() + # When gRPC is enabled, still enable OpenSSL features but use gRPC's OpenSSL + target_compile_definitions(yaze_agent PUBLIC CPPHTTPLIB_OPENSSL_SUPPORT) if(APPLE) target_compile_definitions(yaze_agent PUBLIC CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) target_link_libraries(yaze_agent PUBLIC "-framework CoreFoundation" "-framework Security") endif() - - message(STATUS "✓ SSL/HTTPS support enabled for yaze_agent (Gemini + HTTPS)") - else() - message(WARNING "OpenSSL not found - Gemini HTTPS features disabled (Ollama still works)") - message(STATUS " Install OpenSSL to enable Gemini: brew install openssl (macOS) or apt-get install libssl-dev (Linux)") + message(STATUS "✓ SSL/HTTPS support enabled via gRPC's OpenSSL (Gemini + HTTPS)") endif() endif() @@ -141,6 +153,11 @@ if(YAZE_WITH_GRPC) libprotobuf ) + # On Windows, force whole-archive linking for protobuf to ensure all symbols are included + if(MSVC) + target_link_options(yaze_agent PUBLIC /WHOLEARCHIVE:libprotobuf) + endif() + # Note: YAZE_WITH_GRPC is defined globally via add_compile_definitions in root CMakeLists.txt # This ensures #ifdef YAZE_WITH_GRPC works in all translation units message(STATUS "✓ gRPC GUI automation enabled for yaze_agent") diff --git a/src/cli/z3ed.cmake b/src/cli/z3ed.cmake index 44b85eae..5bfffa33 100644 --- a/src/cli/z3ed.cmake +++ b/src/cli/z3ed.cmake @@ -40,4 +40,9 @@ endif() if(YAZE_WITH_GRPC) message(STATUS "Adding gRPC support to z3ed CLI") target_link_libraries(z3ed PRIVATE grpc++ grpc++_reflection libprotobuf) + + # On Windows, force whole-archive linking for protobuf to ensure all symbols are included + if(MSVC) + target_link_options(z3ed PRIVATE /WHOLEARCHIVE:libprotobuf) + endif() endif() \ No newline at end of file