Skip to content

Commit d4b789b

Browse files
authored
Error in build script when no backends are found (#310)
* Error in build script if no arrayfire backends are found This would result in a linker error anyway. By th rowing the error earlier, we make it easier for the user to debug their arrayfire installation. * Improve formatting of build script errors * Improve formatting of 'AF_PATH not found' warning * Warn if backends exist, but are not accessible * Run rustfmt * CI: Set up arrayfire for clippy job as well The clippy job now needs arrayfire to because the build script checks for a valid arrayfire installation.
1 parent f53bf4c commit d4b789b

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ jobs:
7373
clippy:
7474
name: Clippy Lints
7575
runs-on: ubuntu-18.04
76+
env:
77+
AF_VER: 3.8.0
7678
steps:
7779
- name: Checkout Repository
7880
uses: actions/checkout@master
@@ -83,7 +85,29 @@ jobs:
8385
toolchain: stable
8486
override: true
8587
components: clippy
88+
89+
- name: Cache ArrayFire
90+
uses: actions/cache@v1
91+
id: arrayfire
92+
with:
93+
path: afbin
94+
key: ${{ runner.os }}-af-${{ env.AF_VER }}
95+
96+
- name: Download ArrayFire
97+
# Only download and cache arrayfire if already not found
98+
if: steps.arrayfire.outputs.cache-hit != 'true'
99+
run: |
100+
wget --quiet http://arrayfire.s3.amazonaws.com/${AF_VER}/ArrayFire-v${AF_VER}_Linux_x86_64.sh
101+
chmod +x ./ArrayFire-v${AF_VER}_Linux_x86_64.sh
102+
mkdir afbin
103+
./ArrayFire-v${AF_VER}_Linux_x86_64.sh --skip-license --exclude-subdir --prefix=./afbin
104+
rm ./afbin/lib64/libcu*.so*
105+
rm ./afbin/lib64/libafcuda*.so*
106+
rm ./ArrayFire-v${AF_VER}_Linux_x86_64.sh
107+
86108
- name: Run clippy tool
109+
env:
110+
AF_PATH: ${{ github.workspace }}/afbin
87111
uses: actions-rs/cargo@v1
88112
with:
89113
command: clippy

build.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,32 @@ struct Config {
5858
win_vs_toolset: String,
5959
}
6060

61-
fn fail(s: &str) -> ! {
62-
panic!("\n{}\n\nbuild script failed, must exit now", s)
61+
fn fail(msg: &str) -> ! {
62+
eprintln!("ERROR: {}", msg);
63+
std::process::exit(1);
6364
}
6465

6566
fn dir_exists(location: &str) -> bool {
6667
match fs::metadata(location) {
6768
Ok(f) => f.is_dir(),
68-
Err(_) => false,
69+
Err(err) => {
70+
if err.kind() != ErrorKind::NotFound {
71+
eprintln!("WARNING: failed to access `{}`: {}", location, err);
72+
}
73+
false
74+
}
6975
}
7076
}
7177

7278
fn file_exists(location: &str) -> bool {
7379
match fs::metadata(location) {
7480
Ok(f) => f.is_file(),
75-
Err(_) => false,
81+
Err(err) => {
82+
if err.kind() != ErrorKind::NotFound {
83+
eprintln!("WARNING: failed to access `{}`: {}", location, err);
84+
}
85+
false
86+
}
7687
}
7788
}
7889

@@ -291,13 +302,9 @@ fn blob_backends(conf: &Config, build_dir: &std::path::Path) -> (Vec<String>, Ve
291302
let afpath = match env::var("AF_PATH") {
292303
Ok(af_path) => PathBuf::from(&af_path),
293304
Err(_) => {
294-
println!(
295-
"WARNING! USE_LIB is defined,
296-
but AF_PATH is not found,"
297-
);
298-
println!(
299-
"Trying to find libraries from
300-
known default locations"
305+
eprintln!(
306+
"WARNING: USE_LIB is defined, but AF_PATH is not found. Trying to find \
307+
libraries from known default locations."
301308
);
302309
if cfg!(target_os = "windows") {
303310
PathBuf::from("C:\\Program Files\\ArrayFire\\v3\\")
@@ -449,6 +456,11 @@ fn main() {
449456
}
450457

451458
let (backends, backend_dirs) = blob_backends(&conf, &build_dir);
459+
460+
if backends.is_empty() {
461+
fail("no arrayfire backends found");
462+
}
463+
452464
for backend in backends.iter() {
453465
println!("cargo:rustc-link-lib=dylib={}", backend);
454466
}

0 commit comments

Comments
 (0)