Skip to content

Commit 95f29ef

Browse files
authored
Remove the from-source feature (#39)
Prior to this change, the `openvino-sys` crate had the ability to build OpenVINO from source using CMake from within its `build.rs` script. This increased complexity in various places (documentation, `Cargo.toml` features, `build.rs`) and was prone to breakage as OpenVINO modified its available CMake build features. Instead of providing a `from-source` feature to do all this, this change documents an `OPENVINO_BUILD_DIR` environment variable that can be used for the same purpose: once a user has built OpenVINO from source on their system, they can provide the path to this repository for the `openvino-sys` crate to bind to. The `openvino-finder` crate contains the necessary paths to find the default locations of all of required libraries.
1 parent e687811 commit 95f29ef

File tree

6 files changed

+52
-280
lines changed

6 files changed

+52
-280
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,6 @@ jobs:
3131
- uses: actions/checkout@v2
3232
- uses: EmbarkStudios/cargo-deny-action@v1
3333

34-
# Build and test from the git-submodule-included OpenVINO source code.
35-
source:
36-
name: From source
37-
runs-on: ubuntu-20.04
38-
steps:
39-
- uses: actions/checkout@v2
40-
with:
41-
submodules: recursive
42-
lfs: true
43-
- name: Checkout LFS obects
44-
run: git lfs checkout
45-
- name: Install system dependencies
46-
run: sudo apt update && sudo apt install -y clang cmake libclang-dev gnupg2 libdrm2 libglib2.0-0 libusb-1.0-0-dev lsb-release libgtk-3-0 libtool udev unzip dos2unix
47-
- name: Build (openvino-sys from source)
48-
run: cargo build --verbose --features openvino-sys/from-source
49-
- name: Run tests
50-
# For some reason the library path is not set during the doc tests (`--doc`, see
51-
# https://doc.rust-lang.org/cargo/commands/cargo-test.html#target-selection) so we skip them
52-
# here: issue at https://github.com/intel/openvino-rs/issues/25. Also, the `from-source` build
53-
# does not know how to run the inception SSD test.
54-
run: cargo test --verbose --features openvino-sys/from-source --lib --tests -- --skip detect_inception
55-
5634
# Build and test from an existing OpenVINO installation inside a Docker image (i.e. download the
5735
# binaries, then compile against these).
5836
dynamic_binaries:

Cargo.lock

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

README.md

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
This repository contains the [openvino-sys] crate (low-level, unsafe bindings) and the [openvino]
77
crate (high-level, ergonomic bindings) for accessing OpenVINO™ functionality in Rust.
88

9-
[openvino-sys]: crates/openvino-sys
109
[openvino]: crates/openvino
10+
[openvino-sys]: crates/openvino-sys
11+
[openvino-finder]: crates/openvino-finder
1112
[upstream]: crates/openvino-sys/upstream
1213
[docs]: https://docs.rs/openvino
1314
[ci]: https://github.com/abrown/openvino-rs/actions?query=workflow%3ACI
@@ -39,15 +40,14 @@ source /opt/intel/openvino/setupvars.sh
3940
cargo test
4041
```
4142

42-
The quickest method to build [openvino] and [openvino-sys] is with a local installation of OpenVINO™
43-
(see, e.g., [installing from an apt repository][install-apt]). The build script will attempt to
44-
locate an existing installation (see [openvino-finder]) and link against its shared libraries.
45-
Provide the `OPENVINO_INSTALL_DIR` environment variable to point at a specific installation. Ensure
46-
that the correct libraries are available on the system's load path; OpenVINO™'s `setupvars.sh`
47-
script will do this automatically.
43+
The quickest method to build the [openvino] and [openvino-sys] crates is with a local installation
44+
of OpenVINO™ (see, e.g., [installing from an apt repository][install-apt]). The build script will
45+
attempt to locate an existing installation (see [openvino-finder]) and link against its shared
46+
libraries. Provide the `OPENVINO_INSTALL_DIR` environment variable to point at a specific
47+
installation. Ensure that the correct libraries are available on the system's load path; OpenVINO™'s
48+
`setupvars.sh` script will do this automatically.
4849

4950
[install-apt]: https://docs.openvinotoolkit.org/latest/openvino_docs_install_guides_installing_openvino_apt.html
50-
[openvino-finder]: crates/openvino-finder
5151

5252

5353

@@ -70,26 +70,28 @@ high-level users, call `openvino::Core::new` first to automatically load and lin
7070

7171
### Build from OpenVINO™ sources
7272

73+
First, build OpenVINO by cloning the [openvino] repository and following the [OpenVINO™ build
74+
documentation]. Then, using the top-level directory as `<openvino-repo>` (not the CMake build
75+
directory), build this crate:
76+
7377
```shell script
74-
git submodule update --init --recursive
75-
cargo build -vv --features openvino-sys/from-source
76-
cargo test --features openvino-sys/from-source
78+
OPENVINO_BUILD_DIR=<openvino-repo> cargo build
79+
OPENVINO_BUILD_DIR=<openvino-repo> cargo test
7780
```
7881

79-
[openvino] and [openvino-sys] can also be built directly from OpenVINO™'s source code using CMake.
80-
This is not tested across all OS and OpenVINO™ versions--use at your own risk! Also, this build
81-
process can be quite slow and there are quite a few dependencies. Some notes:
82-
- first, install the necessary packages to build OpenVINO™; steps are included in the [CI
83-
workflow](.github/workflows)
84-
but reference the [OpenVINO™ build documentation](https://github.com/openvinotoolkit/openvino/blob/master/build-instruction.md)
85-
for the full documentation
86-
- OpenVINO™ has a plugin system for device-specific libraries (e.g. GPU); building all of these
87-
libraries along with the core inference libraries can take >20 minutes. To avoid over-long build
88-
times, [openvino-sys] exposes several Cargo features. By default, [openvino-sys] will only build
89-
the CPU plugin; to build all plugins, use `--features all` (see
90-
[Cargo.toml](crates/openvino-sys/Cargo.toml)).
91-
- OpenVINO™ includes other libraries (e.g. ngraph, tbb); see the
92-
[build.rs](crates/openvino-sys/build.rs) file for how these are linked to these libraries.
82+
Some important notes about the path passed in `OPENVINO_BUILD_DIR`:
83+
- `<openvino-repo>` should be an absolute path (or at least a path relative to the
84+
`crates/openvino-sys` directory, which is the current directory when used at build time)
85+
- `<openvino-repo>` should either be outside of this crate's tree or in the `target` directory (see
86+
the limitations on [`cargo:rustc-link-search`]).
87+
88+
The various OpenVINO libraries and dependencies are found using the [openvino-finder] crate. Turn on
89+
logging to troubleshoot any issues finding the right libraries, e.g., `RUST_LOG=info
90+
OPENVINO_BUILD_DIR=... cargo build -vv`.
91+
92+
[openvino]: https://github.com/openvinotoolkit/openvino
93+
[OpenVINO™ build documentation]: https://github.com/openvinotoolkit/openvino/blob/master/build-instruction.md
94+
[`cargo:rustc-link-search`]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-search
9395

9496

9597

crates/openvino-finder/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ pub fn find(library_name: &str) -> Option<PathBuf> {
3535
};
3636
}
3737

38-
// Search using the `OPENVINO_INSTALL_DIR` environment variable; this may be set by users of the
38+
// Search using the `OPENVINO_BUILD_DIR` environment variable; this may be set by users of the
3939
// `openvino-rs` library.
40-
if let Some(install_dir) = env::var_os(ENV_OPENVINO_INSTALL_DIR) {
41-
let install_dir = PathBuf::from(install_dir);
42-
for lib_dir in KNOWN_INSTALLATION_SUBDIRECTORIES {
40+
if let Some(build_dir) = env::var_os(ENV_OPENVINO_BUILD_DIR) {
41+
let install_dir = PathBuf::from(build_dir);
42+
for lib_dir in KNOWN_BUILD_SUBDIRECTORIES {
4343
let search_path = install_dir.join(lib_dir).join(&file);
4444
check_and_return!(search_path);
4545
}
4646
}
4747

48-
// Search using the `OPENVINO_BUILD_DIR` environment variable; this may be set by users of the
48+
// Search using the `OPENVINO_INSTALL_DIR` environment variable; this may be set by users of the
4949
// `openvino-rs` library.
50-
if let Some(build_dir) = env::var_os(ENV_OPENVINO_BUILD_DIR) {
51-
let install_dir = PathBuf::from(build_dir);
52-
for lib_dir in KNOWN_BUILD_SUBDIRECTORIES {
50+
if let Some(install_dir) = env::var_os(ENV_OPENVINO_INSTALL_DIR) {
51+
let install_dir = PathBuf::from(install_dir);
52+
for lib_dir in KNOWN_INSTALLATION_SUBDIRECTORIES {
5353
let search_path = install_dir.join(lib_dir).join(&file);
5454
check_and_return!(search_path);
5555
}

crates/openvino-sys/Cargo.toml

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,13 @@ libloading = {version = "0.7", optional = true }
3030
openvino-finder = {version = "0.3.3", path = "../openvino-finder" }
3131

3232
[build-dependencies]
33-
cmake = "0.1.45"
3433
openvino-finder = {version = "0.3.3", path = "../openvino-finder" }
34+
pretty_env_logger = "0.4"
3535

3636
[features]
37-
default = ["cpu"]
38-
39-
# Plugin features: if building from source, this allows selecting which OpenVINO plugins to build.
40-
all = ["auto", "auto_batch", "cpu", "gpu", "gna", "hetero", "myriad", "multi"]
41-
auto = []
42-
auto_batch = []
43-
cpu = []
44-
gpu = []
45-
gna = []
46-
hetero = []
47-
myriad = []
48-
multi = []
49-
5037
# Linking features: `build.rs` will default to dynamic linking if none is selected.
5138
dynamic-linking = [] # Will find and bind to an OpenVINO shared library at compile time.
5239
runtime-linking = ["libloading", "lazy_static"] # Will bind to an OpenVINO shared library at runtime using `load`.
5340

54-
# Build features: `build.rs` will attempt to build OpenVINO from source and then link to this.
55-
from-source = []
56-
5741
[package.metadata.docs.rs]
5842
features = ["runtime-linking"]

0 commit comments

Comments
 (0)