add buildtime_bidgen feature to enable rust bindings generation under src/
MODIFY
Cargo.toml
Cargo.toml
@@ -18,3 +18,6 @@ libc = "0.2"
pkg-config = "0.3.14"
cc = "1.0"
glob = "0.3"
+
+[features]
+buildtime_bindgen = []

MODIFY
build.rs
build.rs
@@ -202,6 +202,7 @@ fn build_wrapper(opencv: pkg_config::Library) {
}
gcc.file(cpp);
+ if cfg!(feature = "buildtime_bindgen") {
let e = Command::new("sh")
.current_dir(&out_dir)
.arg("-c")
@@ -220,6 +221,7 @@ fn build_wrapper(opencv: pkg_config::Library) {
.unwrap();
assert!(e.success());
let _ = fs::remove_file(out_dir.join(format!("{}.consts", module.0)));
+ }
let _ = fs::remove_file(out_dir.join(format!("{}.consts.cpp", module.0)));
}
let _ = fs::remove_file("gen_rust.pyc");
@@ -232,8 +234,7 @@ fn build_wrapper(opencv: pkg_config::Library) {
&mut hub_return_types,
r#"#include "{}""#,
entry.unwrap().file_name().unwrap().to_str().unwrap()
- )
- .unwrap();
+ ).unwrap();
}
}
@@ -249,6 +250,7 @@ fn build_wrapper(opencv: pkg_config::Library) {
gcc.compile("ocvrs");
+ if cfg!(feature = "buildtime_bindgen") {
if !module_dir.exists() {
fs::create_dir(&module_dir).unwrap();
}
@@ -274,7 +276,6 @@ fn build_wrapper(opencv: pkg_config::Library) {
for entry in glob(&format!("{}/*.type.rs", out_dir_as_str)).unwrap() {
let entry = entry.unwrap();
io::copy(&mut File::open(&entry).unwrap(), &mut types).unwrap();
- let _ = fs::remove_file(entry);
}
}
@@ -285,15 +286,17 @@ fn build_wrapper(opencv: pkg_config::Library) {
for entry in glob(&format!("{}/*.rv.rs", out_dir_as_str)).unwrap() {
let entry = entry.unwrap();
io::copy(&mut File::open(&entry).unwrap(), &mut sys).unwrap();
- let _ = fs::remove_file(entry);
}
for module in &modules {
let path = out_dir.join(format!("{}.externs.rs", module.0));
io::copy(&mut File::open(&path).unwrap(), &mut sys).unwrap();
- let _ = fs::remove_file(path);
}
}
}
+ for entry in glob(&format!("{}/*.rs", out_dir_as_str)).unwrap() {
+ let _ = fs::remove_file(entry.unwrap());
+ }
+}
fn main() {
build_wrapper(link_wrapper());

add buildtime_bidgen feature to enable rust bindings generation under src/