Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/scripts/prepare-vcpkg-release.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Copy the release's complete overlay port into a vcpkg checkout."""
"""Copy the release's registry recipe into a vcpkg checkout."""

import argparse
import json
Expand Down Expand Up @@ -34,14 +34,18 @@ def prepare_port(source_port, destination_port, version, sha512):

manifest = json.loads((source_port / "vcpkg.json").read_text(encoding="utf-8"))
if manifest["name"] != "cpp-client-telemetry":
raise ValueError("Release overlay is not the cpp-client-telemetry port")
for feature in ("minimal-sqlite", "android-curl-openssl"):
raise ValueError("Release recipe is not the cpp-client-telemetry port")
if "minimal-sqlite" in manifest.get("features", {}):
raise ValueError("Use the registry recipe, not the development overlay with minimal-sqlite")
for feature in ("android-curl-openssl", "android-curl-mbedtls", "no-logging"):
if feature not in manifest.get("features", {}):
raise ValueError(f"Release overlay is missing the {feature} feature")
raise ValueError(f"Release recipe is missing the {feature} feature")
manifest["version"] = version
manifest.pop("port-version", None)

portfile = (source_port / "portfile.cmake").read_text(encoding="utf-8")
if "MATSDK_VCPKG_SOURCE_DIR" in portfile:
raise ValueError("Registry recipes must not allow development source overrides")
for field, value in (("REF", f"v{version}"), ("SHA512", sha512)):
portfile, count = re.subn(
rf"(?m)^([ \t]*{field}[ \t]+)[^\r\n]+",
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/test-embedding.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ jobs:
run: |
cmake --build build-embedding --target embedding_test --parallel 4
ctest --test-dir build-embedding --output-on-failure
- name: Consume installed caller-provided package
if: matrix.preload-storage == 'ON'
run: |
cmake --install build-embedding --prefix "${RUNNER_TEMP}/matsdk"
cmake -G Ninja -S tests/vcpkg -B build-provided-consumer \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH="${RUNNER_TEMP}/matsdk" \
-DMATSDK_TEST_PRELOAD_DEPENDENCIES=ON
cmake --build build-provided-consumer --parallel 4
ctest --test-dir build-provided-consumer --output-on-failure

windows:
runs-on: windows-2022
Expand All @@ -100,6 +110,39 @@ jobs:
cmake --build build-embedding --config Release --target embedding_test -- /m
ctest --test-dir build-embedding -C Release --output-on-failure

sqlite-coexistence:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-2022, macos-latest]
shared: ["OFF", "ON"]
sqlite: [MINIMAL, VENDORED]
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- name: Install Linux HTTP dependencies
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev
- name: Configure source consumer
run: >
cmake -S tests/package-coexistence -B build-coexistence
-DCMAKE_BUILD_TYPE=Release
-DBUILD_SHARED_LIBS=${{ matrix.shared }}
-DMATSDK_SQLITE_PROVIDER=${{ matrix.sqlite }}
-DMATSDK_ZLIB_PROVIDER=VENDORED
- name: Build, install, and test both consumers
shell: bash
run: |
cmake --build build-coexistence --config Release --parallel 4
ctest --test-dir build-coexistence -C Release --output-on-failure
cmake --install build-coexistence --config Release --prefix "${RUNNER_TEMP}/matsdk"
cmake -S tests/package-coexistence -B build-installed-coexistence \
-DCMAKE_BUILD_TYPE=Release \
-DMATSDK_SQLITE_PROVIDER=${{ matrix.sqlite }} \
-DMATSDK_INSTALLED_PREFIX="${RUNNER_TEMP}/matsdk"
cmake --build build-installed-coexistence --config Release --parallel 4
ctest --test-dir build-installed-coexistence -C Release --output-on-failure

installed-package-linux:
runs-on: ubuntu-latest
strategy:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test-vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
run: python tests/vcpkg/test-release-port.py
- name: Verify native feature mappings
run: cmake -P tests/vcpkg/native-feature-tests.cmake
- name: Verify registry core graphs and feature unions
run: cmake -DREGISTRY_MODE=ON -P tests/vcpkg/native-feature-tests.cmake
- name: Verify installed package dependency selection
run: cmake -P tests/vcpkg/package-dependency-tests.cmake

windows:
runs-on: windows-latest
Expand Down
33 changes: 29 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
cmake_minimum_required(VERSION 3.15...3.31)

project(MSTelemetry LANGUAGES C CXX)
if(APPLE)
set(MATSDK_BUILD_PLATFORM_APPLE TRUE)
else()
set(MATSDK_BUILD_PLATFORM_APPLE FALSE)

# Snapshot caller targets before curl discovery can import storage dependencies.
set(MATSDK_SQLITE_DEPENDENCY_KIND PACKAGE)
if(TARGET SQLite3::SQLite3 OR TARGET SQLite::SQLite3)
set(MATSDK_SQLITE_DEPENDENCY_KIND PROVIDED)
endif()
set(MATSDK_ZLIB_DEPENDENCY_KIND PACKAGE)
if(TARGET ZLIB::ZLIB)
set(MATSDK_ZLIB_DEPENDENCY_KIND PROVIDED)
endif()

################################################################################################
Expand Down Expand Up @@ -180,6 +185,7 @@ endif()
set(MATSDK_NEEDS_CURL OFF)
set(MATSDK_CURL_FETCHED OFF)
set(MATSDK_CURL_LINK_TARGET "")
set(MATSDK_CURL_DEPENDENCY_KIND NONE)
if(PAL_IMPLEMENTATION STREQUAL "CPP11"
AND NOT MATSDK_PLATFORM_IOS
AND (NOT CMAKE_SYSTEM_NAME STREQUAL "Android" OR MATSDK_ANDROID_USES_CURL)
Expand All @@ -189,31 +195,46 @@ if(PAL_IMPLEMENTATION STREQUAL "CPP11"
HAVE_MAT_CURL_HTTP_CLIENT)
if(TARGET CURL::libcurl)
set(MATSDK_CURL_LINK_TARGET CURL::libcurl)
set(MATSDK_CURL_DEPENDENCY_KIND PROVIDED)
elseif(MATSDK_CURL_PROVIDER_UPPER STREQUAL "FETCH")
include(cmake/MatsdkFetchCurl.cmake)
matsdk_fetch_curl(_matsdk_curl_target)
set(MATSDK_CURL_LINK_TARGET "${_matsdk_curl_target}")
set(MATSDK_CURL_FETCHED ON)
set(MATSDK_CURL_DEPENDENCY_KIND BUNDLED)
else()
find_package(CURL REQUIRED)
if(NOT TARGET CURL::libcurl)
message(FATAL_ERROR
"find_package(CURL) did not create the required CURL::libcurl target.")
endif()
set(MATSDK_CURL_LINK_TARGET CURL::libcurl)
set(MATSDK_CURL_DEPENDENCY_KIND PACKAGE)
endif()
endif()

################################################################################################
# Canonical dependency targets
################################################################################################
set(MATSDK_SQLITE_PACKAGE_NAME SQLite3)
set(MATSDK_SQLITE_PACKAGE_TARGET SQLite::SQLite3)
if(MATSDK_SQLITE_PROVIDER_RESOLVED STREQUAL "NONE")
set(MATSDK_SQLITE_DEPENDENCY_KIND NONE)
elseif(NOT MATSDK_SQLITE_PROVIDER_RESOLVED STREQUAL "SYSTEM")
set(MATSDK_SQLITE_DEPENDENCY_KIND BUNDLED)
endif()
if(NOT MATSDK_ZLIB_PROVIDER_RESOLVED STREQUAL "SYSTEM")
set(MATSDK_ZLIB_DEPENDENCY_KIND BUNDLED)
endif()
if(TARGET SQLite::SQLite3 AND NOT TARGET SQLite3::SQLite3)
matsdk_add_interface_dependency(SQLite3::SQLite3 SQLite::SQLite3)
endif()
if(MATSDK_SQLITE_PROVIDER_RESOLVED STREQUAL "SYSTEM" AND NOT TARGET SQLite3::SQLite3)
if(APPLE AND NOT MATSDK_USING_VCPKG)
matsdk_add_apple_system_library(SQLite3::SQLite3 sqlite3)
set(MATSDK_SQLITE_DEPENDENCY_KIND APPLE_SYSTEM)
else()
set(MATSDK_SQLITE_DEPENDENCY_KIND PACKAGE)
find_package(SQLite3 QUIET)
if(TARGET SQLite::SQLite3 AND NOT TARGET SQLite3::SQLite3)
matsdk_add_interface_dependency(SQLite3::SQLite3 SQLite::SQLite3)
Expand All @@ -222,6 +243,8 @@ if(MATSDK_SQLITE_PROVIDER_RESOLVED STREQUAL "SYSTEM" AND NOT TARGET SQLite3::SQL
find_package(unofficial-sqlite3 CONFIG REQUIRED)
matsdk_add_interface_dependency(
SQLite3::SQLite3 unofficial::sqlite3::sqlite3)
set(MATSDK_SQLITE_PACKAGE_NAME unofficial-sqlite3)
set(MATSDK_SQLITE_PACKAGE_TARGET unofficial::sqlite3::sqlite3)
endif()
if(NOT TARGET SQLite3::SQLite3)
message(FATAL_ERROR
Expand All @@ -234,8 +257,10 @@ endif()
if(MATSDK_ZLIB_PROVIDER_RESOLVED STREQUAL "SYSTEM" AND NOT TARGET ZLIB::ZLIB)
if(APPLE AND NOT MATSDK_USING_VCPKG)
matsdk_add_apple_system_library(ZLIB::ZLIB z)
set(MATSDK_ZLIB_DEPENDENCY_KIND APPLE_SYSTEM)
else()
find_package(ZLIB REQUIRED)
set(MATSDK_ZLIB_DEPENDENCY_KIND PACKAGE)
endif()
endif()

Expand Down
30 changes: 11 additions & 19 deletions cmake/MSTelemetryConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,21 @@ include("${CMAKE_CURRENT_LIST_DIR}/MatsdkDependencyTargets.cmake")

# Recreate dependencies only when a static package needs them at the final link.
if(@MATSDK_CONFIG_STATIC_PACKAGE@)
if(@MATSDK_BUILD_PLATFORM_APPLE@)
set(_matsdk_package_sqlite_args APPLE_SYSTEM APPLE_LIBRARY sqlite3)
set(_matsdk_package_zlib_args APPLE_SYSTEM APPLE_LIBRARY z)
else()
set(_matsdk_package_sqlite_args)
set(_matsdk_package_zlib_args)
endif()
matsdk_add_package_system_dependency(
MSTelemetry::sqlite_dependency
SQLite3::SQLite3
"@MATSDK_SQLITE_PROVIDER_RESOLVED@"
SQLite3
LEGACY_TARGET SQLite::SQLite3
${_matsdk_package_sqlite_args})
"@MATSDK_SQLITE_PACKAGE_NAME@"
KIND "@MATSDK_SQLITE_DEPENDENCY_KIND@"
LEGACY_TARGET "@MATSDK_SQLITE_PACKAGE_TARGET@"
APPLE_LIBRARY sqlite3)
matsdk_add_package_system_dependency(
MSTelemetry::zlib_dependency
ZLIB::ZLIB
"@MATSDK_ZLIB_PROVIDER_RESOLVED@"
ZLIB
${_matsdk_package_zlib_args})
KIND "@MATSDK_ZLIB_DEPENDENCY_KIND@"
APPLE_LIBRARY z)
endif()

if("@MATSDK_ANDROID_HTTP_CLIENT_RESOLVED@" STREQUAL "")
Expand Down Expand Up @@ -88,17 +83,14 @@ if(@MATSDK_CONFIG_STATIC_PACKAGE@ AND @MATSDK_NEEDS_CURL@)
set_property(TARGET MSTelemetry::curl_archive PROPERTY
INTERFACE_LINK_LIBRARIES "${_matsdk_curl_tls_targets}")
else()
if(NOT TARGET CURL::libcurl)
find_dependency(CURL)
endif()
matsdk_add_package_system_dependency(
MSTelemetry::curl_dependency CURL::libcurl SYSTEM CURL
KIND "@MATSDK_CURL_DEPENDENCY_KIND@")
endif()
if(@MATSDK_CURL_FETCHED@)
set(_matsdk_curl_dependency_target MSTelemetry::curl_archive)
else()
set(_matsdk_curl_dependency_target CURL::libcurl)
matsdk_add_interface_dependency(
MSTelemetry::curl_dependency MSTelemetry::curl_archive)
endif()
matsdk_add_interface_dependency(
MSTelemetry::curl_dependency "${_matsdk_curl_dependency_target}")
endif()

include("${CMAKE_CURRENT_LIST_DIR}/MSTelemetryTargets.cmake")
Expand Down
41 changes: 31 additions & 10 deletions cmake/MatsdkDependencyTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,41 @@ function(matsdk_add_package_system_dependency dependency_target canonical_target
endif()

set(options APPLE_SYSTEM)
set(one_value_args APPLE_LIBRARY LEGACY_TARGET)
set(one_value_args APPLE_LIBRARY LEGACY_TARGET KIND)
cmake_parse_arguments(MATSDK_PACKAGE_DEP "${options}" "${one_value_args}" "" ${ARGN})

if(MATSDK_PACKAGE_DEP_APPLE_SYSTEM)
if(NOT DEFINED MATSDK_PACKAGE_DEP_APPLE_LIBRARY
OR MATSDK_PACKAGE_DEP_APPLE_LIBRARY STREQUAL "")
if(NOT MATSDK_PACKAGE_DEP_KIND)
set(MATSDK_PACKAGE_DEP_KIND PACKAGE)
if(MATSDK_PACKAGE_DEP_APPLE_SYSTEM)
set(MATSDK_PACKAGE_DEP_KIND APPLE_SYSTEM)
endif()
endif()
if(NOT MATSDK_PACKAGE_DEP_KIND MATCHES "^(PACKAGE|PROVIDED|APPLE_SYSTEM)$")
message(FATAL_ERROR "Invalid dependency kind: ${MATSDK_PACKAGE_DEP_KIND}")
endif()
if(NOT TARGET "${canonical_target}"
AND DEFINED MATSDK_PACKAGE_DEP_LEGACY_TARGET
AND TARGET "${MATSDK_PACKAGE_DEP_LEGACY_TARGET}")
matsdk_add_interface_dependency(
"${canonical_target}" "${MATSDK_PACKAGE_DEP_LEGACY_TARGET}")
endif()
if(NOT TARGET "${canonical_target}")
if(MATSDK_PACKAGE_DEP_KIND STREQUAL "APPLE_SYSTEM")
if(NOT DEFINED MATSDK_PACKAGE_DEP_APPLE_LIBRARY
OR MATSDK_PACKAGE_DEP_APPLE_LIBRARY STREQUAL "")
message(FATAL_ERROR
"APPLE_LIBRARY is required for Apple system dependencies.")
endif()
include("${_MATSDK_DEPENDENCY_TARGETS_DIR}/MatsdkAppleSystemDeps.cmake")
matsdk_add_apple_system_library(
"${canonical_target}" "${MATSDK_PACKAGE_DEP_APPLE_LIBRARY}")
elseif(MATSDK_PACKAGE_DEP_KIND STREQUAL "PACKAGE")
find_dependency(${package_name})
else()
message(FATAL_ERROR
"APPLE_LIBRARY is required for Apple system dependencies.")
"MSTelemetry was built with a caller-provided ${canonical_target}. "
"Define that target before find_package(MSTelemetry).")
endif()
include("${_MATSDK_DEPENDENCY_TARGETS_DIR}/MatsdkAppleSystemDeps.cmake")
matsdk_add_apple_system_library(
"${canonical_target}" "${MATSDK_PACKAGE_DEP_APPLE_LIBRARY}")
elseif(NOT TARGET "${canonical_target}")
find_dependency(${package_name})
endif()
if(NOT TARGET "${canonical_target}"
AND DEFINED MATSDK_PACKAGE_DEP_LEGACY_TARGET
Expand Down
33 changes: 33 additions & 0 deletions cmake/MatsdkSqliteNamespace.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
include_guard()

function(matsdk_namespace_sqlite target header output)
set(symbols)
# The amalgamations also declare platform APIs and test globals absent from sqlite3.h.
foreach(source IN ITEMS "${header}" ${ARGN})
file(STRINGS "${source}" declarations REGEX "^SQLITE_API ")
foreach(declaration IN LISTS declarations)
string(REGEX MATCH "sqlite3[A-Za-z0-9_]+[ \t]*[()\\[;=]" symbol "${declaration}")
if(NOT symbol)
message(FATAL_ERROR "Cannot namespace SQLite API declaration: ${declaration}")
endif()
string(REGEX REPLACE "[ \t]*[()\\[;=]$" "" symbol "${symbol}")
list(APPEND symbols "${symbol}")
endforeach()
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${source}")
endforeach()
if(NOT symbols)
message(FATAL_ERROR "No SQLite API declarations found in ${header}")
endif()
list(REMOVE_DUPLICATES symbols)
list(SORT symbols)
set(contents "#pragma once\n")
foreach(symbol IN LISTS symbols)
string(APPEND contents "#define ${symbol} matsdk_${symbol}\n")
endforeach()
file(GENERATE OUTPUT "${output}" CONTENT "${contents}")
if(MSVC)
target_compile_options(${target} INTERFACE "/FI${output}")
else()
target_compile_options(${target} INTERFACE "SHELL:-include \"${output}\"")
endif()
endfunction()
Loading
Loading