11mod bundled;
2+ mod callback;
23mod from_source;
34
45#[ cfg( any( feature = "bundled" , feature = "from-source" ) ) ]
@@ -13,6 +14,7 @@ use std::path::PathBuf;
1314
1415use crate :: from_source:: { compile_scip, download_scip_source, is_from_source_feature_enabled} ;
1516use bundled:: * ;
17+ use callback:: DeriveCastedConstant ;
1618
1719#[ cfg( not( feature = "bundled" ) ) ]
1820pub fn is_bundled_feature_enabled ( ) -> bool {
@@ -60,11 +62,19 @@ fn _build_from_scip_dir(path: &str) -> bindgen::Builder {
6062 . to_str ( )
6163 . unwrap ( )
6264 . to_owned ( ) ;
65+ let scipdef_file = PathBuf :: from ( & path)
66+ . join ( "include" )
67+ . join ( "scip" )
68+ . join ( "def.h" )
69+ . to_str ( )
70+ . unwrap ( )
71+ . to_owned ( ) ;
6372
6473 bindgen:: Builder :: default ( )
6574 . header ( scip_header_file)
6675 . header ( scipdefplugins_header_file)
67- . parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks ) )
76+ . header ( scipdef_file)
77+ . parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks :: new ( ) ) )
6878 . clang_arg ( format ! ( "-I{}" , include_dir_path) )
6979}
7080
@@ -90,7 +100,7 @@ fn look_in_scipoptdir_and_conda_env() -> Option<bindgen::Builder> {
90100 }
91101 }
92102
93- return None ;
103+ None
94104}
95105
96106fn try_system_include_paths ( ) -> Option < bindgen:: Builder > {
@@ -100,25 +110,27 @@ fn try_system_include_paths() -> Option<bindgen::Builder> {
100110 let search_paths = vec ! [
101111 "/usr/include" ,
102112 "/usr/local/include" ,
103- "/opt/local/include" , // MacPorts
104- "/opt/homebrew/include" , // Homebrew ARM Mac
105- "/usr/local/opt/scip/include" , // Homebrew Intel Mac
113+ "/opt/local/include" , // MacPorts
114+ "/opt/homebrew/include" , // Homebrew ARM Mac
115+ "/usr/local/opt/scip/include" , // Homebrew Intel Mac
106116 ] ;
107117
108118 for base_path in search_paths {
109119 let base = PathBuf :: from ( base_path) ;
110120 let scip_h = base. join ( "scip" ) . join ( "scip.h" ) ;
111121 let scipdefplugins_h = base. join ( "scip" ) . join ( "scipdefplugins.h" ) ;
122+ let def_h = base. join ( "scip" ) . join ( "def.h" ) ;
112123
113- if scip_h. exists ( ) && scipdefplugins_h. exists ( ) {
124+ if scip_h. exists ( ) && scipdefplugins_h. exists ( ) && def_h . exists ( ) {
114125 println ! ( "cargo:warning=Found SCIP headers in {}" , base_path) ;
115126
116127 return Some (
117128 bindgen:: Builder :: default ( )
118129 . header ( scip_h. to_str ( ) . unwrap ( ) )
119130 . header ( scipdefplugins_h. to_str ( ) . unwrap ( ) )
120- . parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks ) )
121- . clang_arg ( format ! ( "-I{}" , base_path) )
131+ . header ( def_h. to_str ( ) . unwrap ( ) )
132+ . parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks :: new ( ) ) )
133+ . clang_arg ( format ! ( "-I{}" , base_path) ) ,
122134 ) ;
123135 }
124136 }
@@ -188,14 +200,17 @@ fn main() -> Result<(), Box<dyn Error>> {
188200 println ! ( "cargo:rustc-link-lib=soplex" ) ;
189201 }
190202 }
203+ // Setup the DeriveCastedConstant callback to target SCIP_INVALID
204+ let derive_casted_constant = DeriveCastedConstant :: new ( ) . target ( "SCIP_INVALID" ) ;
191205
192206 let builder = builder
193207 . blocklist_item ( "FP_NAN" )
194208 . blocklist_item ( "FP_INFINITE" )
195209 . blocklist_item ( "FP_ZERO" )
196210 . blocklist_item ( "FP_SUBNORMAL" )
197211 . blocklist_item ( "FP_NORMAL" )
198- . parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks ) ) ;
212+ . parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks :: new ( ) ) )
213+ . parse_callbacks ( Box :: new ( derive_casted_constant) ) ;
199214
200215 let bindings = builder. generate ( ) ?;
201216 let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
0 commit comments