Skip to content

Commit c4d0a9e

Browse files
authored
Add cargo clippy and cargo deny scans to CI (#36)
* Add strict clippy scanning to crates This change configures rather pedantic settings for `cargo clippy`. These crates, as bindings to an underlying API, use a limited subset of the language so very few settings need to be ignored. If the `clippy::pedantic` warnings become burdensome in the future, this can be removed, but this commit makes the necessary changes to run without warnings. * ci: add clippy checking to CI workflow * Use `cargo deny` to check for vulnerable dependencies This change adds a way in CI to verify that dependencies have no outstanding vulnerabilities. It also upgrades the regex crate which had a reported performance-affecting vulnerability.
1 parent 59e1fa9 commit c4d0a9e

File tree

31 files changed

+236
-120
lines changed

31 files changed

+236
-120
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,19 @@ jobs:
1919
submodules: true
2020
- run: rustup component add rustfmt
2121
- run: cargo fmt --all -- --check
22+
# Use the `runtime-linking` feature here to avoid requiring an OpenVINO installation to be
23+
# present when building.
24+
- run: cargo clippy --features runtime-linking
2225
- run: cd crates/openvino-tensor-converter && cargo fmt --all -- --check
2326

24-
# Build and test from the git-submodule-included OpenVINO source code.
27+
rust_dependencies:
28+
name: Check Rust dependencies
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v2
32+
- uses: EmbarkStudios/cargo-deny-action@v1
33+
34+
# Build and test from the git-submodule-included OpenVINO source code.
2535
source:
2636
name: From source
2737
runs-on: ubuntu-20.04

Cargo.lock

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

clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
doc-valid-idents = ["OpenVINO"]

crates/openvino-finder/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ readme = "README.md"
77
authors = ["OpenVINO Project Developers"]
88
repository = "https://github.com/intel/openvino-rs"
99
documentation = "https://docs.rs/openvino-finder"
10+
keywords = ["openvino", "machine-learning", "ml", "neural-network"]
11+
categories = ["development-tools"]
1012
edition = "2018"
1113

1214
[dependencies]

crates/openvino-finder/src/lib.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//! Provides a mechanism for locating the OpenVINO shared libraries installed on a system.
2+
3+
#![deny(missing_docs)]
4+
#![deny(clippy::all)]
5+
#![warn(clippy::pedantic)]
6+
#![warn(clippy::cargo)]
7+
#![allow(clippy::must_use_candidate)]
8+
19
use cfg_if::cfg_if;
210
use std::env;
311
use std::path::PathBuf;
@@ -82,46 +90,46 @@ pub fn find(library_name: &str) -> Option<PathBuf> {
8290
None
8391
}
8492

85-
const ENV_OPENVINO_INSTALL_DIR: &'static str = "OPENVINO_INSTALL_DIR";
86-
const ENV_OPENVINO_BUILD_DIR: &'static str = "OPENVINO_BUILD_DIR";
87-
const ENV_INTEL_OPENVINO_DIR: &'static str = "INTEL_OPENVINO_DIR";
93+
const ENV_OPENVINO_INSTALL_DIR: &str = "OPENVINO_INSTALL_DIR";
94+
const ENV_OPENVINO_BUILD_DIR: &str = "OPENVINO_BUILD_DIR";
95+
const ENV_INTEL_OPENVINO_DIR: &str = "INTEL_OPENVINO_DIR";
8896

8997
cfg_if! {
9098
if #[cfg(any(target_os = "linux"))] {
91-
const ENV_LIBRARY_PATH: &'static str = "LD_LIBRARY_PATH";
99+
const ENV_LIBRARY_PATH: &str = "LD_LIBRARY_PATH";
92100
} else if #[cfg(target_os = "macos")] {
93-
const ENV_LIBRARY_PATH: &'static str = "DYLD_LIBRARY_PATH";
101+
const ENV_LIBRARY_PATH: &str = "DYLD_LIBRARY_PATH";
94102
} else if #[cfg(target_os = "windows")] {
95-
const ENV_LIBRARY_PATH: &'static str = "PATH";
103+
const ENV_LIBRARY_PATH: &str = "PATH";
96104
} else {
97105
// 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";
106+
const ENV_LIBRARY_PATH: &str = "LD_LIBRARY_PATH";
99107
}
100108
}
101109

102110
cfg_if! {
103111
if #[cfg(any(target_os = "linux", target_os = "macos"))] {
104-
const DEFAULT_INSTALLATION_DIRECTORIES: &'static [&'static str] =
112+
const DEFAULT_INSTALLATION_DIRECTORIES: & [& str] =
105113
&["/opt/intel/openvino_2021", "/opt/intel/openvino"];
106114
} else if #[cfg(target_os = "windows")] {
107-
const DEFAULT_INSTALLATION_DIRECTORIES: &'static [&'static str] = &[
115+
const DEFAULT_INSTALLATION_DIRECTORIES: & [& str] = &[
108116
"C:\\Program Files (x86)\\Intel\\openvino",
109117
"C:\\Program Files (x86)\\Intel\\openvino_2021",
110118
];
111119
} else {
112-
const DEFAULT_INSTALLATION_DIRECTORIES: &'static [&'static str] = &[];
120+
const DEFAULT_INSTALLATION_DIRECTORIES: & [& str] = &[];
113121
}
114122
}
115123

116-
const KNOWN_INSTALLATION_SUBDIRECTORIES: &'static [&'static str] = &[
124+
const KNOWN_INSTALLATION_SUBDIRECTORIES: &[&str] = &[
117125
"deployment_tools/ngraph/lib",
118126
"deployment_tools/inference_engine/lib/intel64",
119127
"deployment_tools/inference_engine/external/hddl/lib",
120128
"deployment_tools/inference_engine/external/gna/lib",
121129
"deployment_tools/inference_engine/external/tbb/lib",
122130
];
123131

124-
const KNOWN_BUILD_SUBDIRECTORIES: &'static [&'static str] = &[
132+
const KNOWN_BUILD_SUBDIRECTORIES: &[&str] = &[
125133
"bin/intel64/Debug/lib",
126134
"bin/intel64/Release/lib",
127135
"inference-engine/temp/tbb/lib",

crates/openvino-sys/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ readme = "README.md"
77
authors = ["OpenVINO Project Developers"]
88
repository = "https://github.com/intel/openvino-rs"
99
documentation = "https://docs.rs/openvino-sys"
10+
keywords = ["external-ffi-bindings", "openvino", "machine-learning", "ml", "neural-network"]
11+
categories = ["external-ffi-bindings", "science"]
1012
edition = "2018"
1113
include = [
1214
"/Cargo.toml",

crates/openvino-sys/build.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use cmake;
21
use std::env;
32
use std::path::{Path, PathBuf};
43

54
// These are the libraries we expect to be available to dynamically link to:
6-
const LIBRARIES: &'static [&'static str] = &[
5+
const LIBRARIES: &[&str] = &[
76
"inference_engine",
87
"inference_engine_legacy",
98
"inference_engine_transformations",
@@ -14,11 +13,11 @@ const LIBRARIES: &'static [&'static str] = &[
1413

1514
// A user-specified environment variable indicating that `build.rs` should not attempt to link
1615
// against any libraries (e.g. a doc build, user may link them later).
17-
const ENV_OPENVINO_SKIP_LINKING: &'static str = "OPENVINO_SKIP_LINKING";
16+
const ENV_OPENVINO_SKIP_LINKING: &str = "OPENVINO_SKIP_LINKING";
1817

1918
// A build.rs-specified environment variable that must be populated with the location of the
2019
// inference engine library that OpenVINO is being linked to in this script.
21-
const ENV_OPENVINO_LIB_PATH: &'static str = "OPENVINO_LIB_PATH";
20+
const ENV_OPENVINO_LIB_PATH: &str = "OPENVINO_LIB_PATH";
2221

2322
fn main() {
2423
// Trigger rebuild on changes to build.rs and Cargo.toml and every source file.

crates/openvino-sys/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@
1515
//! let version = unsafe { CStr::from_ptr(openvino_sys::ie_c_api_version().api_version) };
1616
//! assert!(version.to_string_lossy().starts_with("2"));
1717
//! ```
18-
#![allow(non_upper_case_globals)]
19-
#![allow(non_camel_case_types)]
20-
#![allow(non_snake_case)]
21-
#![allow(dead_code)]
18+
19+
#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
20+
#![allow(unused, dead_code)]
21+
#![deny(clippy::all)]
22+
#![warn(clippy::pedantic)]
23+
#![warn(clippy::cargo)]
24+
#![allow(clippy::must_use_candidate)]
25+
#![allow(clippy::wildcard_imports)]
2226

2327
mod linking;
2428

crates/openvino-sys/src/linking/dynamic.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ macro_rules! link {
1212
) => (
1313
/// When compiled as a dynamically-linked library, this function does nothing. It exists to
1414
/// provide a consistent API with the runtime-linked version.
15+
///
16+
/// # Errors
17+
///
18+
/// This version never fails.
1519
pub fn load() -> Result<(), String> {
1620
Ok(())
1721
}

crates/openvino-sys/src/linking/runtime.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ macro_rules! link {
4343
where
4444
F: FnOnce(&SharedLibrary) -> T,
4545
{
46-
match LIBRARY.read().unwrap().as_ref() {
47-
Some(library) => Some(f(&library)),
48-
_ => None,
49-
}
46+
LIBRARY.read().unwrap().as_ref().map(|library| f(&library))
5047
}
5148

5249
// The set of functions loaded dynamically.
@@ -74,6 +71,10 @@ macro_rules! link {
7471
}
7572

7673
/// Load all of the function definitions from a shared library.
74+
///
75+
/// # Errors
76+
///
77+
/// May fail if the `openvino-finder` cannot discover the library on the current system.
7778
pub fn load() -> Result<(), String> {
7879
match crate::library::find() {
7980
None => Err("Unable to find the `inference_engine_c_api` library to load".into()),

0 commit comments

Comments
 (0)