@@ -10,8 +10,13 @@ use std::path::PathBuf;
1010use std:: process:: Command ;
1111use std:: convert:: AsRef ;
1212
13+ #[ allow( dead_code) ]
1314#[ derive( RustcDecodable ) ]
1415struct Config {
16+ // below variable dictates which
17+ // backend library is used by rust wrapper
18+ use_backend : String ,
19+
1520 // Use the existing lib if it exists
1621 use_lib : bool ,
1722 lib_dir : String ,
@@ -81,13 +86,15 @@ fn read_file(file_name: &std::path::PathBuf) -> String {
8186 . open ( & file_path) ;
8287
8388 let mut file = match options {
84- Ok ( file) => file,
89+ Ok ( file) => file,
8590 Err ( ..) => panic ! ( "error reading file" ) ,
8691 } ;
8792
8893 let mut s = String :: new ( ) ;
89- file. read_to_string ( & mut s) ;
90- return s. to_string ( )
94+ match file. read_to_string ( & mut s) {
95+ Ok ( _) => s,
96+ Err ( ..) => panic ! ( "Error reading file to a string" ) ,
97+ }
9198}
9299
93100fn read_conf ( conf_file : & std:: path:: PathBuf ) -> Config {
@@ -332,7 +339,9 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,
332339 backend_dirs. push ( build_dir. join ( "package/lib" ) . to_str ( ) . to_owned ( ) . unwrap ( ) . to_string ( ) ) ;
333340 }
334341
335- if conf. build_cuda == "ON" {
342+ if conf. use_backend == "cpu" {
343+ backends. push ( "afcpu" . to_string ( ) ) ;
344+ } else if conf. use_backend == "cuda" {
336345 backends. push ( "afcuda" . to_string ( ) ) ;
337346 backends. push ( "nvvm" . to_string ( ) ) ;
338347 if cfg ! ( windows) {
@@ -342,13 +351,7 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,
342351 backend_dirs. push ( format ! ( "{}/lib64" , conf. cuda_sdk) ) ;
343352 backend_dirs. push ( format ! ( "{}/nvvm/lib64" , conf. cuda_sdk) ) ;
344353 }
345- }
346-
347- if conf. build_cpu == "ON" {
348- backends. push ( "afcpu" . to_string ( ) ) ;
349- }
350-
351- if conf. build_opencl == "ON" {
354+ } else if conf. use_backend == "opencl" {
352355 backends. push ( ( "afopencl" . to_string ( ) ) ) ;
353356 backends. push ( "OpenCL" . to_string ( ) ) ;
354357 if cfg ! ( windows) {
0 commit comments