Skip to content

Commit 13dcd15

Browse files
committed
Merge pull request #48 from arrayfire/hotfix/build
remove the lib directory dependency from conf and add a message for when AF_PATH is not set
2 parents 0ae16c4 + ecd06a5 commit 13dcd15

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

build.conf

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@
2323
"boost_dir": "E:\\Libraries\\boost_1_56_0",
2424

2525
"cuda_sdk": "/usr/local/cuda",
26-
"opencl_sdk": "/usr",
27-
"sdk_lib_dir": "lib64"
26+
"opencl_sdk": "/usr"
2827
}

build.rs

+28-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ struct Config {
4343
// GPU backends
4444
cuda_sdk: String,
4545
opencl_sdk: String,
46-
sdk_lib_dir: String,
4746
}
4847

4948
macro_rules! t {
@@ -57,6 +56,13 @@ fn fail(s: &str) -> ! {
5756
panic!("\n{}\n\nbuild script failed, must exit now", s)
5857
}
5958

59+
fn dir_exists(location: &str) -> bool {
60+
match fs::metadata(location) {
61+
Ok(f) => f.is_dir(),
62+
Err(_) => false,
63+
}
64+
}
65+
6066
fn file_exists(location: &str) -> bool {
6167
match fs::metadata(location) {
6268
Ok(f) => f.is_file(),
@@ -339,7 +345,10 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,
339345
let mut backends :Vec<String> = Vec::new();
340346

341347
if conf.use_lib {
342-
let afpath = PathBuf::from(&env::var("AF_PATH").unwrap());
348+
let afpath = match env::var("AF_PATH") {
349+
Ok(af_path) => PathBuf::from(&af_path),
350+
Err(_) => panic!("Error use_lib is defined, but AF_PATH is not defined"),
351+
};
343352
let libpath = afpath.join("lib");
344353
backend_dirs.push(libpath.to_str().to_owned().unwrap().to_string());
345354
} else {
@@ -354,8 +363,17 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,
354363
backend_dirs.push(format!("{}\\lib\\x64", conf.cuda_sdk));
355364
backend_dirs.push(format!("{}\\nvvm\\lib\\x64", conf.cuda_sdk));
356365
} else {
357-
backend_dirs.push(format!("{}/{}", conf.cuda_sdk, conf.sdk_lib_dir));
358-
backend_dirs.push(format!("{}/nvvm/{}", conf.cuda_sdk, conf.sdk_lib_dir));
366+
let sdk_dir = format!("{}/{}", conf.cuda_sdk, "lib64");
367+
match dir_exists(&sdk_dir){
368+
true => {
369+
backend_dirs.push(sdk_dir);
370+
backend_dirs.push(format!("{}/nvvm/{}", conf.cuda_sdk, "lib64"));
371+
},
372+
false => {
373+
backend_dirs.push(format!("{}/{}", conf.cuda_sdk, "lib"));
374+
backend_dirs.push(format!("{}/nvvm/{}", conf.cuda_sdk, "lib"));
375+
},
376+
};
359377
}
360378
}
361379

@@ -367,7 +385,12 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,
367385
if cfg!(windows) {
368386
backend_dirs.push(format!("{}\\lib\\x64", conf.opencl_sdk));
369387
} else {
370-
backend_dirs.push(format!("{}/{}", conf.opencl_sdk, conf.sdk_lib_dir));
388+
let sdk_dir = format!("{}/{}", conf.opencl_sdk, "lib64");
389+
if dir_exists(&sdk_dir){
390+
backend_dirs.push(sdk_dir);
391+
}else {
392+
backend_dirs.push(format!("{}/{}", conf.opencl_sdk, "lib"));
393+
}
371394
}
372395
}
373396

0 commit comments

Comments
 (0)