Re-enable parallel clang-runtime
MODIFY
build.rs
build.rs
@@ -8,6 +8,7 @@ use std::{
io::{BufRead, BufReader},
iter::{self, FromIterator},
path::{Path, PathBuf},
+ process::Command,
};
use dunce::canonicalize;
@@ -788,16 +789,13 @@ fn main() -> Result<()> {
#[cfg(feature = "buildtime-bindgen")]
let generator_build = if cfg!(feature = "clang-runtime") { // start building binding generator as early as possible
- None
- // fixme, https://github.com/twistedfall/opencv-rust/issues/145
- // let cargo_bin = PathBuf::from(env::var_os("CARGO").unwrap_or("cargo".into()));
- // let mut cargo = Command::new(cargo_bin);
- // // generator script is quite slow in debug mode, so we force it to be built in release mode
- // cargo
- // .args(&["build", "--release", "--package", "opencv-binding-generator", "--bin", "binding-generator"])
- // .env("CARGO_TARGET_DIR", &*OUT_DIR);
- // println!("running: {:?}", &cargo);
- // Some(cargo.spawn()?)
+ let cargo_bin = PathBuf::from(env::var_os("CARGO").unwrap_or_else(|| "cargo".into()));
+ let mut cargo = Command::new(cargo_bin);
+ // generator script is quite slow in debug mode, so we force it to be built in release mode
+ cargo.args(&["build", "--release", "--package", "opencv-binding-generator", "--bin", "binding-generator"])
+ .env("CARGO_TARGET_DIR", &*OUT_DIR);
+ println!("running: {:?}", &cargo);
+ Some(cargo.spawn()?)
} else {
None
};

MODIFY
build_generator.rs
build_generator.rs
@@ -4,7 +4,7 @@ use std::{
fs::{self, DirEntry, File, OpenOptions},
io::{self, BufRead, BufReader, Write},
path::{Path, PathBuf},
- process::Child,
+ process::{Child, Command},
sync::Arc,
thread,
time::Instant,
@@ -90,63 +90,45 @@ pub fn gen_wrapper(opencv_header_dir: &Path, generator_build: Option<Child>) ->
let job_server = jobserver::Client::new(num_jobs).expect("Can't create job server");
let mut join_handles = Vec::with_capacity(modules.len());
let start;
- if cfg!(feature = "clang-runtime") {
let clang = clang::Clang::new().expect("Cannot initialize clang");
println!("=== Clang: {}", clang::get_version());
let gen = binding_generator::Generator::new(clang_stdlib_include_dir.as_deref(), &opencv_header_dir, &*SRC_CPP_DIR, clang);
eprintln!("=== Clang command line args: {:#?}", gen.build_clang_command_line_args());
+ if cfg!(feature = "clang-runtime") {
+ let status = generator_build.expect("Impossible").wait()?;
+ if !status.success() {
+ return Err("Failed to build the bindings generator".into());
+ }
+ let opencv_header_dir = Arc::new(opencv_header_dir.to_owned());
start = Instant::now();
modules.iter().for_each(|module| {
- let bindings_writer = binding_generator::writer::RustNativeBindingWriter::new(
- &*SRC_CPP_DIR,
- &*OUT_DIR,
- &module,
- version,
- false,
- );
- gen.process_opencv_module(&module, bindings_writer);
- println!("Generated: {}", module);
+ let token = job_server.acquire().expect("Can't acquire token from job server");
+ let join_handle = thread::spawn({
+ let clang_stdlib_include_dir = Arc::clone(&clang_stdlib_include_dir);
+ let opencv_header_dir = Arc::clone(&opencv_header_dir);
+ move || {
+ let clang_stdlib_include_dir = (*clang_stdlib_include_dir).as_ref()
+ .and_then(|p| p.to_str())
+ .unwrap_or("None");
+ let mut bin_generator = Command::new(OUT_DIR.join("release/binding-generator"));
+ bin_generator.arg(&*opencv_header_dir)
+ .arg(&*SRC_CPP_DIR)
+ .arg(&*OUT_DIR)
+ .arg(&module)
+ .arg(version)
+ .arg(clang_stdlib_include_dir);
+ eprintln!("=== Running binding generator binary: {:#?}", bin_generator);
+ let res = bin_generator.status().expect("Can't run bindings generator");
+ if !res.success() {
+ panic!("Failed to run the bindings generator");
+ }
+ eprintln!("=== Generated: {}", module);
+ drop(token); // needed to move the token to the thread
+ }
+ });
+ join_handles.push(join_handle);
});
- drop(generator_build); // fixme, prevent unused var warning
- // fixme, https://github.com/twistedfall/opencv-rust/issues/145
- // let status = generator_build.expect("Impossible").wait()?;
- // if !status.success() {
- // return Err("Failed to build the bindings generator".into());
- // }
- // let opencv_header_dir = Arc::new(opencv_header_dir.to_owned());
- // start = Instant::now();
- // modules.iter().for_each(|module| {
- // let token = job_server.acquire().expect("Can't acquire token from job server");
- // let join_handle = thread::spawn({
- // let clang_stdlib_include_dir = Arc::clone(&clang_stdlib_include_dir);
- // let opencv_header_dir = Arc::clone(&opencv_header_dir);
- // move || {
- // let clang_stdlib_include_dir = (*clang_stdlib_include_dir).as_ref()
- // .and_then(|p| p.to_str())
- // .unwrap_or("None");
- // let mut bin_generator = std::process::Command::new(OUT_DIR.join("release/binding-generator"));
- // bin_generator.arg(&*opencv_header_dir)
- // .arg(&*SRC_CPP_DIR)
- // .arg(&*OUT_DIR)
- // .arg(&module)
- // .arg(version)
- // .arg(clang_stdlib_include_dir);
- // eprintln!("=== Running binding generator binary: {:#?}", bin_generator);
- // let res = bin_generator.status().expect("Can't run bindings generator");
- // if !res.success() {
- // panic!("Failed to run the bindings generator");
- // }
- // eprintln!("=== Generated: {}", module);
- // drop(token); // needed to move the token to the thread
- // }
- // });
- // join_handles.push(join_handle);
- // });
} else {
- let clang = clang::Clang::new().expect("Cannot initialize clang");
- println!("=== Clang: {}", clang::get_version());
- let gen = binding_generator::Generator::new(clang_stdlib_include_dir.as_deref(), &opencv_header_dir, &*SRC_CPP_DIR, clang);
- eprintln!("=== Clang command line args: {:#?}", gen.build_clang_command_line_args());
let gen = Arc::new(gen);
start = Instant::now();
modules.iter().for_each(|module| {

MODIFY
ci/script.sh
ci/script.sh
@@ -64,6 +64,9 @@ cargo test -vv --no-default-features --features "$CARGO_FEATURES"
cargo test --release -vv --no-default-features --features "$CARGO_FEATURES"
cargo test --release -vv --no-default-features --features "$CARGO_FEATURES,clang-runtime"
+pushd ci/test-proj-clang-runtime
+cargo run -vv --features="$CARGO_FEATURES"
+popd
export CXX=clang++
touch build.rs

ADD
ci/test-proj-clang-runtime/.gitignore
+/target

ADD
ci/test-proj-clang-runtime/Cargo.toml
+[package]
+name = "test-proj-clang-runtime"
+description = "Helper to test whether project using opencv dependency compiles"
+version = "0.1.0"
+authors = ["Pro"]
+edition = "2018"
+
+[dependencies]
+opencv = { path = "../..", default-features = false, features = ["clang-runtime"] }
+
+[workspace]
+
+[features]
+buildtime-bindgen = ["opencv/buildtime-bindgen"]
+opencv-32 = ["opencv/opencv-32"]
+opencv-34 = ["opencv/opencv-34"]
+opencv-4 = ["opencv/opencv-4"]
+contrib = ["opencv/contrib"]

ADD
ci/test-proj-clang-runtime/src/main.rs
+use opencv::prelude::*;
+
+fn main() {
+ let m = Mat::default().unwrap();
+ println!("{}", opencv::core::type_to_str(m.typ().unwrap()).unwrap());
+}

Re-enable parallel clang-runtime