@@ -13,10 +13,6 @@ use std::convert::AsRef;
1313#[ allow( dead_code) ]
1414#[ derive( RustcDecodable ) ]
1515struct Config {
16- // below variable dictates which
17- // backend library is used by rust wrapper
18- use_backend : String ,
19-
2016 // Use the existing lib if it exists
2117 use_lib : bool ,
2218 lib_dir : String ,
@@ -25,9 +21,6 @@ struct Config {
2521 // Build related
2622 build_type : String ,
2723 build_threads : String ,
28- build_cuda : String ,
29- build_opencl : String ,
30- build_cpu : String ,
3124 build_examples : String ,
3225 build_test : String ,
3326 build_graphics : String ,
@@ -66,6 +59,13 @@ fn fail(s: &str) -> ! {
6659 panic ! ( "\n {}\n \n build script failed, must exit now" , s)
6760}
6861
62+ fn file_exists ( location : & str ) -> bool {
63+ match fs:: metadata ( location) {
64+ Ok ( f) => f. is_file ( ) ,
65+ Err ( _) => false ,
66+ }
67+ }
68+
6969fn run ( cmd : & mut Command , program : & str ) {
7070 println ! ( "running: {:?}" , cmd) ;
7171 let status = match cmd. status ( ) {
@@ -233,9 +233,6 @@ fn run_cmake_command(conf: &Config, build_dir: &std::path::PathBuf) {
233233
234234 run ( cmake_cmd. arg ( ".." ) . arg ( "-G" ) . arg ( "Visual Studio 12 2013 Win64" )
235235 . args ( & [ format ! ( "-DCMAKE_BUILD_TYPE:STRING={}" , conf. build_type) ,
236- format ! ( "-DBUILD_CPU:BOOL={}" , conf. build_cpu) ,
237- format ! ( "-DBUILD_CUDA:BOOL={}" , conf. build_cuda) ,
238- format ! ( "-DBUILD_OPENCL:BOOL={}" , conf. build_opencl) ,
239236 format ! ( "-DBUILD_EXAMPLES:BOOL={}" , conf. build_examples) ,
240237 format ! ( "-DBUILD_TEST:BOOL={}" , conf. build_test) ,
241238 format ! ( "-DBOOST_ROOT={}" , conf. boost_dir) ,
@@ -312,9 +309,6 @@ fn run_cmake_command(conf: &Config, build_dir: &std::path::PathBuf) {
312309
313310 run ( cmake_cmd. arg ( ".." )
314311 . args ( & [ format ! ( "-DCMAKE_BUILD_TYPE:STRING={}" , conf. build_type) ,
315- format ! ( "-DBUILD_CPU:BOOL={}" , conf. build_cpu) ,
316- format ! ( "-DBUILD_CUDA:BOOL={}" , conf. build_cuda) ,
317- format ! ( "-DBUILD_OPENCL:BOOL={}" , conf. build_opencl) ,
318312 format ! ( "-DBUILD_EXAMPLES:BOOL={}" , conf. build_examples) ,
319313 format ! ( "-DBUILD_TEST:BOOL={}" , conf. build_test) ,
320314 format ! ( "-DCMAKE_INSTALL_PREFIX:STRING={}" , "package" ) ] )
@@ -332,6 +326,16 @@ fn run_cmake_command(conf: &Config, build_dir: &std::path::PathBuf) {
332326 . arg ( format ! ( "install" ) ) , "make" ) ;
333327}
334328
329+ fn backend_exists ( name : & str ) -> bool {
330+ let win_backend = name. to_string ( ) + ".dll" ;
331+ let osx_backend = name. to_string ( ) + ".dylib" ;
332+ let linux_backend = name. to_string ( ) + ".so" ;
333+
334+ return file_exists ( & win_backend)
335+ || file_exists ( & osx_backend)
336+ || file_exists ( & linux_backend)
337+ }
338+
335339fn blob_backends ( conf : & Config , build_dir : & std:: path:: PathBuf ) -> ( Vec < String > , Vec < String > ) {
336340 let mut backend_dirs : Vec < String > = Vec :: new ( ) ;
337341 let mut backends : Vec < String > = Vec :: new ( ) ;
@@ -342,20 +346,21 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,
342346 backend_dirs. push ( build_dir. join ( "package/lib" ) . to_str ( ) . to_owned ( ) . unwrap ( ) . to_string ( ) ) ;
343347 }
344348
345- if conf. use_backend == "cpu" {
346- backends. push ( "afcpu" . to_string ( ) ) ;
347- } else if conf. use_backend == "cuda" {
348- backends. push ( "afcuda" . to_string ( ) ) ;
349- backends. push ( "nvvm" . to_string ( ) ) ;
349+ let lib_dir = PathBuf :: from ( backend_dirs. last ( ) . unwrap ( ) ) ;
350+
351+ // blob in cuda deps
352+ if backend_exists ( & lib_dir. join ( "libafcuda" ) . to_string_lossy ( ) ) {
350353 if cfg ! ( windows) {
351354 backend_dirs. push ( format ! ( "{}\\ lib\\ x64" , conf. cuda_sdk) ) ;
352355 backend_dirs. push ( format ! ( "{}\\ nvvm\\ lib\\ x64" , conf. cuda_sdk) ) ;
353356 } else {
354357 backend_dirs. push ( format ! ( "{}/{}" , conf. cuda_sdk, conf. sdk_lib_dir) ) ;
355358 backend_dirs. push ( format ! ( "{}/nvvm/{}" , conf. cuda_sdk, conf. sdk_lib_dir) ) ;
356359 }
357- } else if conf. use_backend == "opencl" {
358- backends. push ( ( "afopencl" . to_string ( ) ) ) ;
360+ }
361+
362+ //blob in opencl deps
363+ if backend_exists ( & lib_dir. join ( "libafopencl" ) . to_string_lossy ( ) ) {
359364 if ! cfg ! ( target_os = "macos" ) {
360365 backends. push ( "OpenCL" . to_string ( ) ) ;
361366 }
@@ -366,6 +371,10 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,
366371 }
367372 }
368373
374+ if backend_exists ( & lib_dir. join ( "libaf" ) . to_string_lossy ( ) ) {
375+ backends. push ( "af" . to_string ( ) ) ;
376+ }
377+
369378 if conf. build_graphics =="ON" {
370379 backends. push ( "forge" . to_string ( ) ) ;
371380 if !conf. use_lib {
0 commit comments