Skip to content

Commit 1c114c1

Browse files
committed
Fixed build options for OS specific cases
1 parent 13dcd15 commit 1c114c1

File tree

1 file changed

+59
-39
lines changed

1 file changed

+59
-39
lines changed

build.rs

Lines changed: 59 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ use std::path::PathBuf;
1010
use std::process::Command;
1111
use std::convert::AsRef;
1212

13+
// Windows specific library file names
14+
static WIN_CUDA_LIB_NAME: &'static str = "afcuda";
15+
static WIN_OCL_LIB_NAME: &'static str = "afopencl";
16+
static WIN_UNI_LIB_NAME: &'static str = "af";
17+
// Linux & OSX specific library file names
18+
static UNIX_CUDA_LIB_NAME: &'static str = "libafcuda";
19+
static UNIX_OCL_LIB_NAME: &'static str = "libafopencl";
20+
static UNIX_UNI_LIB_NAME: &'static str = "libaf";
21+
1322
#[allow(dead_code)]
1423
#[derive(RustcDecodable)]
1524
struct Config {
@@ -356,53 +365,64 @@ fn blob_backends(conf: &Config, build_dir: &std::path::PathBuf) -> (Vec<String>,
356365
}
357366

358367
let lib_dir = PathBuf::from(backend_dirs.last().unwrap());
359-
360-
// blob in cuda deps
361-
if backend_exists(&lib_dir.join("libafcuda").to_string_lossy()) {
362-
if cfg!(windows) {
363-
backend_dirs.push(format!("{}\\lib\\x64", conf.cuda_sdk));
364-
backend_dirs.push(format!("{}\\nvvm\\lib\\x64", conf.cuda_sdk));
365-
} else {
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-
};
368+
if ! conf.use_lib {
369+
// blob in cuda deps
370+
let mut lib_file_to_check = if cfg!(windows) {WIN_CUDA_LIB_NAME} else {UNIX_CUDA_LIB_NAME};
371+
if backend_exists(&lib_dir.join(lib_file_to_check).to_string_lossy()) {
372+
if cfg!(windows) {
373+
backend_dirs.push(format!("{}\\lib\\x64", conf.cuda_sdk));
374+
backend_dirs.push(format!("{}\\nvvm\\lib\\x64", conf.cuda_sdk));
375+
} else {
376+
let sdk_dir = format!("{}/{}", conf.cuda_sdk, "lib64");
377+
match dir_exists(&sdk_dir){
378+
true => {
379+
backend_dirs.push(sdk_dir);
380+
backend_dirs.push(format!("{}/nvvm/{}", conf.cuda_sdk, "lib64"));
381+
},
382+
false => {
383+
backend_dirs.push(format!("{}/{}", conf.cuda_sdk, "lib"));
384+
backend_dirs.push(format!("{}/nvvm/{}", conf.cuda_sdk, "lib"));
385+
},
386+
};
387+
}
377388
}
378-
}
379389

380-
//blob in opencl deps
381-
if backend_exists(&lib_dir.join("libafopencl").to_string_lossy()) {
382-
if ! cfg!(target_os = "macos"){
383-
backends.push("OpenCL".to_string());
390+
//blob in opencl deps
391+
lib_file_to_check = if cfg!(windows) {WIN_OCL_LIB_NAME} else {UNIX_OCL_LIB_NAME};
392+
if backend_exists(&lib_dir.join(lib_file_to_check).to_string_lossy()) {
393+
if ! cfg!(target_os = "macos"){
394+
backends.push("OpenCL".to_string());
395+
}
396+
if cfg!(windows) {
397+
let sdk_dir = format!("{}\\lib\\x64", conf.opencl_sdk);
398+
if dir_exists(&sdk_dir){
399+
backend_dirs.push(sdk_dir);
400+
}else {
401+
backend_dirs.push(format!("{}\\lib\\x86_64", conf.opencl_sdk));
402+
}
403+
} else {
404+
let sdk_dir = format!("{}/{}", conf.opencl_sdk, "lib64");
405+
if dir_exists(&sdk_dir){
406+
backend_dirs.push(sdk_dir);
407+
}else {
408+
backend_dirs.push(format!("{}/{}", conf.opencl_sdk, "lib"));
409+
}
410+
}
384411
}
385-
if cfg!(windows) {
386-
backend_dirs.push(format!("{}\\lib\\x64", conf.opencl_sdk));
387-
} else {
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"));
412+
413+
if conf.build_graphics=="ON" {
414+
if !conf.use_lib {
415+
backend_dirs.push(build_dir.join("third_party/forge/lib")
416+
.to_str().to_owned().unwrap().to_string());
393417
}
394418
}
395419
}
396420

397-
if backend_exists(&lib_dir.join("libaf").to_string_lossy()) {
421+
let lib_file_to_check = if cfg!(windows) {WIN_UNI_LIB_NAME} else {UNIX_UNI_LIB_NAME};
422+
if backend_exists(&lib_dir.join(lib_file_to_check).to_string_lossy()) {
398423
backends.push("af".to_string());
399-
}
400-
401-
if conf.build_graphics=="ON" {
402-
backends.push("forge".to_string());
403-
if !conf.use_lib {
404-
backend_dirs.push(build_dir.join("third_party/forge/lib")
405-
.to_str().to_owned().unwrap().to_string());
424+
if !conf.use_lib && conf.build_graphics=="ON" {
425+
backends.push("forge".to_string());
406426
}
407427
}
408428

0 commit comments

Comments
 (0)