Reorganize cargo module-features
MODIFY
Cargo.toml
Cargo.toml
@@ -61,21 +61,75 @@ rgb = { version = "0.8.27", features = ["argb"], optional = true }
[features]
clang-runtime = ["clang/runtime"]
docs-only = []
-default = ["all-modules"]
-
-# OpenCV modules
-all-modules = [
- "alphamat", "aruco", "barcode", "bgsegm", "bioinspired", "calib3d", "ccalib", "cudaarithm",
- "cudabgsegm", "cudacodec", "cudafeatures2d", "cudafilters", "cudaimgproc", "cudaobjdetect",
- "cudaoptflow", "cudastereo", "cudawarping", "cvv", "dnn", "dnn_superres", "dpm", "face",
- "features2d", "flann", "freetype", "fuzzy", "gapi", "hdf", "hfs", "highgui", "img_hash",
- "imgcodecs", "imgproc", "intensity_transform", "line_descriptor", "mcc", "ml", "objdetect",
- "optflow", "ovis", "phase_unwrapping", "photo", "plot", "quality", "rapid", "rgbd", "saliency",
- "sfm", "shape", "stereo", "stitching", "structured_light", "superres", "surface_matching",
- "text", "tracking", "video", "videoio", "videostab", "viz", "xfeatures2d", "ximgproc",
- "xobjdetect", "xphoto", "wechat_qrcode",
+default = [
+ "alphamat",
+ "aruco",
+ "barcode",
+ "bgsegm",
+ "bioinspired",
+ "calib3d",
+ "ccalib",
+ "cudaarithm",
+ "cudabgsegm",
+ "cudacodec",
+ "cudafeatures2d",
+ "cudafilters",
+ "cudaimgproc",
+ "cudaobjdetect",
+ "cudaoptflow",
+ "cudastereo",
+ "cudawarping",
+ "cvv",
+ "dnn",
+ "dnn_superres",
+ "dpm",
+ "face",
+ "features2d",
+ "flann",
+ "freetype",
+ "fuzzy",
+ "gapi",
+ "hdf",
+ "hfs",
+ "highgui",
+ "img_hash",
+ "imgcodecs",
+ "imgproc",
+ "intensity_transform",
+ "line_descriptor",
+ "mcc",
+ "ml",
+ "objdetect",
+ "optflow",
+ "ovis",
+ "phase_unwrapping",
+ "photo",
+ "plot",
+ "quality",
+ "rapid",
+ "rgbd",
+ "saliency",
+ "sfm",
+ "shape",
+ "stereo",
+ "stitching",
+ "structured_light",
+ "superres",
+ "surface_matching",
+ "text",
+ "tracking",
+ "video",
+ "videoio",
+ "videostab",
+ "viz",
+ "xfeatures2d",
+ "ximgproc",
+ "xobjdetect",
+ "xphoto",
+ "wechat_qrcode",
]
+# OpenCV modules
alphamat = []
aruco = []
barcode = []

MODIFY
README.md
README.md
@@ -253,13 +253,15 @@ The following variables affect the building the of the `opencv` crate, but belon
See crate's [README](https://github.com/KyleMayes/clang-sys/blob/master/README.md#environment-variables)
## Cargo features
+* There is a feature named after each OpenCV module (e.g. `imgproc`, `highgui`, etc.). They are all enabled by
+ default, but if a corresponding module is not found then it will silently be ignored. If you need to select a
+ specific set of modules be sure to disable the default features and provide the required feature set:
+ ```
+ opencv = { version = ..., default-features = false, features = ["calib3d", "features2d", "flann"]}
+ ```
* `clang-runtime` - enables the runtime detection of libclang (`runtime` feature of `clang-sys`). Useful as a
workaround for when your dependencies (like `bindgen`) pull in `clang-sys` with hard `runtime` feature.
* `docs-only` - internal usage, for building docs on [docs.rs](https://docs.rs/opencv)
-* `all-modules` - include all OpenCV modules. This is the default.
-* If you don't want to include all modules you can specify the module name as a feature. Make sure to include
- all dependent modules, e.g.
- `opencv = { version = ..., default-features = false, features = ["calib3d", "features2d", "flann"]}`.
## API details

MODIFY
build.rs
build.rs
@@ -138,20 +138,22 @@ fn get_version_from_headers(header_dir: &Path) -> Option<Version> {
}
fn make_modules(opencv_dir: &Path) -> Result<()> {
- let ignore_modules: HashSet<&'static str> = [
+ let ignore_modules = IntoIterator::into_iter([
"core_detect",
"cudalegacy",
"cudev",
"gapi",
"opencv",
"opencv_modules",
- ].iter().copied().collect();
+ ]).collect::<HashSet<_>>();
- let enable_modules = [
- "core"
- ].iter().map(ToString::to_string).chain(env::vars_os().filter_map(|(k, _)|
- k.to_str().and_then(|s| s.strip_prefix("CARGO_FEATURE_").map(str::to_lowercase))
- )).collect::<HashSet<_>>();
+ let enable_modules = IntoIterator::into_iter(["core".to_string()])
+ .chain(env::vars_os()
+ .filter_map(|(k, _)| k.to_str()
+ .and_then(|s| s.strip_prefix("CARGO_FEATURE_"))
+ .map(str::to_lowercase)
+ )
+ ).collect::<HashSet<_>>();
let modules = glob(&format!("{}/*.hpp", opencv_dir.to_str().ok_or("Can't OpenCV header directory to UTF-8 string")?))?
.filter_map(|entry| {

Reorganize cargo module-features