Skip to content
Merged
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
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions docs/docs/cpp_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/docs/releases/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
43 changes: 43 additions & 0 deletions tests/core_consumer/check_package_version.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Run with -DVERSION_FILE=<rabitqlibConfigVersion.cmake> -DPROJECT_VERSION=<X.Y.Z> -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}")
Loading