From 32017522e1065c6b4547d649711faa01ab351dc9 Mon Sep 17 00:00:00 2001 From: xiaozhuai <798047000@qq.com> Date: Mon, 31 Aug 2026 02:02:00 +0800 Subject: [PATCH] [glaze] Make asio dependency optional (#53588) --- ports/glaze/001-fix-asio.patch | 39 ++++++++++++-------- ports/glaze/portfile.cmake | 8 +++- ports/glaze/usage | 7 ++++ ports/glaze/vcpkg.json | 15 +++++++- scripts/test_ports/vcpkg-ci-glaze/vcpkg.json | 8 +++- versions/baseline.json | 2 +- versions/g-/glaze.json | 5 +++ 7 files changed, 64 insertions(+), 20 deletions(-) create mode 100644 ports/glaze/usage diff --git a/ports/glaze/001-fix-asio.patch b/ports/glaze/001-fix-asio.patch index e7766e300a..8d62a0a567 100644 --- a/ports/glaze/001-fix-asio.patch +++ b/ports/glaze/001-fix-asio.patch @@ -1,20 +1,39 @@ diff --git a/cmake/install-config.cmake.in b/cmake/install-config.cmake.in -index dbd6977f..7227a9a8 100644 +index dbd6977f..b2ea2c64 100644 --- a/cmake/install-config.cmake.in +++ b/cmake/install-config.cmake.in -@@ -10,6 +10,8 @@ if(_glaze_EETF_FORMAT) +@@ -10,6 +10,26 @@ if(_glaze_EETF_FORMAT) endif() unset(_glaze_EETF_FORMAT) -+find_dependency(asio REQUIRED) ++set(_glaze_ENABLE_NETWORKING "@glaze_ENABLE_NETWORKING@") ++if(_glaze_ENABLE_NETWORKING) ++ # vcpkg always uses standalone Asio, as declared in the port manifest. ++ # Preserve the documented networking interface without selecting Boost or ++ # downloading an undeclared dependency. ++ find_dependency(asio REQUIRED) ++ if(NOT TARGET glaze::asio) ++ add_library(glaze::asio INTERFACE IMPORTED) ++ set_property(TARGET glaze::asio PROPERTY INTERFACE_LINK_LIBRARIES asio::asio) ++ endif() ++ ++ function(glaze_setup_asio) ++ endfunction() ++else() ++ function(glaze_setup_asio) ++ message(FATAL_ERROR "glaze_setup_asio() called but glaze was built without networking support") ++ endfunction() ++endif() ++unset(_glaze_ENABLE_NETWORKING) + # Handle SSL dependency (OpenSSL) set(_glaze_ENABLE_SSL "@glaze_ENABLE_SSL@") if(_glaze_ENABLE_SSL) -@@ -19,13 +21,13 @@ unset(_glaze_ENABLE_SSL) +@@ -18,14 +38,3 @@ endif() + unset(_glaze_ENABLE_SSL) include("${CMAKE_CURRENT_LIST_DIR}/glazeTargets.cmake") - +- -# Make the Asio backend selector available to networking consumers. This only -# declares the glaze_USE_BUNDLED_ASIO option and the glaze_setup_asio() function; -# nothing is resolved until the consumer calls glaze_setup_asio() and links @@ -25,16 +44,6 @@ index dbd6977f..7227a9a8 100644 -if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/glaze-asio.cmake") - include("${CMAKE_CURRENT_LIST_DIR}/glaze-asio.cmake") -endif() -+# vcpkg always uses standalone Asio, as declared in the port manifest. -+# Preserve the documented networking interface without selecting Boost or -+# downloading an undeclared dependency. -+if(NOT TARGET glaze::asio) -+ add_library(glaze::asio INTERFACE IMPORTED) -+ set_property(TARGET glaze::asio PROPERTY INTERFACE_LINK_LIBRARIES asio::asio) -+endif() -+ -+function(glaze_setup_asio) -+endfunction() diff --git a/cmake/install-rules.cmake b/cmake/install-rules.cmake index cae895a7..42accbfc 100644 --- a/cmake/install-rules.cmake diff --git a/ports/glaze/portfile.cmake b/ports/glaze/portfile.cmake index fefddcd571..53a3c25ea1 100644 --- a/ports/glaze/portfile.cmake +++ b/ports/glaze/portfile.cmake @@ -14,7 +14,8 @@ vcpkg_from_github( vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS FEATURES - ssl glaze_ENABLE_SSL + networking glaze_ENABLE_NETWORKING + ssl glaze_ENABLE_SSL ) vcpkg_cmake_configure( @@ -29,8 +30,11 @@ vcpkg_cmake_configure( vcpkg_cmake_install() vcpkg_cmake_config_fixup() -vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/glaze/ext/glaze_asio.hpp" "#if __has_include() && !defined(GLZ_USE_BOOST_ASIO)" "#if 1") +if("networking" IN_LIST FEATURES) + vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/include/glaze/ext/glaze_asio.hpp" "#if __has_include() && !defined(GLZ_USE_BOOST_ASIO)" "#if 1") +endif() file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug") vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") +file(INSTALL "${CURRENT_PORT_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") diff --git a/ports/glaze/usage b/ports/glaze/usage new file mode 100644 index 0000000000..154e30efc2 --- /dev/null +++ b/ports/glaze/usage @@ -0,0 +1,7 @@ +glaze provides CMake targets: + + find_package(glaze CONFIG REQUIRED) + target_link_libraries(main PRIVATE glaze::glaze) + # Glaze's networking features, this requires glaze[networking] to be on + glaze_setup_asio() + target_link_libraries(main PRIVATE glaze::asio) diff --git a/ports/glaze/vcpkg.json b/ports/glaze/vcpkg.json index 6241ffa2f1..8ac9601ea7 100644 --- a/ports/glaze/vcpkg.json +++ b/ports/glaze/vcpkg.json @@ -1,12 +1,12 @@ { "name": "glaze", "version": "8.2.0", + "port-version": 1, "description": "One of the fastest JSON libraries in the world. Glaze reads and writes from C++ memory, simplifying interfaces and offering incredible performance.", "homepage": "https://github.com/stephenberry/glaze", "license": "MIT", "supports": "!uwp", "dependencies": [ - "asio", { "name": "vcpkg-cmake", "host": true @@ -17,9 +17,22 @@ } ], "features": { + "networking": { + "description": "Enable networking support", + "dependencies": [ + "asio" + ] + }, "ssl": { "description": "Enable SSL/TLS support for HTTPS servers", "dependencies": [ + { + "name": "glaze", + "default-features": false, + "features": [ + "networking" + ] + }, "openssl" ] } diff --git a/scripts/test_ports/vcpkg-ci-glaze/vcpkg.json b/scripts/test_ports/vcpkg-ci-glaze/vcpkg.json index 178780120a..edc5cc6fab 100644 --- a/scripts/test_ports/vcpkg-ci-glaze/vcpkg.json +++ b/scripts/test_ports/vcpkg-ci-glaze/vcpkg.json @@ -3,7 +3,13 @@ "version-string": "ci", "description": "Validates Glaze networking CMake integration", "dependencies": [ - "glaze", + { + "name": "glaze", + "default-features": false, + "features": [ + "networking" + ] + }, { "name": "vcpkg-cmake", "host": true diff --git a/versions/baseline.json b/versions/baseline.json index 00407b3bf3..027c3ec5c5 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -3466,7 +3466,7 @@ }, "glaze": { "baseline": "8.2.0", - "port-version": 0 + "port-version": 1 }, "glbinding": { "baseline": "3.1.0", diff --git a/versions/g-/glaze.json b/versions/g-/glaze.json index f13b765f04..03c73ff6d7 100644 --- a/versions/g-/glaze.json +++ b/versions/g-/glaze.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "8900ed8cedf36274dfc2ce646140d74fe469d378", + "version": "8.2.0", + "port-version": 1 + }, { "git-tree": "cbb70bf9b288bccae1e248bc148ec1da3a918df2", "version": "8.2.0",