#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
#![allow(unused, dead_code)]
#![deny(clippy::all)]
#![warn(clippy::pedantic)]
#![warn(clippy::cargo)]
#![allow(
clippy::must_use_candidate,
clippy::suspicious_doc_comments,
clippy::wildcard_imports
)]
mod linking;
mod generated;
pub use generated::*;
pub mod library {
use std::path::PathBuf;
pub fn load() -> Result<(), String> {
super::generated::load()?;
check_version()
}
pub fn load_from(path: impl Into<std::path::PathBuf>) -> Result<(), String> {
super::generated::load_from(path.into())?;
check_version()
}
fn check_version() -> Result<(), String> {
let version = get_version()?;
if is_pre_2025_1_version(&version) {
return Err(format!("OpenVINO version is too old (see https://github.com/intel/openvino-rs/issues/167): {version}"));
}
Ok(())
}
fn get_version() -> Result<String, String> {
use super::generated::{
ov_get_openvino_version, ov_status_e, ov_version_free, ov_version_t,
};
let mut ov_version = ov_version_t {
buildNumber: std::ptr::null(),
description: std::ptr::null(),
};
let code = unsafe { ov_get_openvino_version(&mut ov_version) };
if code != ov_status_e::OK {
return Err(format!("failed to get OpenVINO version: {code:?}"));
}
let c_str_version = unsafe { std::ffi::CStr::from_ptr(ov_version.buildNumber) };
let version = c_str_version.to_string_lossy().into_owned();
unsafe { ov_version_free(std::ptr::addr_of_mut!(ov_version)) };
Ok(version)
}
fn is_pre_2025_1_version(version: &str) -> bool {
let mut parts = version.split(['.', '-']);
let year: usize = parts.next().unwrap().parse().unwrap();
let minor: usize = parts.next().unwrap().parse().unwrap();
year < 2025 || (year == 2025 && minor < 1)
}
pub fn find() -> Option<PathBuf> {
if cfg!(feature = "runtime-linking") {
openvino_finder::find("openvino_c", openvino_finder::Linking::Dynamic)
} else {
Some(PathBuf::from(env!("OPENVINO_LIB_PATH")))
}
}
}