@@ -2,6 +2,7 @@ use std::borrow::Cow;
2
2
use std:: env;
3
3
use std:: fs:: File ;
4
4
use std:: io:: BufReader ;
5
+ use std:: mem:: ManuallyDrop ;
5
6
use std:: ops:: ControlFlow ;
6
7
use std:: path:: { Path , PathBuf } ;
7
8
@@ -355,7 +356,24 @@ pub struct Generator {
355
356
opencv_include_dir : PathBuf ,
356
357
opencv_module_header_dir : PathBuf ,
357
358
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
+ }
359
377
}
360
378
361
379
impl Generator {
@@ -383,7 +401,7 @@ impl Generator {
383
401
opencv_include_dir : canonicalize ( opencv_include_dir) . expect ( "Can't canonicalize opencv_include_dir" ) ,
384
402
opencv_module_header_dir : canonicalize ( opencv_module_header_dir) . expect ( "Can't canonicalize opencv_module_header_dir" ) ,
385
403
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" ) ) ,
387
405
}
388
406
}
389
407
0 commit comments