Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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: 0 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ jobs:
# path and Cargo links the binary to it in the `build.rs` script.
- name: Check dynamic linking
run: cargo test
# TODO: the finder does not yet know how to distinguish between `*.lib` (required here) and
# `*.dll` (required by runtime-linking).
if: ${{ !startsWith(runner.os, 'windows') }}
# Finally, run the runtime-linking tests: the binddings do not link at build time, instead
# as the tests are run.
- name: Check runtime linking
Expand Down
47 changes: 37 additions & 10 deletions crates/openvino-finder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,46 @@ macro_rules! check_and_return {
///
/// Panics if it cannot list the contents of a search directory.
pub fn find(library_name: &str) -> Option<PathBuf> {
let file = format!(
let library = format!(
"{}{}{}",
env::consts::DLL_PREFIX,
library_name,
env::consts::DLL_SUFFIX
);
log::info!("Attempting to find library: {}", file);
log::info!("Attempting to find library: {}", library);
find_library(&library)
}

/// Find the path to an OpenVINO link library.
///
/// Follows the same procedure as [find], but searches for "import" libraries.
/// This differentiation is important on Windows, which requires ".lib" when linking:
/// https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-creation#creating-an-import-library
pub fn find_link(library_name: &str) -> Option<PathBuf> {
find_import_library(library_name)
}

#[cfg(target_os = "linux")]
#[inline(always)]
fn find_import_library(library_name: &str) -> Option<PathBuf> {
find(library_name)
}

#[cfg(target_os = "windows")]
#[inline(always)]
fn find_import_library(library_name: &str) -> Option<PathBuf> {
let library = format!("{}.lib", library_name);
log::info!("Attempting to find link library: {}", library);
find_library(&library)
}

fn find_library(library: &str) -> Option<PathBuf> {
// Search using the `OPENVINO_BUILD_DIR` environment variable; this may be set by users of the
// `openvino-rs` library.
if let Some(build_dir) = env::var_os(ENV_OPENVINO_BUILD_DIR) {
let install_dir = PathBuf::from(build_dir);
for lib_dir in KNOWN_BUILD_SUBDIRECTORIES {
let search_path = install_dir.join(lib_dir).join(&file);
let search_path = install_dir.join(lib_dir).join(library);
check_and_return!(search_path);
}
}
Expand All @@ -111,7 +137,7 @@ pub fn find(library_name: &str) -> Option<PathBuf> {
if let Some(install_dir) = env::var_os(ENV_OPENVINO_INSTALL_DIR) {
let install_dir = PathBuf::from(install_dir);
for lib_dir in KNOWN_INSTALLATION_SUBDIRECTORIES {
let search_path = install_dir.join(lib_dir).join(&file);
let search_path = install_dir.join(lib_dir).join(library);
check_and_return!(search_path);
}
}
Expand All @@ -121,7 +147,7 @@ pub fn find(library_name: &str) -> Option<PathBuf> {
if let Some(install_dir) = env::var_os(ENV_INTEL_OPENVINO_DIR) {
let install_dir = PathBuf::from(install_dir);
for lib_dir in KNOWN_INSTALLATION_SUBDIRECTORIES {
let search_path = install_dir.join(lib_dir).join(&file);
let search_path = install_dir.join(lib_dir).join(library);
check_and_return!(search_path);
}
}
Expand All @@ -130,7 +156,7 @@ pub fn find(library_name: &str) -> Option<PathBuf> {
// `DYLD_LIBRARY_PATH` on MacOS).
if let Some(path) = env::var_os(ENV_LIBRARY_PATH) {
for lib_dir in env::split_paths(&path) {
let search_path = lib_dir.join(&file);
let search_path = lib_dir.join(library);
check_and_return!(search_path);
}
}
Expand All @@ -143,13 +169,13 @@ pub fn find(library_name: &str) -> Option<PathBuf> {
.filter(|d| d.is_dir())
{
// Check if the file is located in the installation directory.
let search_path = install_dir.join(&file);
let search_path = install_dir.join(library);
check_and_return!(search_path);

// Otherwise, check for version terminators: e.g., `libfoo.so.3.1.2`.
let filenames = list_directory(&install_dir).expect("cannot list installation directory");
let versions = get_suffixes(filenames, &file);
if let Some(path) = build_latest_version(&install_dir, &file, versions) {
let versions = get_suffixes(filenames, library);
if let Some(path) = build_latest_version(&install_dir, library, versions) {
check_and_return!(path);
}
}
Expand All @@ -161,7 +187,7 @@ pub fn find(library_name: &str) -> Option<PathBuf> {
.filter(|d| d.is_dir())
{
for lib_dir in KNOWN_INSTALLATION_SUBDIRECTORIES {
let search_path = default_dir.join(lib_dir).join(&file);
let search_path = default_dir.join(lib_dir).join(library);
check_and_return!(search_path);
}
}
Expand Down Expand Up @@ -220,6 +246,7 @@ const KNOWN_INSTALLATION_SUBDIRECTORIES: &[&str] = &[
"runtime/lib/intel64/Release",
"runtime/lib/intel64",
"runtime/3rdparty/tbb/lib",
"runtime/bin/intel64/Release",
"runtime/bin/intel64",
"runtime/3rdparty/tbb/bin",
];
Expand Down
2 changes: 1 addition & 1 deletion crates/openvino-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn add_dynamically_linked_library(library: &str) {
fn find_libraries_in_existing_installation() -> Vec<PathBuf> {
let mut dirs = vec![];
for library in LIBRARIES {
if let Some(path) = openvino_finder::find(library) {
if let Some(path) = openvino_finder::find_link(library) {
println!(
"cargo:warning=Found library to link against: {}",
path.display()
Expand Down