Skip to content

Error in build script when no backends are found #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
34 changes: 23 additions & 11 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,32 @@ 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 {
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
}
}
}

Expand Down Expand Up @@ -291,13 +302,9 @@ fn blob_backends(conf: &Config, build_dir: &std::path::Path) -> (Vec<String>, 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\\")
Expand Down Expand Up @@ -449,6 +456,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);
}
Expand Down