From 921fa4a9ab81d8edc9d65c37ad78faa965bc7277 Mon Sep 17 00:00:00 2001 From: Pro Date: Thu, 25 Jul 2024 22:38:34 +0200 Subject: [PATCH] Cleanup --- binding-generator/src/class.rs | 4 ++ build.rs | 78 +++++++++++++++++++++++++++++++++- build/generator.rs | 2 +- src/opencv.rs | 1 + 4 files changed, 83 insertions(+), 2 deletions(-) diff --git a/binding-generator/src/class.rs b/binding-generator/src/class.rs index 4b4106c1f..9d8be59de 100644 --- a/binding-generator/src/class.rs +++ b/binding-generator/src/class.rs @@ -255,6 +255,7 @@ impl<'tu, 'ge> Class<'tu, 'ge> { } pub fn all_bases(&self) -> HashSet> { + #![allow(clippy::mutable_key_type)] #[allow(clippy::unnecessary_to_owned)] self .bases() @@ -276,6 +277,7 @@ impl<'tu, 'ge> Class<'tu, 'ge> { } pub fn descendants(&self) -> HashSet> { + #![allow(clippy::mutable_key_type)] match self { &Self::Clang { gen_env, .. } => gen_env .descendants_of(&self.cpp_name(CppNameStyle::Reference)) @@ -287,6 +289,7 @@ impl<'tu, 'ge> Class<'tu, 'ge> { } pub fn all_descendants(&self) -> HashSet> { + #![allow(clippy::mutable_key_type)] self .descendants() .into_iter() @@ -299,6 +302,7 @@ impl<'tu, 'ge> Class<'tu, 'ge> { } pub fn all_family(&self) -> HashSet> { + #![allow(clippy::mutable_key_type)] fn collect<'tu, 'ge>(out: &mut HashSet>, cls: Class<'tu, 'ge>) { if out.insert(cls.clone()) { #[allow(clippy::unnecessary_to_owned)] diff --git a/build.rs b/build.rs index e27244068..5d1d42273 100644 --- a/build.rs +++ b/build.rs @@ -27,8 +27,9 @@ mod library; type Result> = std::result::Result; -static MODULES: OnceCell> = OnceCell::new(); +static MODULES: OnceCell> = OnceCell::new(); // replace with `OnceLock` when MSRV is 1.70.0 +// replace `Lazy` with `LazyLock` when MSRV is 1.80.0 static OUT_DIR: Lazy = Lazy::new(|| PathBuf::from(env::var_os("OUT_DIR").expect("Can't read OUT_DIR env var"))); static MANIFEST_DIR: Lazy = Lazy::new(|| PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").expect("Can't read CARGO_MANIFEST_DIR env var"))); @@ -288,6 +289,78 @@ fn build_wrapper(opencv: &Library) { let mut cc = build_compiler(opencv); eprintln!("=== Compiler information: {:#?}", cc.get_compiler()); let modules = MODULES.get().expect("MODULES not initialized"); + static SUPPORTED_MODULES: [&str; 67] = [ + "alphamat", + "aruco", + "aruco_detector", + "barcode", + "bgsegm", + "bioinspired", + "calib3d", + "ccalib", + "core", + "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", + "wechat_qrcode", + "xfeatures2d", + "ximgproc", + "xobjdetect", + "xphoto", + ]; + for module in SUPPORTED_MODULES { + println!("cargo:rustc-check-cfg=cfg(ocvrs_has_module_{module})"); // replace with cargo:: syntax when MSRV is 1.77 + } for module in modules.iter() { println!("cargo:rustc-cfg=ocvrs_has_module_{module}"); cc.file(OUT_DIR.join(format!("{module}.cpp"))); @@ -336,6 +409,9 @@ fn main() -> Result<()> { let opencv = Library::probe()?; eprintln!("=== OpenCV library configuration: {opencv:#?}"); + println!("cargo:rustc-check-cfg=cfg(ocvrs_opencv_branch_4)"); // replace with cargo:: syntax when MSRV is 1.77 + println!("cargo:rustc-check-cfg=cfg(ocvrs_opencv_branch_34)"); // replace with cargo:: syntax when MSRV is 1.77 + println!("cargo:rustc-check-cfg=cfg(ocvrs_opencv_branch_32)"); // replace with cargo:: syntax when MSRV is 1.77 if OPENCV_BRANCH_4.matches(&opencv.version) { println!("cargo:rustc-cfg=ocvrs_opencv_branch_4"); } else if OPENCV_BRANCH_34.matches(&opencv.version) { diff --git a/build/generator.rs b/build/generator.rs index a3b6f67f6..f5c669742 100644 --- a/build/generator.rs +++ b/build/generator.rs @@ -223,7 +223,7 @@ fn collect_generated_bindings(modules: &[String], target_module_dir: &Path, manu write_module_include(&mut hub_rs, module)?; let module_filename = format!("{module}.rs"); let module_src_file = OUT_DIR.join(&module_filename); - let mut module_rs = BufWriter::new(File::create(&target_module_dir.join(&module_filename))?); + let mut module_rs = BufWriter::new(File::create(target_module_dir.join(&module_filename))?); // Need to wrap modules inside `mod { }` because they have top-level comments (//!) and those don't play well when // module file is include!d (as opposed to connecting the module with `mod` from the parent module). // The same doesn't apply to `sys` and `types` below because they don't contain top-level comments. diff --git a/src/opencv.rs b/src/opencv.rs index 7c4a4c268..98840ab13 100644 --- a/src/opencv.rs +++ b/src/opencv.rs @@ -9,6 +9,7 @@ unused_parens )] #[allow( + clippy::doc_lazy_continuation, clippy::double_must_use, clippy::excessive_precision, clippy::let_and_return,