From 31b6b2a5d13513be6f3bded6188b03dbd4e0bede Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 14 Jan 2022 10:11:26 +0000 Subject: [PATCH 1/6] 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. --- build.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.rs b/build.rs index 5b55757a..8c7c00da 100644 --- a/build.rs +++ b/build.rs @@ -449,6 +449,11 @@ fn main() { } let (backends, backend_dirs) = blob_backends(&conf, &build_dir); + + if backends.is_empty() { + fail("no arrayfire backends found"); + } + for backend in backends.iter() { println!("cargo:rustc-link-lib=dylib={}", backend); } From 661dc79728396d2271f5a073dc128c2e036550cf Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 14 Jan 2022 10:11:58 +0000 Subject: [PATCH 2/6] Improve formatting of build script errors --- build.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index 8c7c00da..6fb92961 100644 --- a/build.rs +++ b/build.rs @@ -58,8 +58,9 @@ struct Config { win_vs_toolset: String, } -fn fail(s: &str) -> ! { - panic!("\n{}\n\nbuild script failed, must exit now", s) +fn fail(msg: &str) -> ! { + eprintln!("ERROR: {}", msg); + std::process::exit(1); } fn dir_exists(location: &str) -> bool { From 8ebd199b00ce816c081814eed36ca001ba306614 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 14 Jan 2022 10:12:26 +0000 Subject: [PATCH 3/6] Improve formatting of 'AF_PATH not found' warning --- build.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/build.rs b/build.rs index 6fb92961..dd3cb480 100644 --- a/build.rs +++ b/build.rs @@ -292,13 +292,9 @@ fn blob_backends(conf: &Config, build_dir: &std::path::Path) -> (Vec, Ve let afpath = match env::var("AF_PATH") { Ok(af_path) => PathBuf::from(&af_path), Err(_) => { - println!( - "WARNING! USE_LIB is defined, - but AF_PATH is not found," - ); - println!( - "Trying to find libraries from - known default locations" + eprintln!( + "WARNING: USE_LIB is defined, but AF_PATH is not found. Trying to find \ + libraries from known default locations." ); if cfg!(target_os = "windows") { PathBuf::from("C:\\Program Files\\ArrayFire\\v3\\") From 3242b39bb3a041256312459a97399c6504296aa8 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 14 Jan 2022 10:25:34 +0000 Subject: [PATCH 4/6] Warn if backends exist, but are not accessible --- build.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index dd3cb480..6b13aa17 100644 --- a/build.rs +++ b/build.rs @@ -66,14 +66,24 @@ fn fail(msg: &str) -> ! { fn dir_exists(location: &str) -> bool { match fs::metadata(location) { Ok(f) => f.is_dir(), - Err(_) => false, + Err(err) => { + if err.kind() != ErrorKind::NotFound { + eprintln!("WARNING: failed to access `{}`: {}", location, err); + } + false + }, } } fn file_exists(location: &str) -> bool { match fs::metadata(location) { Ok(f) => f.is_file(), - Err(_) => false, + Err(err) => { + if err.kind() != ErrorKind::NotFound { + eprintln!("WARNING: failed to access `{}`: {}", location, err); + } + false + }, } } From ff970c9814ca360efc4b3eff8128aa5e9063dad0 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 14 Jan 2022 10:46:20 +0000 Subject: [PATCH 5/6] Run rustfmt --- build.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.rs b/build.rs index 6b13aa17..c1fca518 100644 --- a/build.rs +++ b/build.rs @@ -71,7 +71,7 @@ fn dir_exists(location: &str) -> bool { eprintln!("WARNING: failed to access `{}`: {}", location, err); } false - }, + } } } @@ -83,7 +83,7 @@ fn file_exists(location: &str) -> bool { eprintln!("WARNING: failed to access `{}`: {}", location, err); } false - }, + } } } @@ -458,7 +458,7 @@ fn main() { let (backends, backend_dirs) = blob_backends(&conf, &build_dir); if backends.is_empty() { - fail("no arrayfire backends found"); + fail("no arrayfire backends found"); } for backend in backends.iter() { From 15f63ca398cffe8312c9b1ab86c9d9e9fac7efbe Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 14 Jan 2022 10:47:49 +0000 Subject: [PATCH 6/6] 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. --- .github/workflows/ci.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 967b0169..4e27f9a6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,6 +73,8 @@ jobs: clippy: name: Clippy Lints runs-on: ubuntu-18.04 + env: + AF_VER: 3.8.0 steps: - name: Checkout Repository uses: actions/checkout@master @@ -83,7 +85,29 @@ jobs: toolchain: stable override: true components: clippy + + - name: Cache ArrayFire + uses: actions/cache@v1 + id: arrayfire + with: + path: afbin + key: ${{ runner.os }}-af-${{ env.AF_VER }} + + - name: Download ArrayFire + # Only download and cache arrayfire if already not found + if: steps.arrayfire.outputs.cache-hit != 'true' + run: | + wget --quiet http://arrayfire.s3.amazonaws.com/${AF_VER}/ArrayFire-v${AF_VER}_Linux_x86_64.sh + chmod +x ./ArrayFire-v${AF_VER}_Linux_x86_64.sh + mkdir afbin + ./ArrayFire-v${AF_VER}_Linux_x86_64.sh --skip-license --exclude-subdir --prefix=./afbin + rm ./afbin/lib64/libcu*.so* + rm ./afbin/lib64/libafcuda*.so* + rm ./ArrayFire-v${AF_VER}_Linux_x86_64.sh + - name: Run clippy tool + env: + AF_PATH: ${{ github.workspace }}/afbin uses: actions-rs/cargo@v1 with: command: clippy