1 parent
3851aeb703
commit
053ee5b296
23 files changed
+836
-84
No files matched your search
@@ -53,6 +53,11 @@ get_property(ALL_MODULE_DEPENDENCY_RECORDS GLOBAL PROPERTY
|
|||||||
|
|
||||||
set(VOID_MODULES_LIST "${ALL_DISCOVERED_MODULES}")
|
set(VOID_MODULES_LIST "${ALL_DISCOVERED_MODULES}")
|
||||||
set(VOID_MODULE_DEPENDENCY_RECORDS "${ALL_MODULE_DEPENDENCY_RECORDS}")
|
set(VOID_MODULE_DEPENDENCY_RECORDS "${ALL_MODULE_DEPENDENCY_RECORDS}")
|
||||||
|
if(WIN32 AND NOT CYGWIN)
|
||||||
|
set(VOID_BOOST_STACKTRACE_COMPONENT stacktrace_windbg)
|
||||||
|
else()
|
||||||
|
set(VOID_BOOST_STACKTRACE_COMPONENT stacktrace_addr2line)
|
||||||
|
endif()
|
||||||
|
|
||||||
write_basic_package_version_file(
|
write_basic_package_version_file(
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# Isolated completeness probe used by cmake/Dependencies.cmake. Imported
|
||||||
|
# targets created by a failed find_package stay scoped to this directory, so a
|
||||||
|
# subsequent FetchContent fallback can define its own Boost targets safely.
|
||||||
|
if(WIN32 AND NOT CYGWIN)
|
||||||
|
set(_stacktrace_component stacktrace_windbg)
|
||||||
|
else()
|
||||||
|
set(_stacktrace_component stacktrace_addr2line)
|
||||||
|
endif()
|
||||||
|
find_package(Boost CONFIG QUIET
|
||||||
|
COMPONENTS ${_stacktrace_component} url)
|
||||||
|
|
||||||
|
if(TARGET Boost::${_stacktrace_component} AND TARGET Boost::url)
|
||||||
|
set_property(GLOBAL PROPERTY VOID_COMPLETE_SYSTEM_BOOST TRUE)
|
||||||
|
endif()
|
||||||
+110
-13
@@ -1,33 +1,127 @@
|
|||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
|
function(void_ensure_boost_header_targets)
|
||||||
|
if(NOT TARGET Boost::headers AND TARGET Boost::boost)
|
||||||
|
add_library(Boost::headers INTERFACE IMPORTED)
|
||||||
|
set_property(TARGET Boost::headers PROPERTY
|
||||||
|
INTERFACE_LINK_LIBRARIES Boost::boost)
|
||||||
|
endif()
|
||||||
|
foreach(_component IN ITEMS beast asio)
|
||||||
|
if(NOT TARGET Boost::${_component} AND
|
||||||
|
TARGET boost_${_component})
|
||||||
|
add_library(Boost::${_component} ALIAS boost_${_component})
|
||||||
|
elseif(NOT TARGET Boost::${_component} AND TARGET Boost::headers)
|
||||||
|
# System Boost packages commonly expose one aggregate include
|
||||||
|
# target rather than per-header-library targets.
|
||||||
|
add_library(Boost::${_component} INTERFACE IMPORTED)
|
||||||
|
set_property(TARGET Boost::${_component} PROPERTY
|
||||||
|
INTERFACE_LINK_LIBRARIES Boost::headers)
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(void_install_fetched_boost_runtime)
|
||||||
|
get_property(_runtime_registered GLOBAL
|
||||||
|
PROPERTY VOID_FETCHED_BOOST_RUNTIME_REGISTERED)
|
||||||
|
if(_runtime_registered)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
set_property(GLOBAL PROPERTY VOID_FETCHED_BOOST_RUNTIME_REGISTERED TRUE)
|
||||||
|
|
||||||
|
# Boost disables its install rules when consumed through add_subdirectory.
|
||||||
|
# Register the selected shared runtime closure explicitly so an installed
|
||||||
|
# shared Void package never points back into its build tree.
|
||||||
|
foreach(_target IN ITEMS
|
||||||
|
boost_container
|
||||||
|
boost_context
|
||||||
|
boost_coroutine
|
||||||
|
boost_date_time
|
||||||
|
boost_stacktrace_addr2line
|
||||||
|
boost_stacktrace_windbg
|
||||||
|
boost_url)
|
||||||
|
if(TARGET ${_target})
|
||||||
|
get_target_property(_type ${_target} TYPE)
|
||||||
|
if(_type STREQUAL "SHARED_LIBRARY" OR
|
||||||
|
_type STREQUAL "MODULE_LIBRARY")
|
||||||
|
if(UNIX)
|
||||||
|
set_property(TARGET ${_target} PROPERTY
|
||||||
|
INSTALL_RPATH "$ORIGIN")
|
||||||
|
endif()
|
||||||
|
install(TARGETS ${_target}
|
||||||
|
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||||
|
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
function(void_fetch_dependency DEP_NAME)
|
function(void_fetch_dependency DEP_NAME)
|
||||||
if(DEP_NAME STREQUAL "Boost")
|
if(DEP_NAME STREQUAL "Boost")
|
||||||
# Components Void uses across modules: stacktrace_backtrace (Stacktrace),
|
if(WIN32 AND NOT CYGWIN)
|
||||||
# url + system (Net; beast/asio are header-only and come via Boost::headers).
|
set(_stacktrace_component stacktrace_windbg)
|
||||||
if(TARGET Boost::stacktrace_backtrace AND TARGET Boost::url)
|
else()
|
||||||
|
set(_stacktrace_component stacktrace_addr2line)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Components Void uses across modules: a platform Stacktrace backend,
|
||||||
|
# plus url, beast, and asio (Net).
|
||||||
|
if(TARGET Boost::${_stacktrace_component} AND TARGET Boost::url)
|
||||||
|
void_ensure_boost_header_targets()
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# On modern Boost (1.85+) system/asio/beast are header-only and folded
|
# Probe in a child directory because a failed component-aware
|
||||||
# into Boost::headers; only stacktrace_backtrace and url are components.
|
# find_package(Boost) can still leave partial imported targets such as
|
||||||
find_package(Boost QUIET COMPONENTS stacktrace_backtrace url)
|
# Boost::headers in its directory scope. Those partial targets collide
|
||||||
if(TARGET Boost::stacktrace_backtrace AND TARGET Boost::url)
|
# with Boost's FetchContent build. Imported targets created by this
|
||||||
|
# probe stay in the child scope; only a boolean result is exported.
|
||||||
|
get_property(_boost_probe_ran GLOBAL
|
||||||
|
PROPERTY VOID_COMPLETE_SYSTEM_BOOST SET)
|
||||||
|
if(NOT _boost_probe_ran)
|
||||||
|
set_property(GLOBAL PROPERTY VOID_COMPLETE_SYSTEM_BOOST FALSE)
|
||||||
|
add_subdirectory(
|
||||||
|
"${CMAKE_CURRENT_FUNCTION_LIST_DIR}/BoostProbe"
|
||||||
|
"${PROJECT_BINARY_DIR}/void-boost-probe"
|
||||||
|
EXCLUDE_FROM_ALL)
|
||||||
|
endif()
|
||||||
|
get_property(_complete_system_boost GLOBAL
|
||||||
|
PROPERTY VOID_COMPLETE_SYSTEM_BOOST)
|
||||||
|
if(_complete_system_boost)
|
||||||
|
# On modern Boost, beast/asio are header-only and folded into
|
||||||
|
# Boost::headers. The fetched Asio target carries its own System
|
||||||
|
# dependency; requiring a separate system component here rejects
|
||||||
|
# otherwise complete distro packages where Boost.System is folded
|
||||||
|
# into Boost::headers.
|
||||||
|
find_package(Boost CONFIG REQUIRED
|
||||||
|
COMPONENTS ${_stacktrace_component} url)
|
||||||
|
void_ensure_boost_header_targets()
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(TARGET Boost::headers OR TARGET Boost::boost)
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"[Void] Incomplete Boost targets already exist in the parent "
|
||||||
|
"project. Provide ${_stacktrace_component} and url before "
|
||||||
|
"adding Void, or let Void resolve Boost first.")
|
||||||
|
endif()
|
||||||
|
|
||||||
message(STATUS "[Void] Boost (stacktrace/url) not found — falling back to FetchContent")
|
message(STATUS "[Void] Boost (stacktrace/url) not found — falling back to FetchContent")
|
||||||
set(BOOST_INCLUDE_LIBRARIES "stacktrace;url;system;beast;asio" CACHE STRING "" FORCE)
|
# Keep Boost's selection local to this dependency resolution. Avoid
|
||||||
set(BOOST_ENABLE_CMAKE ON CACHE BOOL "" FORCE)
|
# overwriting a parent project's cache when Void is embedded.
|
||||||
|
set(BOOST_INCLUDE_LIBRARIES "stacktrace;url;system;beast;asio")
|
||||||
FetchContent_Declare(Boost
|
FetchContent_Declare(Boost
|
||||||
URL https://github.com/boostorg/boost/releases/download/boost-1.84.0/boost-1.84.0.tar.xz
|
URL https://github.com/boostorg/boost/releases/download/boost-1.84.0/boost-1.84.0.tar.xz
|
||||||
URL_HASH SHA256=2e64e5d79a738d0fa6fb546c6e5c2bd28f88d268a2a080546f74e5ff98f29d0e
|
URL_HASH SHA256=2e64e5d79a738d0fa6fb546c6e5c2bd28f88d268a2a080546f74e5ff98f29d0e
|
||||||
EXCLUDE_FROM_ALL
|
|
||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(Boost)
|
FetchContent_MakeAvailable(Boost)
|
||||||
|
|
||||||
if(NOT TARGET Boost::stacktrace_backtrace AND TARGET boost_stacktrace_backtrace)
|
if(NOT TARGET Boost::${_stacktrace_component} AND
|
||||||
add_library(Boost::stacktrace_backtrace ALIAS boost_stacktrace_backtrace)
|
TARGET boost_${_stacktrace_component})
|
||||||
|
add_library(Boost::${_stacktrace_component}
|
||||||
|
ALIAS boost_${_stacktrace_component})
|
||||||
endif()
|
endif()
|
||||||
|
void_ensure_boost_header_targets()
|
||||||
|
void_install_fetched_boost_runtime()
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -47,9 +141,12 @@ function(void_fetch_dependency DEP_NAME)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(DEP_NAME STREQUAL "SQLite3")
|
if(DEP_NAME STREQUAL "SQLite3")
|
||||||
if(NOT TARGET SQLite3::SQLite3)
|
if(NOT TARGET SQLite3::SQLite3 AND NOT TARGET SQLite::SQLite3)
|
||||||
find_package(SQLite3 REQUIRED)
|
find_package(SQLite3 REQUIRED)
|
||||||
endif()
|
endif()
|
||||||
|
if(NOT TARGET SQLite3::SQLite3 AND TARGET SQLite::SQLite3)
|
||||||
|
add_library(SQLite3::SQLite3 ALIAS SQLite::SQLite3)
|
||||||
|
endif()
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
+71
-1
@@ -35,15 +35,42 @@ function(void_add_module MODULE_NAME)
|
|||||||
target_sources(${TGT} PRIVATE ${SRC})
|
target_sources(${TGT} PRIVATE ${SRC})
|
||||||
target_compile_features(${TGT} PUBLIC cxx_std_26)
|
target_compile_features(${TGT} PUBLIC cxx_std_26)
|
||||||
endif()
|
endif()
|
||||||
|
get_target_property(_module_target_type ${TGT} TYPE)
|
||||||
|
if(_module_target_type STREQUAL "SHARED_LIBRARY" OR
|
||||||
|
_module_target_type STREQUAL "MODULE_LIBRARY")
|
||||||
|
# External packages are implementation details of compiled shared
|
||||||
|
# modules: Void's installed public headers do not expose their types.
|
||||||
|
# Keeping these links private also lets a shared Void SDK carry a
|
||||||
|
# fetched runtime dependency without requiring that dependency's CMake
|
||||||
|
# development package on every consumer machine.
|
||||||
|
set(_external_scope PRIVATE)
|
||||||
|
set(_record_external_dependencies FALSE)
|
||||||
|
else()
|
||||||
|
set(_external_scope ${SCOPE})
|
||||||
|
set(_record_external_dependencies TRUE)
|
||||||
|
endif()
|
||||||
add_library(${ALIAS} ALIAS ${TGT})
|
add_library(${ALIAS} ALIAS ${TGT})
|
||||||
|
|
||||||
set_property(GLOBAL APPEND PROPERTY VOID_MODULES ${MODULE_NAME})
|
set_property(GLOBAL APPEND PROPERTY VOID_MODULES ${MODULE_NAME})
|
||||||
set(_module_external_deps "")
|
set(_module_external_deps "")
|
||||||
foreach(ext_dep IN LISTS ARG_EXTERNAL_DEPS)
|
foreach(ext_dep IN LISTS ARG_EXTERNAL_DEPS)
|
||||||
|
# FindSQLite3's package name and imported-target namespace differ.
|
||||||
|
# Preserve the package name in exported dependency metadata.
|
||||||
|
if(ext_dep MATCHES "^SQLite::")
|
||||||
|
set(BASE_DEP SQLite3)
|
||||||
|
else()
|
||||||
string(REGEX REPLACE "::.*" "" BASE_DEP ${ext_dep})
|
string(REGEX REPLACE "::.*" "" BASE_DEP ${ext_dep})
|
||||||
|
endif()
|
||||||
|
if(_record_external_dependencies)
|
||||||
list(APPEND _module_external_deps ${BASE_DEP})
|
list(APPEND _module_external_deps ${BASE_DEP})
|
||||||
|
endif()
|
||||||
include(cmake/Dependencies.cmake)
|
include(cmake/Dependencies.cmake)
|
||||||
void_fetch_dependency(${BASE_DEP})
|
void_fetch_dependency(${BASE_DEP})
|
||||||
|
if(NOT TARGET ${ext_dep})
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"[Void] Dependency '${ext_dep}' required by module "
|
||||||
|
"'${MODULE_NAME}' was not provided")
|
||||||
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
set(_module_internal_deps ${ARG_INTERNAL_DEPS} ${ARG_OPTIONAL_DEPS})
|
set(_module_internal_deps ${ARG_INTERNAL_DEPS} ${ARG_OPTIONAL_DEPS})
|
||||||
@@ -78,7 +105,41 @@ function(void_add_module MODULE_NAME)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(ARG_EXTERNAL_DEPS)
|
if(ARG_EXTERNAL_DEPS)
|
||||||
target_link_libraries(${TGT} ${SCOPE} ${ARG_EXTERNAL_DEPS})
|
if(_external_scope STREQUAL "PRIVATE")
|
||||||
|
foreach(_external_dep IN LISTS ARG_EXTERNAL_DEPS)
|
||||||
|
string(MAKE_C_IDENTIFIER "${_external_dep}"
|
||||||
|
_external_dep_identifier)
|
||||||
|
set(_build_external_target
|
||||||
|
"_void_${MODULE_NAME}_${_external_dep_identifier}")
|
||||||
|
add_library(${_build_external_target} INTERFACE IMPORTED)
|
||||||
|
set_property(TARGET ${_build_external_target} PROPERTY
|
||||||
|
INTERFACE_LINK_LIBRARIES "${_external_dep}")
|
||||||
|
target_link_libraries(${TGT} PRIVATE
|
||||||
|
"$<BUILD_INTERFACE:${_build_external_target}>")
|
||||||
|
endforeach()
|
||||||
|
else()
|
||||||
|
# Keep fetched dependency build targets out of Void's install
|
||||||
|
# export. Static and interface consumers still receive the same
|
||||||
|
# canonical targets after find_dependency().
|
||||||
|
foreach(_external_dep IN LISTS ARG_EXTERNAL_DEPS)
|
||||||
|
string(MAKE_C_IDENTIFIER "${_external_dep}"
|
||||||
|
_external_dep_identifier)
|
||||||
|
set(_build_external_target
|
||||||
|
"_void_${MODULE_NAME}_${_external_dep_identifier}")
|
||||||
|
add_library(${_build_external_target} INTERFACE IMPORTED)
|
||||||
|
set_property(TARGET ${_build_external_target} PROPERTY
|
||||||
|
INTERFACE_LINK_LIBRARIES "${_external_dep}")
|
||||||
|
# Defer namespace reconstruction until a consumer evaluates
|
||||||
|
# the installed target. Otherwise CMake canonicalizes aliases
|
||||||
|
# from a FetchContent dependency (Boost::url -> boost_url) and
|
||||||
|
# requires the third-party target in Void's export set.
|
||||||
|
string(REPLACE "::" "$<1:::>" _install_external_dep
|
||||||
|
"${_external_dep}")
|
||||||
|
target_link_libraries(${TGT} ${_external_scope}
|
||||||
|
"$<BUILD_INTERFACE:${_build_external_target}>"
|
||||||
|
"$<INSTALL_INTERFACE:${_install_external_dep}>")
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
foreach(_lib IN LISTS ARG_DEPS_WIN32)
|
foreach(_lib IN LISTS ARG_DEPS_WIN32)
|
||||||
@@ -140,6 +201,15 @@ function(void_add_module MODULE_NAME)
|
|||||||
CXX_EXTENSIONS OFF
|
CXX_EXTENSIONS OFF
|
||||||
EXPORT_NAME ${MODULE_NAME}
|
EXPORT_NAME ${MODULE_NAME}
|
||||||
)
|
)
|
||||||
|
if(UNIX AND _module_target_type STREQUAL "SHARED_LIBRARY")
|
||||||
|
set_property(TARGET ${TGT} PROPERTY INSTALL_RPATH "$ORIGIN")
|
||||||
|
endif()
|
||||||
|
if(WIN32 AND _module_target_type STREQUAL "SHARED_LIBRARY")
|
||||||
|
# Void's public headers do not require consumers to opt into a DLL
|
||||||
|
# import macro. Generate the export table for compiled shared modules
|
||||||
|
# so the same installed targets remain usable on Windows.
|
||||||
|
set_property(TARGET ${TGT} PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
# GCC 16+ exposes experimental C++26 reflection (P2996) via -freflection.
|
# GCC 16+ exposes experimental C++26 reflection (P2996) via -freflection.
|
||||||
# Apply it to every module unconditionally so any module is free to use
|
# Apply it to every module unconditionally so any module is free to use
|
||||||
|
|||||||
@@ -64,7 +64,20 @@ if(_void_external_deps)
|
|||||||
endif()
|
endif()
|
||||||
foreach(dep IN LISTS _void_external_deps)
|
foreach(dep IN LISTS _void_external_deps)
|
||||||
if(dep STREQUAL "Boost")
|
if(dep STREQUAL "Boost")
|
||||||
find_dependency(Boost REQUIRED COMPONENTS stacktrace_backtrace url)
|
find_dependency(Boost CONFIG REQUIRED COMPONENTS
|
||||||
|
@VOID_BOOST_STACKTRACE_COMPONENT@ url)
|
||||||
|
if(NOT TARGET Boost::headers AND TARGET Boost::boost)
|
||||||
|
add_library(Boost::headers INTERFACE IMPORTED)
|
||||||
|
set_property(TARGET Boost::headers PROPERTY
|
||||||
|
INTERFACE_LINK_LIBRARIES Boost::boost)
|
||||||
|
endif()
|
||||||
|
foreach(_component IN ITEMS beast asio)
|
||||||
|
if(NOT TARGET Boost::${_component} AND TARGET Boost::headers)
|
||||||
|
add_library(Boost::${_component} INTERFACE IMPORTED)
|
||||||
|
set_property(TARGET Boost::${_component} PROPERTY
|
||||||
|
INTERFACE_LINK_LIBRARIES Boost::headers)
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
elseif(dep STREQUAL "Sodium")
|
elseif(dep STREQUAL "Sodium")
|
||||||
find_dependency(PkgConfig REQUIRED)
|
find_dependency(PkgConfig REQUIRED)
|
||||||
pkg_check_modules(SODIUM REQUIRED IMPORTED_TARGET libsodium)
|
pkg_check_modules(SODIUM REQUIRED IMPORTED_TARGET libsodium)
|
||||||
@@ -75,6 +88,11 @@ foreach(dep IN LISTS _void_external_deps)
|
|||||||
endif()
|
endif()
|
||||||
elseif(dep STREQUAL "LibArchive")
|
elseif(dep STREQUAL "LibArchive")
|
||||||
find_dependency(LibArchive REQUIRED)
|
find_dependency(LibArchive REQUIRED)
|
||||||
|
elseif(dep STREQUAL "SQLite3")
|
||||||
|
find_dependency(SQLite3 REQUIRED)
|
||||||
|
if(NOT TARGET SQLite3::SQLite3 AND TARGET SQLite::SQLite3)
|
||||||
|
add_library(SQLite3::SQLite3 ALIAS SQLite::SQLite3)
|
||||||
|
endif()
|
||||||
elseif(NOT TARGET ${dep})
|
elseif(NOT TARGET ${dep})
|
||||||
find_dependency(${dep})
|
find_dependency(${dep})
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -51,7 +51,11 @@ foreach(line IN LISTS lines)
|
|||||||
if(_match)
|
if(_match)
|
||||||
string(REGEX REPLACE "^[ \t]*class[ \t]+([A-Za-z_][A-Za-z0-9_]*)[ \t]*:.*" "\\1" fixture_class_name "${line}")
|
string(REGEX REPLACE "^[ \t]*class[ \t]+([A-Za-z_][A-Za-z0-9_]*)[ \t]*:.*" "\\1" fixture_class_name "${line}")
|
||||||
set(in_fixture_class TRUE)
|
set(in_fixture_class TRUE)
|
||||||
string(REGEX MATCH "^[ \t]*" fixture_indent "${line}")
|
# Derive indentation without an empty-match-capable regex. CMake 4
|
||||||
|
# rejects such expressions even when the current input is non-empty.
|
||||||
|
string(STRIP "${line}" _trimmed_fixture_line)
|
||||||
|
string(FIND "${line}" "${_trimmed_fixture_line}" _indent_length)
|
||||||
|
string(SUBSTRING "${line}" 0 ${_indent_length} fixture_indent)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(in_fixture_class)
|
if(in_fixture_class)
|
||||||
@@ -127,8 +131,17 @@ foreach(line IN LISTS lines)
|
|||||||
set(current_skip "")
|
set(current_skip "")
|
||||||
else()
|
else()
|
||||||
# If line is code (not comment/empty), break the comment association
|
# If line is code (not comment/empty), break the comment association
|
||||||
string(REGEX MATCH "^[ \t]*$" _is_empty "${line}")
|
string(STRIP "${line}" _stripped_line)
|
||||||
string(REGEX MATCH "^[ \t]*//" _is_comment "${line}")
|
if(_stripped_line STREQUAL "")
|
||||||
|
set(_is_empty TRUE)
|
||||||
|
else()
|
||||||
|
set(_is_empty FALSE)
|
||||||
|
endif()
|
||||||
|
if(line MATCHES "^[ \t]*//")
|
||||||
|
set(_is_comment TRUE)
|
||||||
|
else()
|
||||||
|
set(_is_comment FALSE)
|
||||||
|
endif()
|
||||||
if(NOT _is_empty AND NOT _is_comment)
|
if(NOT _is_empty AND NOT _is_comment)
|
||||||
set(current_tags "")
|
set(current_tags "")
|
||||||
set(current_skip "")
|
set(current_skip "")
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
# Short URL service
|
||||||
|
|
||||||
|
Void::ShortUrl::IShortener is a provider-neutral ABI-v1 service for creating
|
||||||
|
short URLs and, when supported, resolving their keys. It has no dependency on
|
||||||
|
Echoion or any specific HTTP provider.
|
||||||
|
|
||||||
|
Implementations derive from IShortener and can be registered directly in a
|
||||||
|
Void::Service::ServiceRegistry. Plugin implementations export the standard
|
||||||
|
void_plugin_service(void*) symbol and are bound with
|
||||||
|
Void::Service::PluginServiceBinding<Void::ShortUrl::IShortener>.
|
||||||
|
|
||||||
|
The versioned contract lives in Void::ShortUrl::V1; aliases in Void::ShortUrl
|
||||||
|
select the current ABI. Implementations report a provider identifier and health
|
||||||
|
status. An empty custom key asks the provider to generate one, and an expiry of
|
||||||
|
zero means permanent.
|
||||||
|
|
||||||
|
Keep the returned shared pointer for the complete operation. That pin guarantees
|
||||||
|
the implementation and its shared object remain alive during plugin reload.
|
||||||
|
resolve() intentionally defaults to not_supported, which permits providers
|
||||||
|
backed by external APIs that cannot reverse a short link.
|
||||||
|
|
||||||
|
V1 is frozen: enum ordinals, data-member order, and virtual method order must
|
||||||
|
not change after release. Incompatible evolution is introduced as V2 with a
|
||||||
|
new service interface. Because the ABI carries C++ standard-library values,
|
||||||
|
host and provider must use the same C++ runtime and the exact toolchain
|
||||||
|
contract recorded by the application release.
|
||||||
|
|
||||||
|
A provider must either honor a non-empty custom key and non-zero expiry or
|
||||||
|
return unsupported/conflict; silently ignoring either request is invalid.
|
||||||
@@ -49,6 +49,11 @@ namespace Void::Plugin
|
|||||||
[[nodiscard]] explicit operator bool() const noexcept;
|
[[nodiscard]] explicit operator bool() const noexcept;
|
||||||
|
|
||||||
[[nodiscard]] const PluginInfo& info() const noexcept;
|
[[nodiscard]] const PluginInfo& info() const noexcept;
|
||||||
|
/// Resolve an optional symbol from the exact shared object pinned
|
||||||
|
/// by this handle. The returned address remains valid while the
|
||||||
|
/// handle is alive, even if the manager concurrently reloads the
|
||||||
|
/// plugin.
|
||||||
|
[[nodiscard]] void* raw_symbol(const char* symbol) const noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,10 @@
|
|||||||
#include <Void/Service/Registry.hpp>
|
#include <Void/Service/Registry.hpp>
|
||||||
#include <Void/Service/Service.hpp>
|
#include <Void/Service/Service.hpp>
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
@@ -17,8 +20,8 @@ namespace Void::Service
|
|||||||
/// extern "C" Void::Service::IService* void_plugin_service(void* inst);
|
/// extern "C" Void::Service::IService* void_plugin_service(void* inst);
|
||||||
/// It returns the IService subobject of the plugin's service object
|
/// It returns the IService subobject of the plugin's service object
|
||||||
/// (which must derive the host interface I, and I must derive
|
/// (which must derive the host interface I, and I must derive
|
||||||
/// IService). The host recovers I* by static_cast — no dynamic_cast, so
|
/// IService). The host verifies the exported subobject with dynamic_cast;
|
||||||
/// it is robust across RTLD_LOCAL plugin boundaries.
|
/// host and provider must therefore share RTTI identity for I.
|
||||||
using service_factory_fn = IService* (*)(void* instance);
|
using service_factory_fn = IService* (*)(void* instance);
|
||||||
|
|
||||||
inline constexpr const char* kServiceSymbol = "void_plugin_service";
|
inline constexpr const char* kServiceSymbol = "void_plugin_service";
|
||||||
@@ -32,23 +35,28 @@ namespace Void::Service
|
|||||||
/// callers never see a freed object.
|
/// callers never see a freed object.
|
||||||
///
|
///
|
||||||
/// Requires: I derives Void::Service::IService; the plugin's service
|
/// Requires: I derives Void::Service::IService; the plugin's service
|
||||||
/// type derives I; the plugin exports void_plugin_service.
|
/// type derives I; the plugin exports void_plugin_service. RTTI identity
|
||||||
|
/// for I must be shared by host and provider, just like PluginManager's
|
||||||
|
/// host-specific instance_validator interfaces.
|
||||||
template <typename I> class PluginServiceBinding
|
template <typename I> class PluginServiceBinding
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static_assert(std::is_base_of_v<IService, I>,
|
static_assert(std::is_base_of_v<IService, I>,
|
||||||
"plugin service interface must derive IService");
|
"plugin service interface must derive IService");
|
||||||
|
using Validator =
|
||||||
|
std::function<bool(const std::shared_ptr<I>& service)>;
|
||||||
|
|
||||||
PluginServiceBinding(Plugin::PluginManager& manager,
|
PluginServiceBinding(Plugin::PluginManager& manager,
|
||||||
ServiceRegistry& registry, std::string name)
|
ServiceRegistry& registry, std::string name,
|
||||||
: m_manager(&manager), m_registry(®istry),
|
Validator validator = {})
|
||||||
m_name(std::move(name))
|
: m_state(std::make_shared<State>(
|
||||||
|
manager, registry, std::move(name), std::move(validator)))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
// The reload callback captures `this`; the binding must
|
// Lifecycle registration cannot be transferred while callbacks may
|
||||||
// deregister it before dying and therefore cannot move.
|
// be in flight.
|
||||||
PluginServiceBinding(const PluginServiceBinding&) = delete;
|
PluginServiceBinding(const PluginServiceBinding&) = delete;
|
||||||
PluginServiceBinding&
|
PluginServiceBinding&
|
||||||
operator=(const PluginServiceBinding&) = delete;
|
operator=(const PluginServiceBinding&) = delete;
|
||||||
@@ -56,65 +64,181 @@ namespace Void::Service
|
|||||||
~PluginServiceBinding() { disable_hot_reload(); }
|
~PluginServiceBinding() { disable_hot_reload(); }
|
||||||
|
|
||||||
/// Resolve the current instance's service and (re)register it.
|
/// Resolve the current instance's service and (re)register it.
|
||||||
[[nodiscard]] bool bind()
|
[[nodiscard]] bool bind() noexcept { return m_state->bind(); }
|
||||||
{
|
|
||||||
auto handle = m_manager->acquire(m_name);
|
|
||||||
if (!handle) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
auto* fn = reinterpret_cast<service_factory_fn>(
|
|
||||||
m_manager->raw_symbol(m_name, kServiceSymbol));
|
|
||||||
if (fn == nullptr) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
IService* base = fn(handle.get());
|
|
||||||
if (base == nullptr) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
I* iface = static_cast<I*>(base); // I : IService
|
|
||||||
|
|
||||||
// Keep the plugin instance (and its mapped .so) alive for
|
|
||||||
// as long as the registry holds this service.
|
|
||||||
auto owner = std::make_shared<Plugin::PluginHandle>(handle);
|
|
||||||
std::shared_ptr<I> pinned(std::move(owner), iface);
|
|
||||||
m_registry->provide<I>(std::move(pinned));
|
|
||||||
Void::Log::debug("Service.Plugin",
|
|
||||||
"bound service from plugin '{}'", m_name);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Auto-rebind on hot reload (debounced file watching). The
|
/// Auto-rebind on hot reload (debounced file watching). The
|
||||||
/// manager keeps old instances alive while pinned, so the swap
|
/// manager keeps old instances alive while pinned, so the swap
|
||||||
/// is seamless. Idempotent.
|
/// is seamless. Idempotent.
|
||||||
void enable_hot_reload()
|
void enable_hot_reload()
|
||||||
{
|
{
|
||||||
|
std::lock_guard lifecycleLock{m_lifecycleMutex};
|
||||||
if (m_reload_id != 0) {
|
if (m_reload_id != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_reload_id =
|
m_state->set_hot_reload_enabled(true);
|
||||||
m_manager->on_reloaded([this](std::string_view name) {
|
try {
|
||||||
if (name == m_name) {
|
std::weak_ptr<State> weakState{m_state};
|
||||||
(void)bind();
|
m_reload_id = m_state->manager().on_reloaded(
|
||||||
|
[weakState](std::string_view name) noexcept {
|
||||||
|
if (auto state = weakState.lock()) {
|
||||||
|
state->rebind(name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
m_manager->watch(m_name);
|
m_state->manager().watch(m_state->name());
|
||||||
|
} catch (...) {
|
||||||
|
m_state->set_hot_reload_enabled(false);
|
||||||
|
if (m_reload_id != 0) {
|
||||||
|
m_state->manager().remove_on_reloaded(m_reload_id);
|
||||||
|
m_reload_id = 0;
|
||||||
|
}
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stop observing reloads (the file watch itself is shared and
|
/// Stop observing reloads (the file watch itself is shared and
|
||||||
/// stays). Idempotent; called by the destructor.
|
/// stays). Idempotent; called by the destructor.
|
||||||
void disable_hot_reload()
|
void disable_hot_reload() noexcept
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
|
std::lock_guard lifecycleLock{m_lifecycleMutex};
|
||||||
|
m_state->set_hot_reload_enabled(false);
|
||||||
if (m_reload_id != 0) {
|
if (m_reload_id != 0) {
|
||||||
m_manager->remove_on_reloaded(m_reload_id);
|
m_state->manager().remove_on_reloaded(m_reload_id);
|
||||||
m_reload_id = 0;
|
m_reload_id = 0;
|
||||||
}
|
}
|
||||||
|
} catch (...) {
|
||||||
|
// Destruction must remain noexcept. The weak callback
|
||||||
|
// cannot keep State alive after m_state is released even if
|
||||||
|
// observer removal itself reports a failure.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
class State
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
State(Plugin::PluginManager& manager,
|
||||||
|
ServiceRegistry& registry, std::string name,
|
||||||
|
Validator validator)
|
||||||
|
: m_manager(&manager), m_registry(®istry),
|
||||||
|
m_name(std::move(name)),
|
||||||
|
m_validator(std::move(validator))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool bind() noexcept
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
std::lock_guard lock{m_mutex};
|
||||||
|
return bind_locked();
|
||||||
|
} catch (...) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void rebind(std::string_view name) noexcept
|
||||||
|
{
|
||||||
|
if (name != m_name) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
std::lock_guard lock{m_mutex};
|
||||||
|
if (m_hotReloadEnabled) {
|
||||||
|
(void)bind_locked();
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_hot_reload_enabled(bool enabled)
|
||||||
|
{
|
||||||
|
std::lock_guard lock{m_mutex};
|
||||||
|
m_hotReloadEnabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] Plugin::PluginManager&
|
||||||
|
manager() const noexcept
|
||||||
|
{
|
||||||
|
return *m_manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] const std::string& name() const noexcept
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
[[nodiscard]] bool bind_locked() noexcept
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
auto handle = m_manager->acquire(m_name);
|
||||||
|
if (!handle) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
auto* factory =
|
||||||
|
reinterpret_cast<service_factory_fn>(
|
||||||
|
handle.raw_symbol(kServiceSymbol));
|
||||||
|
if (factory == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
IService* base = factory(handle.get());
|
||||||
|
if (base == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
I* iface = dynamic_cast<I*>(base);
|
||||||
|
if (iface == nullptr) {
|
||||||
|
Void::Log::warn(
|
||||||
|
"Service.Plugin",
|
||||||
|
"plugin '{}' exported an incompatible "
|
||||||
|
"service interface",
|
||||||
|
m_name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pin the exact instance and shared object that
|
||||||
|
// supplied the factory and service subobject.
|
||||||
|
auto owner = std::make_shared<Plugin::PluginHandle>(
|
||||||
|
std::move(handle));
|
||||||
|
std::shared_ptr<I> pinned(std::move(owner), iface);
|
||||||
|
if (m_validator && !m_validator(pinned)) {
|
||||||
|
Void::Log::warn(
|
||||||
|
"Service.Plugin",
|
||||||
|
"plugin '{}' service validation failed",
|
||||||
|
m_name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
m_registry->provide<I>(std::move(pinned));
|
||||||
|
Void::Log::debug("Service.Plugin",
|
||||||
|
"bound service from plugin '{}'",
|
||||||
|
m_name);
|
||||||
|
return true;
|
||||||
|
} catch (const std::exception& error) {
|
||||||
|
Void::Log::warn(
|
||||||
|
"Service.Plugin",
|
||||||
|
"binding service from plugin '{}' threw: {}",
|
||||||
|
m_name, error.what());
|
||||||
|
} catch (...) {
|
||||||
|
Void::Log::warn(
|
||||||
|
"Service.Plugin",
|
||||||
|
"binding service from plugin '{}' threw",
|
||||||
|
m_name);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Plugin::PluginManager* m_manager;
|
Plugin::PluginManager* m_manager;
|
||||||
ServiceRegistry* m_registry;
|
ServiceRegistry* m_registry;
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
|
Validator m_validator;
|
||||||
|
std::mutex m_mutex;
|
||||||
|
bool m_hotReloadEnabled{false};
|
||||||
|
};
|
||||||
|
|
||||||
|
std::shared_ptr<State> m_state;
|
||||||
|
std::mutex m_lifecycleMutex;
|
||||||
Plugin::ReloadCallbackId m_reload_id{0};
|
Plugin::ReloadCallbackId m_reload_id{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,165 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Void/Service/Service.hpp>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
namespace Void::ShortUrl::V1
|
||||||
|
{
|
||||||
|
inline constexpr std::string_view kServiceId{"void.short-url"};
|
||||||
|
inline constexpr std::uint32_t kServiceVersion{1};
|
||||||
|
|
||||||
|
enum class ErrorCode : std::uint32_t {
|
||||||
|
none = 0,
|
||||||
|
invalid_request,
|
||||||
|
unsupported,
|
||||||
|
not_found,
|
||||||
|
expired,
|
||||||
|
conflict,
|
||||||
|
unauthorized,
|
||||||
|
rate_limited,
|
||||||
|
timeout,
|
||||||
|
unavailable,
|
||||||
|
provider_error,
|
||||||
|
internal_error,
|
||||||
|
invalid_url,
|
||||||
|
revoked,
|
||||||
|
storage,
|
||||||
|
response_too_large,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Error {
|
||||||
|
ErrorCode code{ErrorCode::none};
|
||||||
|
std::string message;
|
||||||
|
std::uint32_t retry_after_seconds{0};
|
||||||
|
|
||||||
|
[[nodiscard]] bool ok() const noexcept
|
||||||
|
{
|
||||||
|
return code == ErrorCode::none;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] explicit operator bool() const noexcept
|
||||||
|
{
|
||||||
|
return !ok();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ShortenRequest {
|
||||||
|
std::string target_url;
|
||||||
|
std::string custom_key;
|
||||||
|
std::int64_t expires_at_unix_seconds{0};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ShortenResult {
|
||||||
|
std::string short_url;
|
||||||
|
std::string key;
|
||||||
|
std::int64_t expires_at_unix_seconds{0};
|
||||||
|
Error error;
|
||||||
|
|
||||||
|
[[nodiscard]] bool ok() const noexcept
|
||||||
|
{
|
||||||
|
return error.ok() && !short_url.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] explicit operator bool() const noexcept
|
||||||
|
{
|
||||||
|
return ok();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class HealthStatus : std::uint32_t {
|
||||||
|
unknown = 0,
|
||||||
|
healthy,
|
||||||
|
degraded,
|
||||||
|
unhealthy,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Health {
|
||||||
|
HealthStatus status{HealthStatus::unknown};
|
||||||
|
std::string message;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ResolveRequest {
|
||||||
|
std::string key;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ResolveResult {
|
||||||
|
std::string target_url;
|
||||||
|
std::int64_t expires_at_unix_seconds{0};
|
||||||
|
Error error;
|
||||||
|
|
||||||
|
[[nodiscard]] bool ok() const noexcept
|
||||||
|
{
|
||||||
|
return error.ok() && !target_url.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] explicit operator bool() const noexcept
|
||||||
|
{
|
||||||
|
return ok();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class IShortener : public Service::IService
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
~IShortener() override = default;
|
||||||
|
|
||||||
|
[[nodiscard]] std::string_view service_name() const final
|
||||||
|
{
|
||||||
|
return kServiceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] virtual std::uint32_t service_version() const noexcept
|
||||||
|
{
|
||||||
|
return kServiceVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] virtual std::string_view
|
||||||
|
provider_id() const noexcept = 0;
|
||||||
|
|
||||||
|
[[nodiscard]] virtual Health health() const = 0;
|
||||||
|
|
||||||
|
[[nodiscard]] virtual ShortenResult
|
||||||
|
shorten(const ShortenRequest& request) = 0;
|
||||||
|
|
||||||
|
[[nodiscard]] virtual bool supports_resolve() const noexcept
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] virtual ResolveResult resolve(const ResolveRequest&)
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
.target_url = {},
|
||||||
|
.expires_at_unix_seconds = 0,
|
||||||
|
.error =
|
||||||
|
{
|
||||||
|
.code = ErrorCode::unsupported,
|
||||||
|
.message =
|
||||||
|
"this shortener does not support resolution",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Void::ShortUrl::V1
|
||||||
|
|
||||||
|
namespace Void::ShortUrl
|
||||||
|
{
|
||||||
|
using V1::Error;
|
||||||
|
using V1::ErrorCode;
|
||||||
|
using V1::Health;
|
||||||
|
using V1::HealthStatus;
|
||||||
|
using V1::IShortener;
|
||||||
|
using V1::ResolveRequest;
|
||||||
|
using V1::ResolveResult;
|
||||||
|
using V1::ShortenRequest;
|
||||||
|
using V1::ShortenResult;
|
||||||
|
|
||||||
|
inline constexpr auto kServiceId = V1::kServiceId;
|
||||||
|
inline constexpr auto kServiceVersion = V1::kServiceVersion;
|
||||||
|
} // namespace Void::ShortUrl
|
||||||
@@ -103,7 +103,10 @@ template <typename T>
|
|||||||
inline void do_not_optimize(T& val) noexcept
|
inline void do_not_optimize(T& val) noexcept
|
||||||
{
|
{
|
||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
asm volatile("" : "+r,m"(val) : : "memory");
|
// A memory operand works for every object type and remains accepted by
|
||||||
|
// GCC 16, which rejects the old mixed "+r,m" alternative constraint for
|
||||||
|
// some scalar instantiations.
|
||||||
|
asm volatile("" : "+m"(val) : : "memory");
|
||||||
#else
|
#else
|
||||||
volatile T* p = &val;
|
volatile T* p = &val;
|
||||||
(void)*p;
|
(void)*p;
|
||||||
@@ -114,7 +117,7 @@ template <typename T>
|
|||||||
inline void do_not_optimize(const T& val) noexcept
|
inline void do_not_optimize(const T& val) noexcept
|
||||||
{
|
{
|
||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
asm volatile("" : : "r,m"(val) : "memory");
|
asm volatile("" : : "m"(val) : "memory");
|
||||||
#else
|
#else
|
||||||
volatile const T* p = &val;
|
volatile const T* p = &val;
|
||||||
(void)*p;
|
(void)*p;
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ void_add_module(Net
|
|||||||
INTERNAL_DEPS Functional Text
|
INTERNAL_DEPS Functional Text
|
||||||
EXTERNAL_DEPS
|
EXTERNAL_DEPS
|
||||||
Boost::headers
|
Boost::headers
|
||||||
|
Boost::beast
|
||||||
|
Boost::asio
|
||||||
Boost::url
|
Boost::url
|
||||||
OpenSSL::SSL
|
OpenSSL::SSL
|
||||||
OpenSSL::Crypto
|
OpenSSL::Crypto
|
||||||
|
|||||||
+14
-19
@@ -78,6 +78,19 @@ namespace Void::Plugin
|
|||||||
return m_pin->info;
|
return m_pin->info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* PluginHandle::raw_symbol(const char* symbol) const noexcept
|
||||||
|
{
|
||||||
|
#ifdef VOID_HAS_DLOPEN
|
||||||
|
if (!m_pin || m_pin->handle == nullptr || symbol == nullptr) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return dlsym(m_pin->handle, symbol);
|
||||||
|
#else
|
||||||
|
(void)symbol;
|
||||||
|
return nullptr;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// ── loading helpers ───────────────────────────────────────────────────
|
// ── loading helpers ───────────────────────────────────────────────────
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@@ -589,25 +602,7 @@ namespace Void::Plugin
|
|||||||
void* PluginManager::raw_symbol(std::string_view name,
|
void* PluginManager::raw_symbol(std::string_view name,
|
||||||
const char* symbol) const
|
const char* symbol) const
|
||||||
{
|
{
|
||||||
#ifdef VOID_HAS_DLOPEN
|
return acquire(name).raw_symbol(symbol);
|
||||||
std::shared_ptr<detail::Instance> inst;
|
|
||||||
{
|
|
||||||
std::lock_guard lock(m_mutex);
|
|
||||||
auto* entry = find(name);
|
|
||||||
if (entry == nullptr) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
inst = entry->current.load(std::memory_order_acquire);
|
|
||||||
}
|
|
||||||
if (!inst || inst->handle == nullptr) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return dlsym(inst->handle, symbol);
|
|
||||||
#else
|
|
||||||
(void)name;
|
|
||||||
(void)symbol;
|
|
||||||
return nullptr;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Void::Plugin
|
} // namespace Void::Plugin
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
void_add_module(ShortUrl
|
||||||
|
INTERNAL_DEPS Service
|
||||||
|
)
|
||||||
@@ -7,7 +7,6 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#define BOOST_STACKTRACE_USE_BACKTRACE
|
|
||||||
#include <boost/core/demangle.hpp>
|
#include <boost/core/demangle.hpp>
|
||||||
#include <boost/stacktrace.hpp>
|
#include <boost/stacktrace.hpp>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,17 @@
|
|||||||
|
if(WIN32 AND NOT CYGWIN)
|
||||||
|
set(_void_stacktrace_target Boost::stacktrace_windbg)
|
||||||
|
else()
|
||||||
|
set(_void_stacktrace_target Boost::stacktrace_addr2line)
|
||||||
|
endif()
|
||||||
|
|
||||||
void_add_module(Stacktrace
|
void_add_module(Stacktrace
|
||||||
INTERNAL_DEPS Functional
|
INTERNAL_DEPS Functional
|
||||||
EXTERNAL_DEPS Boost::stacktrace_backtrace
|
EXTERNAL_DEPS ${_void_stacktrace_target}
|
||||||
DEPS_WIN32 dbghelp
|
|
||||||
DEPS_UNIX dl
|
DEPS_UNIX dl
|
||||||
OPTIONS_UNIX -g -fno-omit-frame-pointer
|
OPTIONS_UNIX -g -fno-omit-frame-pointer
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(BUILD_SHARED_LIBS)
|
||||||
|
target_compile_definitions(Void_Stacktrace
|
||||||
|
PRIVATE BOOST_STACKTRACE_DYN_LINK)
|
||||||
|
endif()
|
||||||
@@ -80,6 +80,16 @@ if(_all_generated)
|
|||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
# A few fixtures construct archives and signatures through the upstream C
|
||||||
|
# APIs directly. Those are test implementation dependencies, not part of
|
||||||
|
# the public interface of Void's shared modules.
|
||||||
|
if(TARGET LibArchive::LibArchive)
|
||||||
|
target_link_libraries(VoidTests PRIVATE LibArchive::LibArchive)
|
||||||
|
endif()
|
||||||
|
if(TARGET OpenSSL::Crypto)
|
||||||
|
target_link_libraries(VoidTests PRIVATE OpenSSL::Crypto)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_test(NAME VoidTests COMMAND VoidTests)
|
add_test(NAME VoidTests COMMAND VoidTests)
|
||||||
|
|
||||||
add_test(NAME VoidInstalledComponentConsumers
|
add_test(NAME VoidInstalledComponentConsumers
|
||||||
|
|||||||
@@ -10,7 +10,10 @@
|
|||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <condition_variable>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -147,4 +150,89 @@ Void::Testing::Test internal_service_reload_migrates_and_swaps()
|
|||||||
Void::Testing::expect_eq(v2->accumulate(0), 40); // state migrated
|
Void::Testing::expect_eq(v2->accumulate(0), 40); // state migrated
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A validator rejection during the automatic reload callback must preserve
|
||||||
|
// the last accepted service instead of publishing the rejected candidate.
|
||||||
|
Void::Testing::Test plugin_service_reload_validation_preserves_last_good()
|
||||||
|
{
|
||||||
|
Void::FileSystem::TempDir tmp{"void_svcplugin_validate"};
|
||||||
|
const auto so = tmp.path() / "calc.so";
|
||||||
|
std::filesystem::copy_file(VOID_SERVICE_V1_PATH, so);
|
||||||
|
|
||||||
|
Void::Service::ServiceRegistry registry;
|
||||||
|
Void::Plugin::PluginManager plugins;
|
||||||
|
Void::Testing::expect(plugins.load(so).has_value());
|
||||||
|
|
||||||
|
Void::Service::PluginServiceBinding<VoidTest::ICalc> binding{
|
||||||
|
plugins, registry, "CalcPlugin",
|
||||||
|
[](const std::shared_ptr<VoidTest::ICalc>& service) {
|
||||||
|
return service->version() == 1;
|
||||||
|
}};
|
||||||
|
Void::Testing::expect(binding.bind());
|
||||||
|
binding.enable_hot_reload();
|
||||||
|
|
||||||
|
install(VOID_SERVICE_V2_PATH, so);
|
||||||
|
Void::Testing::expect(plugins.reload("CalcPlugin").has_value());
|
||||||
|
|
||||||
|
auto service = registry.get<VoidTest::ICalc>();
|
||||||
|
Void::Testing::expect(service != nullptr);
|
||||||
|
Void::Testing::expect_eq(service->version(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PluginManager intentionally invokes a copied callback list outside its
|
||||||
|
// mutex. Destroying a binding after that copy must make its callback inert.
|
||||||
|
Void::Testing::Test plugin_service_callback_is_safe_after_binding_destruction()
|
||||||
|
{
|
||||||
|
Void::FileSystem::TempDir tmp{"void_svcplugin_lifetime"};
|
||||||
|
const auto so = tmp.path() / "calc.so";
|
||||||
|
std::filesystem::copy_file(VOID_SERVICE_V1_PATH, so);
|
||||||
|
|
||||||
|
Void::Service::ServiceRegistry registry;
|
||||||
|
Void::Plugin::PluginManager plugins;
|
||||||
|
Void::Testing::expect(plugins.load(so).has_value());
|
||||||
|
|
||||||
|
std::mutex gateMutex;
|
||||||
|
std::condition_variable gateChanged;
|
||||||
|
bool callbackEntered = false;
|
||||||
|
bool releaseCallback = false;
|
||||||
|
const auto blocker = plugins.on_reloaded([&](std::string_view) {
|
||||||
|
std::unique_lock lock{gateMutex};
|
||||||
|
callbackEntered = true;
|
||||||
|
gateChanged.notify_all();
|
||||||
|
gateChanged.wait(lock, [&] { return releaseCallback; });
|
||||||
|
});
|
||||||
|
|
||||||
|
auto binding =
|
||||||
|
std::make_unique<Void::Service::PluginServiceBinding<VoidTest::ICalc>>(
|
||||||
|
plugins, registry, "CalcPlugin");
|
||||||
|
Void::Testing::expect(binding->bind());
|
||||||
|
binding->enable_hot_reload();
|
||||||
|
|
||||||
|
install(VOID_SERVICE_V2_PATH, so);
|
||||||
|
std::atomic<bool> reloadSucceeded{false};
|
||||||
|
std::thread reloader{[&] {
|
||||||
|
reloadSucceeded.store(plugins.reload("CalcPlugin").has_value(),
|
||||||
|
std::memory_order_release);
|
||||||
|
}};
|
||||||
|
bool callbackWasObserved = false;
|
||||||
|
{
|
||||||
|
std::unique_lock lock{gateMutex};
|
||||||
|
callbackWasObserved = gateChanged.wait_for(
|
||||||
|
lock, std::chrono::seconds{5}, [&] { return callbackEntered; });
|
||||||
|
}
|
||||||
|
binding.reset();
|
||||||
|
{
|
||||||
|
std::lock_guard lock{gateMutex};
|
||||||
|
releaseCallback = true;
|
||||||
|
}
|
||||||
|
gateChanged.notify_all();
|
||||||
|
reloader.join();
|
||||||
|
plugins.remove_on_reloaded(blocker);
|
||||||
|
Void::Testing::expect(callbackWasObserved);
|
||||||
|
Void::Testing::expect(reloadSucceeded.load(std::memory_order_acquire));
|
||||||
|
|
||||||
|
auto service = registry.get<VoidTest::ICalc>();
|
||||||
|
Void::Testing::expect(service != nullptr);
|
||||||
|
Void::Testing::expect_eq(service->version(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // service plugins available
|
#endif // service plugins available
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
cmake_minimum_required(VERSION 4.0)
|
||||||
|
project(VoidExternalConsumer LANGUAGES CXX)
|
||||||
|
|
||||||
|
find_package(Void CONFIG REQUIRED COMPONENTS
|
||||||
|
Net
|
||||||
|
Security
|
||||||
|
Sqlite
|
||||||
|
Stacktrace
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(void_external_consumer main.cpp)
|
||||||
|
target_link_libraries(void_external_consumer PRIVATE
|
||||||
|
Void::Net
|
||||||
|
Void::Security
|
||||||
|
Void::Sqlite
|
||||||
|
Void::Stacktrace
|
||||||
|
)
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
|
add_test(NAME VoidExternalConsumer COMMAND void_external_consumer)
|
||||||
Vendored
+19
@@ -0,0 +1,19 @@
|
|||||||
|
#include <Void/Net/Url.hpp>
|
||||||
|
#include <Void/Security/Security.hpp>
|
||||||
|
#include <Void/Sqlite/Sqlite.hpp>
|
||||||
|
#include <Void/Stacktrace/Stacktrace.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
const auto url = Void::Net::Url::parse("https://example.invalid/path");
|
||||||
|
const auto token = Void::Security::hash_token("void-consumer-token");
|
||||||
|
auto database = Void::Sqlite::Database::open(":memory:");
|
||||||
|
const auto frames = Void::Stacktrace::capture_stacktrace(0, 1);
|
||||||
|
|
||||||
|
return url && url->target == "/path" && token && !token->empty() &&
|
||||||
|
database && frames.size() <= 1
|
||||||
|
? 0
|
||||||
|
: 1;
|
||||||
|
}
|
||||||
@@ -54,3 +54,8 @@ run_consumer(Audited
|
|||||||
-DCMAKE_DISABLE_FIND_PACKAGE_Boost=TRUE
|
-DCMAKE_DISABLE_FIND_PACKAGE_Boost=TRUE
|
||||||
-DCMAKE_DISABLE_FIND_PACKAGE_PkgConfig=TRUE
|
-DCMAKE_DISABLE_FIND_PACKAGE_PkgConfig=TRUE
|
||||||
-DCMAKE_DISABLE_FIND_PACKAGE_SQLite3=TRUE)
|
-DCMAKE_DISABLE_FIND_PACKAGE_SQLite3=TRUE)
|
||||||
|
|
||||||
|
# Compiled shared modules keep their third-party implementation dependencies
|
||||||
|
# private, but every installed runtime library must remain linkable and
|
||||||
|
# executable from a clean consumer project.
|
||||||
|
run_consumer(External)
|
||||||
@@ -38,7 +38,7 @@ Void::Testing::Test field_scope_nests()
|
|||||||
|
|
||||||
FieldScope a{"a", "1"};
|
FieldScope a{"a", "1"};
|
||||||
{
|
{
|
||||||
FieldScope b{{{"b", "2"}, {"c", "3"}}};
|
FieldScope b{{"b", "2"}, {"c", "3"}};
|
||||||
log.info("two scopes");
|
log.info("two scopes");
|
||||||
}
|
}
|
||||||
log.info("one scope");
|
log.info("one scope");
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
#include <Void/ShortUrl/ShortUrl.hpp>
|
||||||
|
#include <Void/Testing/Assert.hpp>
|
||||||
|
#include <Void/Testing/Test.hpp>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
class Shortener final : public Void::ShortUrl::IShortener
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
[[nodiscard]] std::string_view provider_id() const noexcept override
|
||||||
|
{
|
||||||
|
return "test";
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] Void::ShortUrl::Health health() const override
|
||||||
|
{
|
||||||
|
return {.status = Void::ShortUrl::HealthStatus::healthy};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] Void::ShortUrl::ShortenResult
|
||||||
|
shorten(const Void::ShortUrl::ShortenRequest& request) override
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
.short_url = "https://sho.rt/s/Ab3dE5fG7h",
|
||||||
|
.key = "Ab3dE5fG7h",
|
||||||
|
.expires_at_unix_seconds = request.expires_at_unix_seconds,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
Void::Testing::Test short_url_service_contract()
|
||||||
|
{
|
||||||
|
Shortener shortener;
|
||||||
|
Void::Testing::expect_eq(shortener.service_name(),
|
||||||
|
Void::ShortUrl::kServiceId);
|
||||||
|
Void::Testing::expect_eq(shortener.service_version(), std::uint32_t{1});
|
||||||
|
Void::Testing::expect_eq(shortener.provider_id(), std::string_view{"test"});
|
||||||
|
Void::Testing::expect_eq(shortener.health().status,
|
||||||
|
Void::ShortUrl::HealthStatus::healthy);
|
||||||
|
|
||||||
|
auto result = shortener.shorten({.target_url = "https://example.com/a"});
|
||||||
|
Void::Testing::expect(result.ok());
|
||||||
|
Void::Testing::expect_eq(result.key, std::string{"Ab3dE5fG7h"});
|
||||||
|
}
|
||||||
|
|
||||||
|
Void::Testing::Test short_url_resolution_is_optional()
|
||||||
|
{
|
||||||
|
Shortener shortener;
|
||||||
|
auto result = shortener.resolve({.key = "Ab3dE5fG7h"});
|
||||||
|
Void::Testing::expect(!result.ok());
|
||||||
|
Void::Testing::expect_eq(result.error.code,
|
||||||
|
Void::ShortUrl::ErrorCode::unsupported);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user