Add ability to add attributes to functions
And disable the missing dll entries on all windows builds, not only vc
MODIFY
binding-generator/src/func.rs
binding-generator/src/func.rs
@@ -627,17 +627,20 @@ impl<'tu, 'g> Func<'tu, 'g> {
let forward_args = forward_args.join(", ");
let post_call_args = post_call_args.join("\n");
let ret_map = return_type.rust_return_map(is_safe);
+ let mut attributes = String::new();
+ if let Some(attrs) = settings::FUNC_CFG_ATTR.get(identifier.as_ref()) {
+ attributes = format!("#[cfg({})]", attrs.0);
+ }
let tpl = if let Some(tpl) = settings::FUNC_MANUAL.get(identifier.as_ref()) {
tpl
- } else if is_infallible {
- &TPL_NO_FAIL
} else {
&TPL
};
tpl.interpolate(&hashmap! {
"doc_comment" => doc_comment.as_str(),
"debug" => &debug,
+ "attributes" => &attributes,
"visibility" => &visibility,
"unsafety_decl" => if is_safe { "" } else { "unsafe " },
"name" => name,
@@ -905,6 +908,11 @@ impl GeneratedElement for Func<'_, '_> {
return "".to_string()
}
+ let identifier = self.identifier();
+ let mut attributes = String::new();
+ if let Some(attrs) = settings::FUNC_CFG_ATTR.get(identifier.as_ref()) {
+ attributes = format!("#[cfg({})]", attrs.0);
+ }
let mut args = vec![];
if let Some(cls) = self.as_instance_method() {
args.push(cls.type_ref().rust_extern_self_func_decl(self.is_const()));
@@ -915,8 +923,9 @@ impl GeneratedElement for Func<'_, '_> {
let return_type = self.return_type();
let return_wrapper_type = return_type.rust_extern_return_wrapper_full();
TPL.interpolate(&hashmap! {
- "debug" => Cow::Owned(get_debug(self)),
- "identifier" => self.identifier(),
+ "attributes" => attributes.into(),
+ "debug" => get_debug(self).into(),
+ "identifier" => identifier,
"args" => args.join(", ").into(),
"return_wrapper_type" => return_wrapper_type,
})
@@ -931,6 +940,13 @@ impl GeneratedElement for Func<'_, '_> {
return "".to_string()
}
+ let identifier = self.identifier();
+ let mut attributes_begin = String::new();
+ let mut attributes_end = String::new();
+ if let Some(attrs) = settings::FUNC_CFG_ATTR.get(identifier.as_ref()) {
+ attributes_begin = format!("#if {}", attrs.1);
+ attributes_end = "#endif".to_string();
+ }
let args = Field::cpp_disambiguate_names(self.arguments()).collect::<Vec<_>>();
let mut decl_args = Vec::with_capacity(args.len());
let mut pre_call_args = Vec::with_capacity(args.len());
@@ -956,14 +972,16 @@ impl GeneratedElement for Func<'_, '_> {
let return_type = self.return_type();
TPL.interpolate(&hashmap! {
+ "attributes_begin" => attributes_begin.into(),
"debug" => get_debug(self).into(),
"return_wrapper_type" => return_type.cpp_extern_return_wrapper_full(),
- "identifier" => self.identifier(),
+ "identifier" => identifier,
"decl_args" => decl_args.join(", ").into(),
"pre_call_args" => pre_call_args.join("\n").into(),
"call" => self.cpp_call_invoke().into(),
"post_call_args" => post_call_args.join("\n").into(),
"return" => self.cpp_method_return(),
+ "attributes_end" => attributes_end.into(),
})
}
}

MODIFY
binding-generator/src/settings.rs
binding-generator/src/settings.rs
@@ -10,8 +10,7 @@ use regex::RegexSet;
use crate::{CompiledInterpolation, ExportConfig, StrExt};
/// map of functions to rename or skip, key is Func.identifier(), value is new name ("+" will be replaced by old name) or "-" to skip
-pub static FUNC_RENAME: Lazy<HashMap<&str, &str>> = Lazy::new(|| {
- let mut out = hashmap! {
+pub static FUNC_RENAME: Lazy<HashMap<&str, &str>> = Lazy::new(|| hashmap! {
// ### aruco ###
"cv_aruco_getPredefinedDictionary_int" => "+_i32",
@@ -504,28 +503,45 @@ pub static FUNC_RENAME: Lazy<HashMap<&str, &str>> = Lazy::new(|| {
// ### xfeatures2d ###
"cv_xfeatures2d_AffineFeature2D_create_Ptr_FeatureDetector__Ptr_DescriptorExtractor_" => "+_with_extractor",
- };
- if cfg!(target_env = "msvc") {
+});
+
+pub static FUNC_CFG_ATTR: Lazy<HashMap<&str, (&str, &str)>> = Lazy::new(|| hashmap! {
// ### core ###
- out.insert("cv_MatConstIterator_MatConstIterator_const_MatX_const_intX", "-"); // missing in windows dll
- out.insert("cv_SparseMatIterator_SparseMatIterator_SparseMatX_const_intX", "-"); // missing in windows dll
- out.insert("cv_getImpl_vector_int_X_vector_String_X", "-"); // missing in windows dll
+ "cv_MatConstIterator_MatConstIterator_const_MatX_const_intX" => (
+ "not(target_os = \"windows\")", "!defined(OCVRS_TARGET_OS_WINDOWS)"
+ ), // missing in windows dll
+ "cv_SparseMatIterator_SparseMatIterator_SparseMatX_const_intX" => (
+ "not(target_os = \"windows\")", "!defined(OCVRS_TARGET_OS_WINDOWS)"
+ ), // missing in windows dll
+ "cv_getImpl_vector_int_X_vector_String_X" => (
+ "not(target_os = \"windows\")", "!defined(OCVRS_TARGET_OS_WINDOWS)"
+ ), // missing in windows dll
// ### dnn ###
- out.insert("cv_dnn_BackendNode_BackendNode_int", "-"); // missing in windows dll
+ "cv_dnn_BackendNode_BackendNode_int" => (
+ "not(target_os = \"windows\")", "!defined(OCVRS_TARGET_OS_WINDOWS)"
+ ), // missing in windows dll
// ### imgproc ###
- out.insert("cv_getRotationMatrix2D__Point2f_double_double", "-"); // missing in windows dll
+ "cv_getRotationMatrix2D__Point2f_double_double" => (
+ "not(target_os = \"windows\")", "!defined(OCVRS_TARGET_OS_WINDOWS)"
+ ), // missing in windows dll
// ### stitching ###
- out.insert("cv_createStitcherScans_bool", "-"); // missing in windows dll
- out.insert("cv_createStitcher_bool", "-"); // missing in windows dll
+ "cv_createStitcherScans_bool" => (
+ "not(target_os = \"windows\")", "!defined(OCVRS_TARGET_OS_WINDOWS)"
+ ), // missing in windows dll
+ "cv_createStitcher_bool" => (
+ "not(target_os = \"windows\")", "!defined(OCVRS_TARGET_OS_WINDOWS)"
+ ), // missing in windows dll
// ### surface_matching ###
- out.insert("cv_ppf_match_3d_PPF3DDetector_read_const_FileNodeX", "-"); // missing in windows dll
- out.insert("cv_ppf_match_3d_PPF3DDetector_write_const_FileStorageX", "-"); // missing in windows dll
- }
- out
+ "cv_ppf_match_3d_PPF3DDetector_read_const_FileNodeX" => (
+ "not(target_os = \"windows\")", "!defined(OCVRS_TARGET_OS_WINDOWS)"
+ ), // missing in windows dll
+ "cv_ppf_match_3d_PPF3DDetector_write_const_FileStorageX" => (
+ "not(target_os = \"windows\")", "!defined(OCVRS_TARGET_OS_WINDOWS)"
+ ), // missing in windows dll
});
pub static ELEMENT_EXCLUDE: Lazy<RegexSet> = Lazy::new(|| RegexSet::new([

MODIFY
binding-generator/tpl/func/cpp.tpl.cpp
binding-generator/tpl/func/cpp.tpl.cpp
+{{attributes_begin}}
{{debug}}
{{return_wrapper_type}} {{identifier}}({{decl_args}}) {
try {
{{return}}
} OCVRS_CATCH({{return_wrapper_type}})
}
+{{attributes_end}}

MODIFY
binding-generator/tpl/func/rust.tpl.rs
binding-generator/tpl/func/rust.tpl.rs
+{{attributes}}
{{doc_comment}}
{{debug}}
{{visibility}}{{unsafety_decl}}fn {{name}}{{generic_decl}}({{decl_args}}) -> {{rv_rust_full}} {

MODIFY
binding-generator/tpl/func/rust_extern.tpl.rs
binding-generator/tpl/func/rust_extern.tpl.rs
+{{attributes}}
{{debug}}
pub fn {{identifier}}({{args}}) -> {{return_wrapper_type}};

MODIFY
src_cpp/common.hpp
src_cpp/common.hpp
+#if defined(_WIN32) || defined(_WIN64) || defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__) \
+ || defined(__CYGWIN__) || defined(__MINGW32__) || defined(__BORLANDC__)
+#define OCVRS_TARGET_OS_WINDOWS
+#endif
+
#define CV_COLLECT_IMPL_DATA
#include <opencv2/core.hpp>

Add ability to add attributes to functions

And disable the missing dll entries on all windows builds, not only vc