diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6a71960..a87b304 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,7 +37,10 @@ jobs: - name: Build (openvino-sys from source) run: cargo build --verbose --features openvino-sys/from-source - name: Run tests - run: cargo test --verbose --features openvino-sys/from-source + # For some reason the library path is not set during the doc tests (`--doc`, see + # https://doc.rust-lang.org/cargo/commands/cargo-test.html#target-selection) so we skip them + # here: issue at https://github.com/intel/openvino-rs/issues/25. + run: cargo test --verbose --features openvino-sys/from-source --lib --tests # Build and test from an existing OpenVINO installation inside a Docker image (i.e. download the # binaries, then compile against these). diff --git a/.gitmodules b/.gitmodules index ed66cb6..74f712f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "crates/upstream"] path = crates/openvino-sys/upstream url = https://github.com/openvinotoolkit/openvino + depth = 1 diff --git a/Cargo.lock b/Cargo.lock index bf30c60..85984f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -51,7 +51,7 @@ dependencies = [ "cexpr", "clang-sys", "clap", - "env_logger", + "env_logger 0.8.3", "lazy_static", "lazycell", "log", @@ -126,6 +126,19 @@ dependencies = [ "cc", ] +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime 1.3.0", + "log", + "regex", + "termcolor", +] + [[package]] name = "env_logger" version = "0.8.3" @@ -133,7 +146,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17392a012ea30ef05a610aa97dfb49496e71c9f676b27879922ea5bdf60d9d3f" dependencies = [ "atty", - "humantime", + "humantime 2.1.0", "log", "regex", "termcolor", @@ -172,6 +185,15 @@ dependencies = [ "libc", ] +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + [[package]] name = "humantime" version = "2.1.0" @@ -252,6 +274,11 @@ dependencies = [ [[package]] name = "openvino-finder" version = "0.3.1" +dependencies = [ + "cfg-if", + "log", + "pretty_env_logger", +] [[package]] name = "openvino-sys" @@ -278,6 +305,16 @@ dependencies = [ "ucd-trie", ] +[[package]] +name = "pretty_env_logger" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d" +dependencies = [ + "env_logger 0.7.1", + "log", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -311,6 +348,12 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "1.0.7" diff --git a/crates/openvino-finder/Cargo.toml b/crates/openvino-finder/Cargo.toml index ec3e114..fc593c5 100644 --- a/crates/openvino-finder/Cargo.toml +++ b/crates/openvino-finder/Cargo.toml @@ -10,3 +10,8 @@ documentation = "https://docs.rs/openvino-finder" edition = "2018" [dependencies] +cfg-if = "1.0" +log = "0.4" + +[dev-dependencies] +pretty_env_logger = "0.4" diff --git a/crates/openvino-finder/src/lib.rs b/crates/openvino-finder/src/lib.rs index b5a7d66..6c495ed 100644 --- a/crates/openvino-finder/src/lib.rs +++ b/crates/openvino-finder/src/lib.rs @@ -1,3 +1,4 @@ +use cfg_if::cfg_if; use std::env; use std::path::PathBuf; @@ -13,6 +14,18 @@ pub fn find(library_name: &str) -> Option { library_name, env::consts::DLL_SUFFIX ); + log::info!("Attempting to find library: {}", file); + + // We search for the library in various different places and early-return if we find it. + macro_rules! check_and_return { + ($path: expr) => { + log::debug!("Searching in: {}", $path.display()); + if $path.is_file() { + log::info!("Found library at path: {}", $path.display()); + return Some($path); + } + }; + } // Search using the `OPENVINO_INSTALL_DIR` environment variable; this may be set by users of the // openvino-rs library. @@ -20,9 +33,17 @@ pub fn find(library_name: &str) -> Option { let install_dir = PathBuf::from(install_dir); for lib_dir in KNOWN_INSTALLATION_SUBDIRECTORIES { let search_path = install_dir.join(lib_dir).join(&file); - if search_path.is_file() { - return Some(search_path); - } + check_and_return!(search_path); + } + } + + // 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); + check_and_return!(search_path); } } @@ -32,9 +53,7 @@ pub fn find(library_name: &str) -> Option { let install_dir = PathBuf::from(install_dir); for lib_dir in KNOWN_INSTALLATION_SUBDIRECTORIES { let search_path = install_dir.join(lib_dir).join(&file); - if search_path.is_file() { - return Some(search_path); - } + check_and_return!(search_path); } } @@ -44,9 +63,7 @@ pub fn find(library_name: &str) -> Option { 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); - if search_path.is_file() { - return Some(search_path); - } + check_and_return!(search_path); } } @@ -58,9 +75,7 @@ pub fn find(library_name: &str) -> Option { { for lib_dir in KNOWN_INSTALLATION_SUBDIRECTORIES { let search_path = default_dir.join(lib_dir).join(&file); - if search_path.is_file() { - return Some(search_path); - } + check_and_return!(search_path); } } @@ -68,24 +83,35 @@ pub fn find(library_name: &str) -> Option { } const ENV_OPENVINO_INSTALL_DIR: &'static str = "OPENVINO_INSTALL_DIR"; - +const ENV_OPENVINO_BUILD_DIR: &'static str = "OPENVINO_BUILD_DIR"; const ENV_INTEL_OPENVINO_DIR: &'static str = "INTEL_OPENVINO_DIR"; -#[cfg(target_os = "linux")] -const ENV_LIBRARY_PATH: &'static str = "LD_LIBRARY_PATH"; -#[cfg(target_os = "macos")] -const ENV_LIBRARY_PATH: &'static str = "DYLD_LIBRARY_PATH"; -#[cfg(target_os = "windows")] -const ENV_LIBRARY_PATH: &'static str = "PATH"; +cfg_if! { + if #[cfg(any(target_os = "linux"))] { + const ENV_LIBRARY_PATH: &'static str = "LD_LIBRARY_PATH"; + } else if #[cfg(target_os = "macos")] { + const ENV_LIBRARY_PATH: &'static str = "DYLD_LIBRARY_PATH"; + } else if #[cfg(target_os = "windows")] { + const ENV_LIBRARY_PATH: &'static str = "PATH"; + } else { + // This may not work but seems like a sane default for target OS' not listed above. + const ENV_LIBRARY_PATH: &'static str = "LD_LIBRARY_PATH"; + } +} -#[cfg(any(target_os = "linux", target_os = "macos"))] -const DEFAULT_INSTALLATION_DIRECTORIES: &'static [&'static str] = - &["/opt/intel/openvino", "/opt/intel/openvino_2021"]; -#[cfg(target_os = "windows")] -const DEFAULT_INSTALLATION_DIRECTORIES: &'static [&'static str] = &[ - "C:\\Program Files (x86)\\Intel\\openvino", - "C:\\Program Files (x86)\\Intel\\openvino_2021", -]; +cfg_if! { + if #[cfg(any(target_os = "linux", target_os = "macos"))] { + const DEFAULT_INSTALLATION_DIRECTORIES: &'static [&'static str] = + &["/opt/intel/openvino", "/opt/intel/openvino_2021"]; + } else if #[cfg(target_os = "windows")] { + const DEFAULT_INSTALLATION_DIRECTORIES: &'static [&'static str] = &[ + "C:\\Program Files (x86)\\Intel\\openvino", + "C:\\Program Files (x86)\\Intel\\openvino_2021", + ]; + } else { + const DEFAULT_INSTALLATION_DIRECTORIES: &'static [&'static str] = &[]; + } +} const KNOWN_INSTALLATION_SUBDIRECTORIES: &'static [&'static str] = &[ "deployment_tools/ngraph/lib", @@ -95,6 +121,12 @@ const KNOWN_INSTALLATION_SUBDIRECTORIES: &'static [&'static str] = &[ "deployment_tools/inference_engine/external/tbb/lib", ]; +const KNOWN_BUILD_SUBDIRECTORIES: &'static [&'static str] = &[ + "bin/intel64/Debug/lib", + "bin/intel64/Release/lib", + "inference-engine/temp/tbb/lib", +]; + #[cfg(test)] mod test { use super::*; @@ -103,6 +135,7 @@ mod test { /// system. #[test] fn find_inference_engine_c_api_locally() { + pretty_env_logger::init(); assert!(find("inference_engine_c_api").is_some()); } }