Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
twistedfall committed Jul 25, 2024
1 parent 639e0c8 commit 921fa4a
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
4 changes: 4 additions & 0 deletions binding-generator/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
}

pub fn all_bases(&self) -> HashSet<Class<'tu, 'ge>> {
#![allow(clippy::mutable_key_type)]
#[allow(clippy::unnecessary_to_owned)]
self
.bases()
Expand All @@ -276,6 +277,7 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
}

pub fn descendants(&self) -> HashSet<Class<'tu, 'ge>> {
#![allow(clippy::mutable_key_type)]
match self {
&Self::Clang { gen_env, .. } => gen_env
.descendants_of(&self.cpp_name(CppNameStyle::Reference))
Expand All @@ -287,6 +289,7 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
}

pub fn all_descendants(&self) -> HashSet<Class<'tu, 'ge>> {
#![allow(clippy::mutable_key_type)]
self
.descendants()
.into_iter()
Expand All @@ -299,6 +302,7 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
}

pub fn all_family(&self) -> HashSet<Class<'tu, 'ge>> {
#![allow(clippy::mutable_key_type)]
fn collect<'tu, 'ge>(out: &mut HashSet<Class<'tu, 'ge>>, cls: Class<'tu, 'ge>) {
if out.insert(cls.clone()) {
#[allow(clippy::unnecessary_to_owned)]
Expand Down
78 changes: 77 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ mod library;

type Result<T, E = Box<dyn std::error::Error>> = std::result::Result<T, E>;

static MODULES: OnceCell<Vec<String>> = OnceCell::new();
static MODULES: OnceCell<Vec<String>> = 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<PathBuf> = Lazy::new(|| PathBuf::from(env::var_os("OUT_DIR").expect("Can't read OUT_DIR env var")));
static MANIFEST_DIR: Lazy<PathBuf> =
Lazy::new(|| PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").expect("Can't read CARGO_MANIFEST_DIR env var")));
Expand Down Expand Up @@ -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")));
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion build/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/opencv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
unused_parens
)]
#[allow(
clippy::doc_lazy_continuation,
clippy::double_must_use,
clippy::excessive_precision,
clippy::let_and_return,
Expand Down

0 comments on commit 921fa4a

Please sign in to comment.