Make sure to pass additional include directories to the binding generator (also drop OPENCV_CLANG_STDLIB_PATH, it's not needed anymore)
MODIFY
README.md
README.md
@@ -216,11 +216,6 @@ The following variables are rarely used, but you might need them under some circ
cmake (cmake related environment variables are applicable with this probe)
* vcpkg
-* `OPENCV_CLANG_STDLIB_PATH`
- Path that contains the stdlib headers for parsing with libclang. Should be used only as a workaround for
- the rare cases where it doesn't get picked up automatically. Should help with issues like
- [this](https://github.com/twistedfall/opencv-rust/issues/125).
-
* `OPENCV_MODULE_WHITELIST` and `OPENCV_MODULE_BLACKLIST`
Comma separated lists that affect modules that get their bindings generated. Setting whitelist will only
generate the specified modules, setting blacklist will exclude the specified modules from generation. If the

MODIFY
binding-generator/src/bin/binding-generator.rs
binding-generator/src/bin/binding-generator.rs
@@ -19,13 +19,20 @@ fn main() {
let module = module.to_str().expect("Not a valid module name");
let version = args.next().expect("5th argument must be OpenCV version");
let version = version.to_str().expect("Not a valid version");
- let clang_stdlib_include_dir = args.next().expect("6th argument must be standard clang include dir override");
- let clang_stdlib_include_dir = clang_stdlib_include_dir.to_str()
- .filter(|&s| !s.is_empty() && s != "None")
- .map(PathBuf::from);
+ let additional_include_dirs = if let Some(additional_include_dirs) = args.next() {
+ additional_include_dirs.to_str()
+ .map(|s| s.split(','))
+ .into_iter()
+ .flatten()
+ .filter(|&s| !s.is_empty())
+ .map(PathBuf::from)
+ .collect()
+ } else {
+ vec![]
+ };
let debug = args.next().map_or(false, |x| x == "1");
let clang = Clang::new().expect("Cannot initialize clang");
let bindings_writer = RustNativeBindingWriter::new(&src_cpp_dir, &out_dir, module, version, debug);
- Generator::new(clang_stdlib_include_dir.as_deref(), &opencv_header_dir, &src_cpp_dir, clang)
+ Generator::new(&opencv_header_dir, &additional_include_dirs, &src_cpp_dir, clang)
.process_opencv_module(&module, bindings_writer);
}

MODIFY
binding-generator/src/bin/settings-cleanup.rs
binding-generator/src/bin/settings-cleanup.rs
@@ -135,7 +135,7 @@ fn main() {
.map(|f| f.to_string())
});
let clang = Clang::new().expect("Cannot initialize clang");
- let gen = Generator::new(None, &opencv_header_dir, &src_cpp_dir, clang);
+ let gen = Generator::new(&opencv_header_dir, &[], &src_cpp_dir, clang);
for module in modules {
println!(" {}", module);
gen.process_module(&module, false, |root_tu| {

MODIFY
binding-generator/src/generator.rs
binding-generator/src/generator.rs
@@ -478,11 +478,11 @@ impl<V: GeneratorVisitor> Drop for OpenCvWalker<'_, '_, V> {
}
impl Generator {
- pub fn new(clang_stdlib_include_dir: Option<&Path>, opencv_include_dir: &Path, src_cpp_dir: &Path, clang: Clang) -> Self {
+ pub fn new(opencv_include_dir: &Path, additional_include_dirs: &[PathBuf], src_cpp_dir: &Path, clang: Clang) -> Self {
let clang_bin = clang_sys::support::Clang::find(None, &[]).expect("Can't find clang binary");
let mut clang_include_dirs = clang_bin.cpp_search_paths.unwrap_or_default();
- if let Some(clang_stdlib_include_dir) = clang_stdlib_include_dir {
- clang_include_dirs.push(canonicalize(clang_stdlib_include_dir.to_path_buf()).expect("Cannot canonicalize clang_stdlib_include_dir"))
+ for additional_dir in additional_include_dirs {
+ clang_include_dirs.push(canonicalize(additional_dir).expect("Cannot canonicalize one of the additional_include_dirs"))
}
Self {
clang_include_dirs,

MODIFY
build.rs
build.rs
@@ -35,7 +35,7 @@ static OPENCV_BRANCH_32: Lazy<VersionReq> = Lazy::new(|| VersionReq::parse("~3.2
static OPENCV_BRANCH_34: Lazy<VersionReq> = Lazy::new(|| VersionReq::parse("~3.4").expect("Can't parse OpenCV 3.4 version requirement"));
static OPENCV_BRANCH_4: Lazy<VersionReq> = Lazy::new(|| VersionReq::parse("~4").expect("Can't parse OpenCV 4 version requirement"));
-static ENV_VARS: [&str; 17] = [
+static ENV_VARS: [&str; 16] = [
"OPENCV_PACKAGE_NAME",
"OPENCV_PKGCONFIG_NAME",
"OPENCV_CMAKE_NAME",
@@ -45,7 +45,6 @@ static ENV_VARS: [&str; 17] = [
"OPENCV_LINK_PATHS",
"OPENCV_INCLUDE_PATHS",
"OPENCV_DISABLE_PROBES",
- "OPENCV_CLANG_STDLIB_PATH",
"OPENCV_MODULE_WHITELIST",
"OPENCV_MODULE_BLACKLIST",
"CMAKE_PREFIX_PATH",

MODIFY
build_generator.rs
build_generator.rs
@@ -73,9 +73,10 @@ pub(crate) fn gen_wrapper(opencv_header_dir: &Path, opencv: &Library, generator_
}
}
- let clang_stdlib_include_dir = Arc::new(env::var_os("OPENCV_CLANG_STDLIB_PATH")
- .map(PathBuf::from)
- );
+ let additional_include_dirs = opencv.include_paths.iter()
+ .filter(|&include_path| include_path != opencv_header_dir)
+ .cloned()
+ .collect::<Vec<_>>();
let num_jobs = env::var("NUM_JOBS").ok()
.and_then(|jobs| jobs.parse().ok())
.unwrap_or(2);
@@ -84,7 +85,11 @@ pub(crate) fn gen_wrapper(opencv_header_dir: &Path, opencv: &Library, generator_
let start;
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);
+ let gen = binding_generator::Generator::new(&opencv_header_dir, &additional_include_dirs, &*SRC_CPP_DIR, clang);
+ let additional_include_dirs = Arc::new(additional_include_dirs.iter().cloned()
+ .map(|p| p.to_str().expect("Can't convert additional include dir to UTF-8 string").to_string())
+ .collect::<Vec<_>>()
+ );
eprintln!("=== Clang command line args: {:#?}", gen.build_clang_command_line_args());
if cfg!(feature = "clang-runtime") {
let status = generator_build.expect("Impossible").wait()?;
@@ -97,12 +102,9 @@ pub(crate) fn gen_wrapper(opencv_header_dir: &Path, opencv: &Library, generator_
let token = job_server.acquire().expect("Can't acquire token from job server");
let opencv_version = opencv.version.to_string();
let join_handle = thread::spawn({
- let clang_stdlib_include_dir = Arc::clone(&clang_stdlib_include_dir);
+ let additional_include_dirs = Arc::clone(&additional_include_dirs);
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 = match HOST_TRIPLE.as_ref() {
Some(host_triple) => Command::new(OUT_DIR.join(format!("{}/release/binding-generator", host_triple))),
None => Command::new(OUT_DIR.join("release/binding-generator")),
@@ -112,7 +114,7 @@ pub(crate) fn gen_wrapper(opencv_header_dir: &Path, opencv: &Library, generator_
.arg(&*OUT_DIR)
.arg(&module)
.arg(&opencv_version)
- .arg(clang_stdlib_include_dir);
+ .arg(additional_include_dirs.join(","));
eprintln!("=== Running binding generator binary: {:#?}", bin_generator);
let res = bin_generator.status().expect("Can't run bindings generator");
if !res.success() {

MODIFY
ci/install-macos-framework.sh
ci/install-macos-framework.sh
set -vex
+#brew -v update
+#brew install cmake eigen ffmpeg
+#brew unlink protobuf # otherwise it will use the system libprotobuf instead of the bundled
+
base_dir="$HOME/build/opencv/"
mkdir -p "$base_dir"

MODIFY
ci/script.sh
ci/script.sh
@@ -20,10 +20,7 @@ if [[ "$OS_FAMILY" == "windows" ]]; then
choco list --local-only
elif [[ "$OS_FAMILY" == "osx" ]]; then
toolchain_path="$(xcode-select --print-path)/Toolchains/XcodeDefault.xctoolchain/"
- export LIBCLANG_PATH="$toolchain_path/usr/lib/libclang.dylib"
- export CLANG_PATH="$toolchain_path/usr/bin/clang"
export DYLD_FALLBACK_LIBRARY_PATH="$toolchain_path/usr/lib/"
- export OPENCV_CLANG_STDLIB_PATH="$(xcode-select --print-path)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include"
if [[ "$BREW_OPENCV_VERSION" != "" ]]; then # brew build
if [[ "$BREW_OPENCV_VERSION" == "@3" ]]; then
export CMAKE_PREFIX_PATH="$(echo /usr/local/Cellar/opencv@3/3.4.*)"
@@ -35,6 +32,8 @@ elif [[ "$OS_FAMILY" == "osx" ]]; then
# export OPENCV_INCLUDE_PATHS="$HOME/build/opencv/opencv-$OPENCV_VERSION-build/opencv2.framework"
export OPENCV_INCLUDE_PATHS="$HOME/build/opencv/opencv-$OPENCV_VERSION-build/build/build-x86_64-macosx/install/include"
fi
+ echo "=== Installed brew packages:"
+ brew list --versions
elif [[ "$OS_FAMILY" == "linux" ]]; then
if [[ "$VCPKG_OPENCV_VERSION" != "" ]]; then # vcpkg build
export VCPKG_ROOT="$HOME/build/vcpkg"

Make sure to pass additional include directories to the binding generator (also drop OPENCV_CLANG_STDLIB_PATH, it's not needed anymore)