improve constants generation
MODIFY
build.rs
build.rs
@@ -388,6 +388,8 @@ fn gen_wrapper((opencv, pkg_name): (&pkg_config::Library, &str), opencv_header_d
let pkg_config_args = build_pkg_config_args((opencv, pkg_name));
let modules = get_modules(&opencv_dir.to_string_lossy())?;
modules.par_iter().for_each(|(module, ..)| {
+ let consts_cpp = out_dir.join(format!("{}.consts.cpp", module));
+ if consts_cpp.is_file() {
let e = compiler.to_command()
.current_dir(&out_dir)
.args(&[
@@ -408,6 +410,7 @@ fn gen_wrapper((opencv, pkg_name): (&pkg_config::Library, &str), opencv_header_d
let mut module_file = OpenOptions::new().append(true).open(out_dir.join(format!("{}.rs", module))).expect("Cannot open module file for append");
io::copy(&mut output.stdout.as_slice(), &mut module_file).expect("Cannot write constant data to module file");
}
+ }
});
if !module_dir.exists() {

MODIFY
gen_rust.py
gen_rust.py
@@ -615,7 +615,7 @@ const_ignore_list = (
"CV_IMPL_IPP", "CV_IMPL_MT", "CV_IMPL_OCL", "CV_IMPL_PLAIN", "CV_IPP_CHECK_COND", "IPP_INITIALIZER_AUTO", "IPP_VERSION_X100",
"CV_TRY", "CV_CATCH_ALL",
"CV__DEBUG_NS_",
- "UINT64_1",
+ "UINT64_1", "UINT32_1",
"CV_STRUCT_INITIALIZER", "CV__ENABLE_C_API_CTORS",
"VSX_IMPL_MULH_",
"CV__DNN_EXPERIMENTAL_NS_",
@@ -1666,8 +1666,9 @@ class ClassInfo(GeneralInfo):
class ConstInfo(GeneralInfo):
TEMPLATES = {
"rust_string": template("${doc_comment}pub const ${name}: &'static str = ${value};\n"),
- "rust_int": template("${doc_comment}pub const ${name}: i32 = ${value};\n"),
"rust_usize": template("${doc_comment}pub const ${name}: usize = ${value};\n"),
+ "rust_int": template("${doc_comment}pub const ${name}: i32 = ${value};\n"),
+ "rust_float": template("${doc_comment}pub const ${name}: f64 = ${value};\n"),
"cpp_string": template(""" printf("pub static ${name}: &'static str = \\"%s\\";\\n", ${full_name});\n"""),
"cpp_double": template(""" printf("pub const ${name}: f64 = %f;\\n", ${full_name});\n"""),
"cpp_int": template(""" printf("pub const ${name}: i32 = 0x%x; // %i\\n", ${full_name}, ${full_name});\n"""),
@@ -1716,6 +1717,8 @@ class ConstInfo(GeneralInfo):
return ConstInfo.TEMPLATES["rust_usize"].substitute(params)
elif re.match(r"^(-?[0-9]+|0x[0-9A-Fa-f]+)$", params["value"]): # decimal or hexadecimal
return ConstInfo.TEMPLATES["rust_int"].substitute(params)
+ elif re.match(r"^\d+\.\d*$", params["value"]): # float
+ return ConstInfo.TEMPLATES["rust_float"].substitute(params)
elif re.match(r"^\(?\s*(\d+\s*<<\s*\d+)\s*\)?$", params["value"]): # (1 << 24)
return ConstInfo.TEMPLATES["rust_int"].substitute(params)
elif re.match(r"^\s*(\d+\s*\+\s*\d+)\s*$", params["value"]): # 0 + 3
@@ -3570,10 +3573,12 @@ class RustWrapperGenerator(object):
with open("{}/{}.types.h".format(cpp_dir, module), "w", encoding="utf_8") as f:
f.write(self.moduleCppTypes.getvalue())
+ module_cpp_consts = self.moduleCppConsts.getvalue()
+ if module_cpp_consts:
with open("{}/{}.consts.cpp".format(cpp_dir, module), "w", encoding="utf_8") as f:
f.write(RustWrapperGenerator.TEMPLATES["cpp"]["consts"].substitute({
"module": module,
- "code": self.moduleCppConsts.getvalue(),
+ "code": module_cpp_consts,
}))
namespaces = ""

improve constants generation