From b6ade9a533211436fcd05b2dcd26223942b59205 Mon Sep 17 00:00:00 2001 From: Toshiki Teramura Date: Sat, 24 Dec 2022 17:32:29 +0900 Subject: [PATCH] Fix macOS case, and tests in openblas_build --- openblas-build/src/build.rs | 29 +++++++++++++++++++---------- openblas-src/build.rs | 15 +++++++++++---- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/openblas-build/src/build.rs b/openblas-build/src/build.rs index 4c13178..22fdf08 100644 --- a/openblas-build/src/build.rs +++ b/openblas-build/src/build.rs @@ -434,16 +434,28 @@ mod tests { )); } + fn get_openblas_source() -> PathBuf { + let openblas_src_root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../openblas-src"); + let openblas_version = "0.3.21"; + let source = openblas_src_root.join(format!("OpenBLAS-{}", openblas_version)); + if !source.exists() { + Command::new("tar") + .arg("xf") + .arg(format!("OpenBLAS-{}.tar.gz", openblas_version)) + .current_dir(openblas_src_root) + .status() + .expect("tar command not found"); + } + source + } + #[ignore] #[test] fn build_default() { let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); let opt = Configure::default(); let _detail = opt - .build( - root.join("../openblas-src/source"), - root.join("test_build/build_default"), - ) + .build(get_openblas_source(), root.join("test_build/build_default")) .unwrap(); } @@ -455,7 +467,7 @@ mod tests { opt.no_shared = true; let detail = opt .build( - root.join("../openblas-src/source"), + get_openblas_source(), root.join("test_build/build_no_shared"), ) .unwrap(); @@ -470,7 +482,7 @@ mod tests { opt.no_lapacke = true; let detail = opt .build( - root.join("../openblas-src/source"), + get_openblas_source(), root.join("test_build/build_no_lapacke"), ) .unwrap(); @@ -486,10 +498,7 @@ mod tests { let mut opt = Configure::default(); opt.use_openmp = true; let detail = opt - .build( - root.join("../openblas-src/source"), - root.join("test_build/build_openmp"), - ) + .build(get_openblas_source(), root.join("test_build/build_openmp")) .unwrap(); assert!(detail.shared_lib.unwrap().has_lib("gomp")); } diff --git a/openblas-src/build.rs b/openblas-src/build.rs index 1da46ae..adcd2d5 100644 --- a/openblas-src/build.rs +++ b/openblas-src/build.rs @@ -1,5 +1,7 @@ use std::{env, path::*, process::Command}; +const OPENBLAS_VERSION: &str = "0.3.21"; + fn feature_enabled(feature: &str) -> bool { env::var(format!("CARGO_FEATURE_{}", feature.to_uppercase())).is_ok() } @@ -158,13 +160,12 @@ fn build() { ); } - let openblas_version = "0.3.21"; let source = - PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("OpenBLAS-{}", openblas_version)); + PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("OpenBLAS-{}", OPENBLAS_VERSION)); if !source.exists() { Command::new("tar") .arg("xf") - .arg(format!("OpenBLAS-{}.tar.gz", openblas_version)) + .arg(format!("OpenBLAS-{}.tar.gz", OPENBLAS_VERSION)) .current_dir(env!("CARGO_MANIFEST_DIR")) .status() .expect("tar command not found"); @@ -243,7 +244,13 @@ fn build() { if source_tmp.exists() { fs::remove_dir_all(&source_tmp).unwrap(); } - run(Command::new("cp").arg("-R").arg("source").arg(&source_tmp)); + run(Command::new("tar") + .arg("xf") + .arg(format!("OpenBLAS-{}.tar.gz", OPENBLAS_VERSION))); + run(Command::new("cp") + .arg("-R") + .arg(format!("OpenBLAS-{}", OPENBLAS_VERSION)) + .arg(&source_tmp)); fs::rename(&source_tmp, &source).unwrap(); } for name in &vec!["CC", "FC", "HOSTCC"] {