diff --git a/CMakeLists.txt b/CMakeLists.txt index e786ef3a..aff6b20c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -326,7 +326,8 @@ configure_package_config_file( write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/rabitqlibConfigVersion.cmake" VERSION "${PROJECT_VERSION}" - COMPATIBILITY SameMajorVersion + # Before 1.0 a minor release may break the API. + COMPATIBILITY SameMinorVersion ) install(EXPORT rabitqlibTargets FILE rabitqlibTargets.cmake diff --git a/docs/docs/cpp_integration.md b/docs/docs/cpp_integration.md index 9df80b68..989b75a1 100644 --- a/docs/docs/cpp_integration.md +++ b/docs/docs/cpp_integration.md @@ -107,6 +107,12 @@ find_package(rabitqlib CONFIG REQUIRED) target_link_libraries(my_program PRIVATE rabitqlib::index) ``` +To require a release, pass its version, for example +`find_package(rabitqlib 0.9 CONFIG REQUIRED)`. Before 1.0 a minor release may break the +API, so only the same minor release, at or above a requested patch, satisfies the request: +0.9.x does, 0.8 and 0.10 do not. A version range must stay within one minor release, for +example `0.9...<0.10`. + For a non-system prefix, point CMake to the installation: ```bash diff --git a/docs/docs/releases/unreleased.md b/docs/docs/releases/unreleased.md index 1b5379d0..94ebe9ce 100644 --- a/docs/docs/releases/unreleased.md +++ b/docs/docs/releases/unreleased.md @@ -87,6 +87,7 @@ - `search` takes a `GraphSearchOptions` struct. Without an `ef_search` it uses `max(k, 64)`, a smaller value is raised to `k`, and an explicit 0 throws; `symqg::QuantizedGraph` rejects an `ef_search` below `k`. - `seed()`, `ef_construction()` and `init()` have no value for a file of a release up to 0.8. - `IvfIndex`, `HnswIndex` and `SymqgIndex` are the supported and documented C++ index API from 0.9. `ivf::IVF`, `hnsw::HierarchicalNSW`, `symqg::QuantizedGraph` and `symqg::QGBuilder` stay installed at their paths and keep their interfaces apart from the changes listed below, but they leave the documentation and carry no compatibility promise. +- The installed CMake package satisfies `find_package(rabitqlib X.Y[.Z])` only when the major and minor versions match: `find_package(rabitqlib 0.8)` no longer finds 0.9, which `SameMajorVersion` compatibility allowed, and a version range must stay within one minor release, such as `0.9...<0.10`. Before 1.0 a minor release may break the API. Move to the new classes as follows: diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b800175b..8a11272b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -78,6 +78,11 @@ add_test(NAME CoreOpenMPFlagCheck COMMAND "${CMAKE_COMMAND}" "-DWORK_DIR=${CMAKE_CURRENT_BINARY_DIR}/openmp-flag-check" -P "${CMAKE_CURRENT_SOURCE_DIR}/core_consumer/check_no_openmp_test.cmake") +add_test(NAME PackageVersionCompatibility COMMAND "${CMAKE_COMMAND}" + "-DVERSION_FILE=${PROJECT_BINARY_DIR}/rabitqlibConfigVersion.cmake" + "-DPROJECT_VERSION=${PROJECT_VERSION}" + -P "${CMAKE_CURRENT_SOURCE_DIR}/core_consumer/check_package_version.cmake") + add_executable(core_api_v1_consumer fixtures/core_api_v1/consumer.cpp) target_link_libraries(core_api_v1_consumer PRIVATE rabitqlib::core) add_test(NAME CoreApiV1Consumer COMMAND core_api_v1_consumer) diff --git a/tests/core_consumer/check_package_version.cmake b/tests/core_consumer/check_package_version.cmake new file mode 100644 index 00000000..68215ca2 --- /dev/null +++ b/tests/core_consumer/check_package_version.cmake @@ -0,0 +1,43 @@ +# Run with -DVERSION_FILE= -DPROJECT_VERSION= -P. +# Before 1.0 a minor release may break the API, so find_package(rabitqlib X.Y) +# accepts only the same major and minor version. A policy change at 1.0 must +# update this check deliberately. +cmake_minimum_required(VERSION 3.20) +if(NOT VERSION_FILE OR NOT PROJECT_VERSION) + message(FATAL_ERROR "VERSION_FILE and PROJECT_VERSION are required") +endif() + +string(REPLACE "." ";" version_parts "${PROJECT_VERSION}") +list(GET version_parts 0 major) +list(GET version_parts 1 minor) + +function(check_request requested expected) + string(REPLACE "." ";" parts "${requested}") + list(LENGTH parts PACKAGE_FIND_VERSION_COUNT) + list(APPEND parts 0 0) + list(GET parts 0 PACKAGE_FIND_VERSION_MAJOR) + list(GET parts 1 PACKAGE_FIND_VERSION_MINOR) + list(GET parts 2 PACKAGE_FIND_VERSION_PATCH) + set(PACKAGE_FIND_VERSION "${requested}") + unset(PACKAGE_VERSION_COMPATIBLE) + include("${VERSION_FILE}") + if(expected AND NOT PACKAGE_VERSION_COMPATIBLE) + message(FATAL_ERROR "rabitqlib ${PROJECT_VERSION} rejected a request for ${requested}") + elseif(NOT expected AND PACKAGE_VERSION_COMPATIBLE) + message(FATAL_ERROR "rabitqlib ${PROJECT_VERSION} accepted a request for ${requested}") + endif() +endfunction() + +check_request("${major}.${minor}" TRUE) +check_request("${major}.${minor}.0" TRUE) +# Requests for an older release are what the compatibility mode decides; every +# mode already rejects newer ones. +if(minor GREATER 0) + math(EXPR previous_minor "${minor} - 1") + check_request("${major}.${previous_minor}" FALSE) +endif() +if(major GREATER 0) + math(EXPR previous_major "${major} - 1") + check_request("${previous_major}.${minor}" FALSE) +endif() +message(STATUS "Package version checks passed for ${PROJECT_VERSION}")