@@ -138,7 +138,7 @@ fn add_dynamically_linked_library(library: &str) {
138
138
///
139
139
/// It would be preferable to use pkg-config here to retrieve the libraries when they are
140
140
/// installed system-wide but there are issues:
141
- /// - OpenVINO does not install itself a system library, e.g., through ldconfig.
141
+ /// - OpenVINO does not install itself a system library, e.g., through ldconfig.;
142
142
/// - OpenVINO relies on a `plugins.xml` file for finding target-specific libraries
143
143
/// and it is unclear how we would discover this in a system-install scenario.
144
144
fn find_libraries_in_existing_installation ( ) -> Vec < PathBuf > {
@@ -166,37 +166,56 @@ fn find_libraries_in_existing_installation() -> Vec<PathBuf> {
166
166
/// Build OpenVINO with CMake. TODO this currently will not work when the crate is published
167
167
/// because the `upstream` directory will not fit inside the 10MB crate limit. To solve this, we
168
168
/// could retrieve the sources (cringe), e.g., with `git2`.
169
+ ///
170
+ /// See https://github.com/openvinotoolkit/openvino/wiki/BuildingForLinux.
169
171
fn build_from_source_using_cmake ( ) -> ( Option < PathBuf > , Vec < PathBuf > ) {
170
172
let out = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
173
+ let out_as_str = out. to_str ( ) . unwrap ( ) ;
171
174
172
175
fn cmake ( out_dir : & str ) -> cmake:: Config {
173
176
let mut config = cmake:: Config :: new ( "upstream" ) ;
174
177
config
175
178
. very_verbose ( true )
176
- . define ( "NGRAPH_ONNX_IMPORT_ENABLE" , "ON" )
177
- . define ( "ENABLE_OPENCV" , "OFF" )
179
+ // Disable code maintenance features.
178
180
. define ( "ENABLE_CPPLINT" , "OFF" )
181
+ . define ( "ENABLE_CLANG_FORMAT" , "OFF" )
182
+ . define ( "ENABLE_NCC_STYLE" , "OFF" )
183
+ // Disable unnecessary targets; these are enabled by default (see
184
+ // https://github.com/openvinotoolkit/openvino/wiki/CMakeOptionsForCustomCompilation).
185
+ // We still need `ENABLE_OV_IR_FRONTEND` (enabled by default) since it is what reads the
186
+ // OpenVINO model files. Still unsure if `ENABLE_GAPI_PREPROCESSING` is needed.
187
+ . define ( "ENABLE_OPENCV" , "OFF" )
188
+ . define ( "ENABLE_OV_ONNX_FRONTEND" , "OFF" )
189
+ . define ( "ENABLE_OV_PADDLE_FRONTEND" , "OFF" )
190
+ . define ( "ENABLE_OV_PDPD_FRONTEND" , "OFF" )
191
+ . define ( "ENABLE_OV_TF_FRONTEND" , "OFF" )
192
+ . define ( "ENABLE_SAMPLES" , "OFF" )
179
193
// As described in https://github.com/intel/openvino-rs/issues/8, the OpenVINO source
180
194
// includes redundant moves. These were previously warnings but newer compilers treat
181
195
// them as errors.
182
196
. cxxflag ( "-Wno-error=redundant-move" )
197
+ . cxxflag ( "-Wno-error=uninitialized" )
183
198
// Because OpenVINO by default wants to build its binaries in its own tree, we must
184
199
// specify that we actually want them in Cargo's output directory.
185
200
. define ( "OUTPUT_ROOT" , out_dir) ;
201
+
202
+ // Enable or disable each plugin's CMake feature. It is unclear if this adding/removing of
203
+ // CMake features is truly needed since we are manually choosing the plugin CMake targets,
204
+ // but we do it here to be safe.
205
+ apply_plugin_features ( & mut config) ;
206
+
186
207
config
187
208
}
188
209
189
210
// Specifying the build targets reduces the build time somewhat; this one will trigger
190
- // builds for other necessary shared libraries (e.g., `openvino`).
191
- let build_path = cmake ( out. to_str ( ) . unwrap ( ) )
192
- . build_target ( "openvino_c" )
193
- . build ( ) ;
211
+ // builds for other necessary shared libraries (e.g., `openvino`, `tbb`).
212
+ let build_path = cmake ( out_as_str) . build_target ( "openvino_c" ) . build ( ) ;
194
213
195
214
// Unfortunately, `openvino_c` will not build the OpenVINO plugins used for
196
215
// the actual computation. Here we re-run CMake for each plugin the user specifies using
197
216
// Cargo features (see `Cargo.toml`).
198
217
for plugin in get_plugin_target_from_features ( ) {
199
- cmake ( out . to_str ( ) . unwrap ( ) ) . build_target ( plugin) . build ( ) ;
218
+ cmake ( out_as_str ) . build_target ( plugin) . build ( ) ;
200
219
}
201
220
202
221
// Collect the locations of the libraries. Note that ngraph should also be found with the
@@ -212,7 +231,7 @@ fn build_from_source_using_cmake() -> (Option<PathBuf>, Vec<PathBuf>) {
212
231
// pre-installed libtbb (on some systems, the nodes_count symbol is not present in the
213
232
// system-provided libtbb) so it may be important to include OpenVINO's version of libtbb
214
233
// here.
215
- let tbb_libraries = dir ( "upstream/inference-engine/ temp/tbb/lib" ) ;
234
+ let tbb_libraries = dir ( "upstream/temp/tbb/lib" ) ;
216
235
visit_dirs ( & tbb_libraries, & |from : PathBuf | {
217
236
let to = openvino_libraries. join ( from. file_name ( ) . unwrap ( ) ) ;
218
237
println ! ( "Copying {} to {}" , from. display( ) , to. display( ) ) ;
@@ -232,37 +251,66 @@ fn build_from_source_using_cmake() -> (Option<PathBuf>, Vec<PathBuf>) {
232
251
}
233
252
234
253
/// Determine CMake targets for the various OpenVINO plugins. The plugin mapping is available in
235
- /// OpenVINO's `plugins.xml` file and, usign that, this function wires up the exposed Cargo
236
- /// features of openvino-sys to the correct CMake target.
254
+ /// OpenVINO's `plugins.xml` file and, using that, this function wires up the exposed Cargo
255
+ /// features of openvino-sys to the correct CMake target. Run `cmake --build . --target help` in
256
+ /// an upstream CMake build directory to see a list of these.
237
257
fn get_plugin_target_from_features ( ) -> Vec < & ' static str > {
238
258
let mut plugins = vec ! [ ] ;
239
259
if cfg ! ( feature = "all" ) {
240
260
plugins. push ( "ie_plugins" )
241
261
} else {
242
262
if cfg ! ( feature = "cpu" ) {
243
- plugins. push ( "MKLDNNPlugin " )
263
+ plugins. push ( "openvino_intel_cpu_plugin " )
244
264
}
245
265
if cfg ! ( feature = "gpu" ) {
246
- plugins. push ( "clDNNPlugin " )
266
+ plugins. push ( "openvino_intel_gpu_plugin " )
247
267
}
248
268
if cfg ! ( feature = "gna" ) {
249
- plugins. push ( "GNAPlugin " )
269
+ plugins. push ( "openvino_intel_gna_plugin " )
250
270
}
251
271
if cfg ! ( feature = "hetero" ) {
252
- plugins. push ( "HeteroPlugin" )
272
+ plugins. push ( "openvino_hetero_plugin" )
273
+ }
274
+ if cfg ! ( feature = "auto" ) {
275
+ plugins. push ( "openvino_auto_plugin" )
253
276
}
254
- if cfg ! ( feature = "multi " ) {
255
- plugins. push ( "MultiDevicePlugin " )
277
+ if cfg ! ( feature = "auto_batch " ) {
278
+ plugins. push ( "openvino_auto_batch_plugin " )
256
279
}
257
280
if cfg ! ( feature = "myriad" ) {
258
- plugins. push ( "myriadPlugin " )
281
+ plugins. push ( "openvino_intel_myriad_plugin " )
259
282
}
260
283
}
261
284
assert ! ( !plugins. is_empty( ) ) ;
262
285
plugins
263
286
}
264
287
265
- /// According to https://docs.rs/cmake/0.1.44/cmake/struct.Config.html#method.profile, the cmake
288
+ /// Apply CMake `ENABLE_*` features for each of Cargo's plugin features; see `Cargo.toml`. For
289
+ /// example, running `cargo build --features gpu` should set `ENABLE_INTEL_GPU=ON` and set all
290
+ /// others to `OFF`. See
291
+ /// https://github.com/openvinotoolkit/openvino/wiki/CMakeOptionsForCustomCompilation.
292
+ fn apply_plugin_features ( config : & mut cmake:: Config ) {
293
+ macro_rules! apply {
294
+ ( $cargo_feature: literal, $cmake_feature: literal) => {
295
+ if cfg!( feature = $cargo_feature) {
296
+ config. define( $cmake_feature, "ON" ) ;
297
+ } else {
298
+ config. define( $cmake_feature, "OFF" ) ;
299
+ }
300
+ } ;
301
+ }
302
+
303
+ apply ! ( "cpu" , "ENABLE_INTEL_CPU" ) ;
304
+ apply ! ( "gpu" , "ENABLE_INTEL_GPU" ) ;
305
+ apply ! ( "gna" , "ENABLE_INTEL_GNA" ) ;
306
+ apply ! ( "myriad" , "ENABLE_INTEL_MYRIAD" ) ;
307
+ apply ! ( "auto" , "ENABLE_AUTO" ) ;
308
+ apply ! ( "auto_batch" , "ENABLE_AUTO_BATCH" ) ;
309
+ apply ! ( "hetero" , "ENABLE_HETERO" ) ;
310
+ apply ! ( "multi" , "ENABLE_MULTI" ) ;
311
+ }
312
+
313
+ /// According to https://docs.rs/cmake/0.1.44/cmake/struct.Config.html#method.profile, the cmake;
266
314
/// crate will tries to infer the appropriate CMAKE_BUILD_TYPE from a combination of Rust opt-level
267
315
/// and debug. To avoid duplicating https://docs.rs/cmake/0.1.44/src/cmake/lib.rs.html#553-559, this
268
316
/// helper searches for build type directories and appends it to the path if a result is found; this
0 commit comments