@@ -14,19 +14,30 @@ fn main() {
1414
1515 println ! ( "cargo::rerun-if-changed=libxml2" ) ;
1616
17- let libs = std:: process:: Command :: new ( format ! ( "{}/bin/xml2-config" , path. display( ) , ) )
17+ let host = env:: var ( "HOST" ) . unwrap ( ) ;
18+ let reg = regex:: Regex :: new ( "-(.)/(.)/" ) . expect ( "reg" ) ;
19+
20+ let mut libs = std:: process:: Command :: new ( "sh" )
21+ . arg ( path. join ( "bin/xml2-config" ) )
1822 . arg ( "--libs" )
1923 . output ( )
20- . expect ( "" ) ;
21- let libs = String :: from_utf8_lossy ( & libs. stdout ) ;
22- println ! ( "cargo::rustc-flags={}" , libs) ;
23-
24- let cflags = std:: process:: Command :: new ( format ! ( "{}/bin/xml2-config" , path. display( ) , ) )
24+ . map ( |output| String :: from_utf8_lossy ( & output. stdout ) . to_string ( ) ) ;
25+ let mut cflags = std:: process:: Command :: new ( "sh" )
26+ . arg ( path. join ( "bin/xml2-config" ) )
2527 . arg ( "--cflags" )
2628 . output ( )
27- . expect ( "" ) ;
28- let cflags = String :: from_utf8_lossy ( & cflags. stdout ) ;
29+ . map ( |output| String :: from_utf8_lossy ( & output. stdout ) . to_string ( ) ) ;
30+
31+ if host. contains ( "windows" ) {
32+ libs = libs. map ( |v| reg. replace_all ( & v, "-$1$2:/" ) . to_string ( ) ) ;
33+ cflags = cflags. map ( |v| reg. replace_all ( & v, "-$1$2:/" ) . to_string ( ) ) ;
34+ }
35+ // NOTE: Manually specify
36+ let libs = libs. unwrap_or_else ( |_| format ! ( "-L{} -lxml2" , path. join( "lib" ) . display( ) ) ) ;
37+ println ! ( "cargo::rustc-flags={}" , libs) ;
2938
39+ // Note: Manually specify
40+ let cflags = cflags. unwrap_or_else ( |_| format ! ( "-I{}" , path. join( "include/libxml2" ) . display( ) ) ) ;
3041 let bindings_path = PathBuf :: from ( out_dir) . join ( "bindings.rs" ) ;
3142 bindgen:: builder ( )
3243 . opaque_type ( "max_align_t" )
0 commit comments