@@ -11,8 +11,8 @@ use std::env;
1111use std:: error:: Error ;
1212use std:: path:: PathBuf ;
1313
14+ use crate :: from_source:: { compile_scip, download_scip_source, is_from_source_feature_enabled} ;
1415use bundled:: * ;
15- use crate :: from_source:: { download_scip_source, is_from_source_feature_enabled, compile_scip} ;
1616
1717#[ cfg( not( feature = "bundled" ) ) ]
1818pub fn is_bundled_feature_enabled ( ) -> bool {
@@ -29,7 +29,7 @@ fn _build_from_scip_dir(path: &str) -> bindgen::Builder {
2929 println ! ( "cargo:libdir={}" , lib_dir_path) ;
3030
3131 #[ cfg( windows) ]
32- let lib_dir_path = PathBuf :: from ( & path) . join ( "bin" ) ;
32+ let lib_dir_path = PathBuf :: from ( & path) . join ( "bin" ) ;
3333 #[ cfg( windows) ]
3434 println ! ( "cargo:rustc-link-search={}" , lib_dir_path. to_str( ) . unwrap( ) ) ;
3535 } else {
@@ -64,7 +64,7 @@ fn _build_from_scip_dir(path: &str) -> bindgen::Builder {
6464 bindgen:: Builder :: default ( )
6565 . header ( scip_header_file)
6666 . header ( scipdefplugins_header_file)
67- . parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks ) )
67+ . parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks :: new ( ) ) )
6868 . clang_arg ( format ! ( "-I{}" , include_dir_path) )
6969}
7070
@@ -94,46 +94,76 @@ fn look_in_scipoptdir_and_conda_env() -> Option<bindgen::Builder> {
9494}
9595
9696fn main ( ) -> Result < ( ) , Box < dyn Error > > {
97- let builder =
98- if is_bundled_feature_enabled ( ) {
99- download_scip ( ) ;
100- let path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) . join ( "scip_install" ) ;
101- _build_from_scip_dir ( path. to_str ( ) . unwrap ( ) )
102- } else if is_from_source_feature_enabled ( ) {
103- let source_path = download_scip_source ( ) ;
104- let build_path = compile_scip ( source_path) ;
105- _build_from_scip_dir ( build_path. to_str ( ) . unwrap ( ) )
97+ let builder = if is_bundled_feature_enabled ( ) {
98+ download_scip ( ) ;
99+ let path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) . join ( "scip_install" ) ;
100+ _build_from_scip_dir ( path. to_str ( ) . unwrap ( ) )
101+ } else if is_from_source_feature_enabled ( ) {
102+ let source_path = download_scip_source ( ) ;
103+ let build_path = compile_scip ( source_path) ;
104+ _build_from_scip_dir ( build_path. to_str ( ) . unwrap ( ) )
105+ } else {
106+ let builder = look_in_scipoptdir_and_conda_env ( ) ;
107+ if builder. is_some ( ) {
108+ builder. unwrap ( )
106109 } else {
107- let builder = look_in_scipoptdir_and_conda_env ( ) ;
108- if builder. is_some ( ) {
109- builder. unwrap ( )
110- } else {
111- println ! ( "cargo:warning=SCIP was not found in SCIPOPTDIR or in Conda environemnt" ) ;
112- println ! ( "cargo:warning=Looking for SCIP in system libraries" ) ;
113-
114- let headers_dir_path = "headers/" ;
115- let headers_dir = PathBuf :: from ( headers_dir_path) ;
116- let scip_header_file = PathBuf :: from ( & headers_dir)
117- . join ( "scip" )
118- . join ( "scip.h" )
119- . to_str ( )
120- . unwrap ( )
121- . to_owned ( ) ;
122- let scipdefplugins_header_file = PathBuf :: from ( & headers_dir)
123- . join ( "scip" )
124- . join ( "scipdefplugins.h" )
125- . to_str ( )
126- . unwrap ( )
127- . to_owned ( ) ;
128-
129- bindgen:: Builder :: default ( )
130- . header ( scip_header_file)
131- . header ( scipdefplugins_header_file)
132- . parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks ) )
133- . clang_arg ( format ! ( "-I{}" , headers_dir_path) )
134- }
135- } ;
110+ println ! ( "cargo:warning=SCIP was not found in SCIPOPTDIR or in Conda environemnt" ) ;
111+ println ! ( "cargo:warning=Looking for SCIP in system libraries" ) ;
112+
113+ let headers_dir_path = "headers/" ;
114+ let headers_dir = PathBuf :: from ( headers_dir_path) ;
115+ let scip_header_file = PathBuf :: from ( & headers_dir)
116+ . join ( "scip" )
117+ . join ( "scip.h" )
118+ . to_str ( )
119+ . unwrap ( )
120+ . to_owned ( ) ;
121+ let scipdefplugins_header_file = PathBuf :: from ( & headers_dir)
122+ . join ( "scip" )
123+ . join ( "scipdefplugins.h" )
124+ . to_str ( )
125+ . unwrap ( )
126+ . to_owned ( ) ;
127+
128+ bindgen:: Builder :: default ( )
129+ . header ( scip_header_file)
130+ . header ( scipdefplugins_header_file)
131+ . parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks :: new ( ) ) )
132+ . clang_arg ( format ! ( "-I{}" , headers_dir_path) )
133+ }
134+ } ;
135+
136+ #[ cfg( windows) ]
137+ {
138+ println ! ( "cargo:rustc-link-lib=libscip" ) ;
139+ }
140+ #[ cfg( not( windows) ) ]
141+ {
142+ println ! ( "cargo:rustc-link-lib=scip" ) ;
143+ }
144+
145+ #[ cfg( feature = "from-source" ) ]
146+ {
147+ let target = env:: var ( "TARGET" ) . unwrap ( ) ;
148+ let apple = target. contains ( "apple" ) ;
149+ let linux = target. contains ( "linux" ) ;
150+ let mingw = target. contains ( "pc-windows-gnu" ) ;
151+ if apple {
152+ println ! ( "cargo:rustc-link-lib=dylib=c++" ) ;
153+ } else if linux || mingw {
154+ println ! ( "cargo:rustc-link-lib=dylib=stdc++" ) ;
155+ }
136156
157+ #[ cfg( windows) ]
158+ {
159+ println ! ( "cargo:rustc-link-lib=libsoplex" ) ;
160+ }
161+ #[ cfg( not( windows) ) ]
162+ {
163+ println ! ( "cargo:rustc-link-lib=soplex" ) ;
164+ }
165+ }
166+
137167 #[ cfg( feature = "static" ) ] {
138168 #[ cfg( windows) ] {
139169 println ! ( "cargo:rustc-link-lib=static=libscip" ) ;
@@ -178,7 +208,7 @@ fn main() -> Result<(), Box<dyn Error>> {
178208 . blocklist_item ( "FP_ZERO" )
179209 . blocklist_item ( "FP_SUBNORMAL" )
180210 . blocklist_item ( "FP_NORMAL" )
181- . parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks ) ) ;
211+ . parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks :: new ( ) ) ) ;
182212
183213 let bindings = builder. generate ( ) ?;
184214 let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
0 commit comments