Skip to content

Commit b84ddb5

Browse files
committed
Handle "plugin not found" cases more gracefully
OpenVINO can be configured with a `plugins.xml` file that points to libraries for running inferences on other devices. Previously, if this file was not provided and `openvino-finder` could not find it, the bindings crate would fail with an error. But this is not always necessary: if the plugin libraries are located in the same directory as the OpenVINO library, then a `plugins.xml` file is not needed. This is the case for APT-installed versions of the package, e.g. In these cases, we can pass an empty string to inform OpenVINO to look in the same directory as the main library ([example]). [example]: https://github.com/openvinotoolkit/openvino/blob/05a24b17769cb634f16343d551e25f542f0855b1/docs/snippets/ie_common.c#L14
1 parent f4af2fc commit b84ddb5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

crates/openvino/src/core.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ impl Core {
2929
pub fn new(xml_config_file: Option<&str>) -> std::result::Result<Core, SetupError> {
3030
openvino_sys::library::load().map_err(LoadingError::SystemFailure)?;
3131

32-
let file = match xml_config_file {
33-
None => openvino_finder::find_plugins_xml()
34-
.ok_or(LoadingError::CannotFindPluginPath)?
32+
let file = if let Some(file) = xml_config_file {
33+
cstr!(file.to_string())
34+
} else if let Some(file) = openvino_finder::find_plugins_xml() {
35+
cstr!(file
3536
.to_str()
3637
.ok_or(LoadingError::CannotStringifyPath)?
37-
.to_string(),
38-
Some(f) => f.to_string(),
38+
.to_string())
39+
} else {
40+
cstr!("".to_string())
3941
};
42+
4043
let mut instance = std::ptr::null_mut();
41-
try_unsafe!(ie_core_create(
42-
cstr!(file),
43-
std::ptr::addr_of_mut!(instance)
44-
))?;
44+
try_unsafe!(ie_core_create(file, std::ptr::addr_of_mut!(instance)))?;
4545
Ok(Core { instance })
4646
}
4747

0 commit comments

Comments
 (0)