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
2 changes: 2 additions & 0 deletions rust/cuvs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub mod error;
mod ffi_utils;
pub mod neighbors;
pub mod resources;
pub mod version;

#[cfg(test)]
pub(crate) mod test_utils;

Expand Down
22 changes: 22 additions & 0 deletions rust/cuvs/src/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

//! cuVS library version query.

use crate::error::{LibraryError, check_cuvs};
use crate::ffi;

/// Returns the cuVS library version as `(major, minor, patch)`.
pub fn version() -> Result<(u16, u16, u16), LibraryError> {
let mut major: u16 = 0;
let mut minor: u16 = 0;
let mut patch: u16 = 0;

// SAFETY:
// - All three pointers are valid, aligned `u16` locals.
let status = unsafe { ffi::cuvsVersionGet(&mut major, &mut minor, &mut patch) };
check_cuvs(status)?;
Ok((major, minor, patch))
}
32 changes: 32 additions & 0 deletions rust/cuvs/tests/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

use cuvs::version::version;

#[test]
fn linked_library_version_is_compatible_with_crate() {
let (library_major, library_minor, library_patch) =
version().expect("the linked cuVS library should report its version");
let (crate_major, crate_minor, crate_patch) = (
env!("CARGO_PKG_VERSION_MAJOR").parse::<u16>().unwrap(),
env!("CARGO_PKG_VERSION_MINOR").parse::<u16>().unwrap(),
env!("CARGO_PKG_VERSION_PATCH").parse::<u16>().unwrap(),
);

// This mirrors the compatibility policy used by cuvs-sys when locating the
// native CMake package: major and minor must match so the expected API and
// ABI are present.
assert_eq!(
(library_major, library_minor),
(crate_major, crate_minor),
"the linked cuVS library must have the same major and minor version as the crate"
);

// cuvs-sys permits a newer patch release because they are backward-compatible.
assert!(
library_patch >= crate_patch,
"the linked cuVS library patch version must not be older than the crate"
);
}
Loading