Skip to content

Commit b25f046

Browse files
committed
Add workaround for clang-19 + clang-runtime on Windows
1 parent bf41c18 commit b25f046

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

binding-generator/src/generator.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::borrow::Cow;
22
use std::env;
33
use std::fs::File;
44
use std::io::BufReader;
5+
use std::mem::ManuallyDrop;
56
use std::ops::ControlFlow;
67
use std::path::{Path, PathBuf};
78

@@ -355,7 +356,24 @@ pub struct Generator {
355356
opencv_include_dir: PathBuf,
356357
opencv_module_header_dir: PathBuf,
357358
src_cpp_dir: PathBuf,
358-
clang: Clang,
359+
clang: ManuallyDrop<Clang>,
360+
}
361+
362+
impl Drop for Generator {
363+
fn drop(&mut self) {
364+
#[cfg(any(not(windows), feature = "clang-runtime"))]
365+
{
366+
// `clang` has an issue on Windows when running with `runtime` feature and clang-19:
367+
// https://github.com/KyleMayes/clang-rs/issues/63
368+
// So we avoid dropping clang in that case as a workaround.
369+
// `clang::get_version()` is string like "Apple clang version 15.0.0 (clang-1500.1.0.2.5)"
370+
if !clang::get_version().contains(" 19.") {
371+
unsafe {
372+
ManuallyDrop::drop(&mut self.clang);
373+
}
374+
}
375+
}
376+
}
359377
}
360378

361379
impl Generator {
@@ -383,7 +401,7 @@ impl Generator {
383401
opencv_include_dir: canonicalize(opencv_include_dir).expect("Can't canonicalize opencv_include_dir"),
384402
opencv_module_header_dir: canonicalize(opencv_module_header_dir).expect("Can't canonicalize opencv_module_header_dir"),
385403
src_cpp_dir: canonicalize(src_cpp_dir).expect("Can't canonicalize src_cpp_dir"),
386-
clang: Clang::new().expect("Can't initialize clang"),
404+
clang: ManuallyDrop::new(Clang::new().expect("Can't initialize clang")),
387405
}
388406
}
389407

0 commit comments

Comments
 (0)