Skip to content

Commit bac30c6

Browse files
committed
openvino-finder: provide sane defaults for unsupported target OS
1 parent 4558445 commit bac30c6

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/openvino-finder/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ documentation = "https://docs.rs/openvino-finder"
1010
edition = "2018"
1111

1212
[dependencies]
13+
cfg-if = "1.0"
1314
log = "0.4"
1415

1516
[dev-dependencies]

crates/openvino-finder/src/lib.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use cfg_if::cfg_if;
12
use std::env;
23
use std::path::PathBuf;
34

@@ -85,21 +86,32 @@ const ENV_OPENVINO_INSTALL_DIR: &'static str = "OPENVINO_INSTALL_DIR";
8586
const ENV_OPENVINO_BUILD_DIR: &'static str = "OPENVINO_BUILD_DIR";
8687
const ENV_INTEL_OPENVINO_DIR: &'static str = "INTEL_OPENVINO_DIR";
8788

88-
#[cfg(target_os = "linux")]
89-
const ENV_LIBRARY_PATH: &'static str = "LD_LIBRARY_PATH";
90-
#[cfg(target_os = "macos")]
91-
const ENV_LIBRARY_PATH: &'static str = "DYLD_LIBRARY_PATH";
92-
#[cfg(target_os = "windows")]
93-
const ENV_LIBRARY_PATH: &'static str = "PATH";
89+
cfg_if! {
90+
if #[cfg(any(target_os = "linux"))] {
91+
const ENV_LIBRARY_PATH: &'static str = "LD_LIBRARY_PATH";
92+
} else if #[cfg(target_os = "macos")] {
93+
const ENV_LIBRARY_PATH: &'static str = "DYLD_LIBRARY_PATH";
94+
} else if #[cfg(target_os = "windows")] {
95+
const ENV_LIBRARY_PATH: &'static str = "PATH";
96+
} else {
97+
// This may not work but seems like a sane default for target OS' not listed above.
98+
const ENV_LIBRARY_PATH: &'static str = "LD_LIBRARY_PATH";
99+
}
100+
}
94101

95-
#[cfg(any(target_os = "linux", target_os = "macos"))]
96-
const DEFAULT_INSTALLATION_DIRECTORIES: &'static [&'static str] =
97-
&["/opt/intel/openvino", "/opt/intel/openvino_2021"];
98-
#[cfg(target_os = "windows")]
99-
const DEFAULT_INSTALLATION_DIRECTORIES: &'static [&'static str] = &[
100-
"C:\\Program Files (x86)\\Intel\\openvino",
101-
"C:\\Program Files (x86)\\Intel\\openvino_2021",
102-
];
102+
cfg_if! {
103+
if #[cfg(any(target_os = "linux", target_os = "macos"))] {
104+
const DEFAULT_INSTALLATION_DIRECTORIES: &'static [&'static str] =
105+
&["/opt/intel/openvino", "/opt/intel/openvino_2021"];
106+
} else if #[cfg(target_os = "windows")] {
107+
const DEFAULT_INSTALLATION_DIRECTORIES: &'static [&'static str] = &[
108+
"C:\\Program Files (x86)\\Intel\\openvino",
109+
"C:\\Program Files (x86)\\Intel\\openvino_2021",
110+
];
111+
} else {
112+
const DEFAULT_INSTALLATION_DIRECTORIES: &'static [&'static str] = &[];
113+
}
114+
}
103115

104116
const KNOWN_INSTALLATION_SUBDIRECTORIES: &'static [&'static str] = &[
105117
"deployment_tools/ngraph/lib",

0 commit comments

Comments
 (0)