Skip to content

Commit 2acdf2b

Browse files
committed
Drop LAPACK symbol inspection
1 parent a12e707 commit 2acdf2b

File tree

5 files changed

+86
-157
lines changed

5 files changed

+86
-157
lines changed

openblas-build/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ ureq = { version = "2.5.0", default-features = false, features = [
2222
"gzip",
2323
] }
2424
native-tls = { version = "0.2.11" }
25-
walkdir = "2.3.1"
2625

openblas-build/nofortran.conf

Lines changed: 0 additions & 44 deletions
This file was deleted.

openblas-build/src/build.rs

Lines changed: 74 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use crate::{check::*, error::*};
44
use std::{env, fs, path::*, process::Command, str::FromStr};
5-
use walkdir::WalkDir;
65

76
/// Interface for 32-bit interger (LP64) and 64-bit integer (ILP64)
87
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -345,12 +344,6 @@ impl Default for Configure {
345344
}
346345
}
347346

348-
/// Deliverables of `make` command
349-
pub struct Deliverables {
350-
/// Inspection what `make` command really show.
351-
pub make_conf: MakeConf,
352-
}
353-
354347
impl Configure {
355348
fn make_args(&self) -> Vec<String> {
356349
let mut args = Vec::new();
@@ -396,37 +389,6 @@ impl Configure {
396389
args
397390
}
398391

399-
/// Inspect existing build deliverables, and validate them.
400-
///
401-
/// Error
402-
/// ------
403-
/// - No build deliverables exist
404-
/// - Build deliverables are not valid
405-
/// - e.g. `self.no_lapack == false`, but the existing library does not contains LAPACK symbols.
406-
///
407-
pub fn inspect(&self, out_dir: impl AsRef<Path>) -> Result<Deliverables, Error> {
408-
let out_dir = out_dir.as_ref();
409-
let make_conf = MakeConf::new(out_dir.join("Makefile.conf"))?;
410-
if !self.no_static {
411-
let lib_path = out_dir.join("libopenblas.a");
412-
if !lib_path.exists() {
413-
return Err(Error::LibraryNotExist { path: lib_path });
414-
}
415-
}
416-
if !self.no_shared {
417-
let lib_path = if cfg!(target_os = "macos") {
418-
out_dir.join("libopenblas.dylib")
419-
} else {
420-
out_dir.join("libopenblas.so")
421-
};
422-
if !lib_path.exists() {
423-
return Err(Error::LibraryNotExist { path: lib_path });
424-
}
425-
}
426-
427-
Ok(Deliverables { make_conf })
428-
}
429-
430392
/// Build OpenBLAS
431393
///
432394
/// Libraries are created directly under `out_dir` e.g. `out_dir/libopenblas.a`
@@ -441,38 +403,12 @@ impl Configure {
441403
self,
442404
openblas_root: impl AsRef<Path>,
443405
out_dir: impl AsRef<Path>,
444-
) -> Result<Deliverables, Error> {
406+
) -> Result<MakeConf, Error> {
407+
let root = openblas_root.as_ref();
445408
let out_dir = out_dir.as_ref();
446-
if !out_dir.exists() {
447-
fs::create_dir_all(out_dir)?;
448-
}
449-
450409
// Do not build if libraries and Makefile.conf already exist and are valid
451-
if let Ok(deliv) = self.inspect(out_dir) {
452-
return Ok(deliv);
453-
}
454-
455-
// Copy OpenBLAS sources from this crate to `out_dir`
456-
let root = openblas_root.as_ref();
457-
for entry in WalkDir::new(root) {
458-
let entry = entry.expect("Unknown IO error while walkdir");
459-
let dest = out_dir.join(
460-
entry
461-
.path()
462-
.strip_prefix(root)
463-
.expect("Directory entry is not under root"),
464-
);
465-
if dest.exists() {
466-
// Do not overwrite
467-
// Cache of previous build should be cleaned by `cargo clean`
468-
continue;
469-
}
470-
if entry.file_type().is_dir() {
471-
fs::create_dir(&dest)?;
472-
}
473-
if entry.file_type().is_file() {
474-
fs::copy(entry.path(), &dest)?;
475-
}
410+
if let Ok(make_conf) = MakeConf::new(out_dir.join("Makefile.conf")) {
411+
return Ok(make_conf);
476412
}
477413

478414
// check if cross compile is needed
@@ -494,7 +430,7 @@ impl Configure {
494430
let out = fs::File::create(out_dir.join("out.log")).expect("Cannot create log file");
495431
let err = fs::File::create(out_dir.join("err.log")).expect("Cannot create log file");
496432
match Command::new("make")
497-
.current_dir(out_dir)
433+
.current_dir(root)
498434
.stdout(out)
499435
.stderr(err)
500436
.args(self.make_args())
@@ -514,7 +450,32 @@ impl Configure {
514450
return Err(e);
515451
}
516452
}
517-
self.inspect(out_dir)
453+
454+
// Copy OpenBLAS and Makefile.conf from this crate to `out_dir`
455+
let mut file_names = Vec::new();
456+
if !self.no_static {
457+
file_names.push("libopenblas.a");
458+
}
459+
if !self.no_shared {
460+
if cfg!(target_os = "macos") {
461+
file_names.push("libopenblas.dylib");
462+
} else {
463+
file_names.push("libopenblas.so");
464+
}
465+
}
466+
file_names.push("Makefile.conf");
467+
for file_name in file_names {
468+
let src = root.join(file_name);
469+
let dest = out_dir.join(file_name);
470+
if dest.exists() {
471+
// Do not overwrite
472+
// Cache of previous build should be cleaned by `cargo clean`
473+
continue;
474+
}
475+
fs::copy(src, dest)?;
476+
}
477+
478+
MakeConf::new(out_dir.join("Makefile.conf"))
518479
}
519480
}
520481

@@ -540,53 +501,73 @@ mod tests {
540501
#[test]
541502
fn build_default() {
542503
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
504+
let out_dir = root.join("test_build/build_default");
543505
let opt = Configure::default();
544-
let _detail = opt
545-
.build(get_openblas_source(), root.join("test_build/build_default"))
546-
.unwrap();
506+
let _ = opt.build(get_openblas_source(), &out_dir).unwrap();
547507
}
548508

549509
#[ignore]
550510
#[test]
551511
fn build_no_shared() {
552512
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
513+
let out_dir = root.join("test_build/build_no_shared");
553514
let mut opt = Configure::default();
554515
opt.no_shared = true;
555-
let detail = opt
556-
.build(
557-
get_openblas_source(),
558-
root.join("test_build/build_no_shared"),
559-
)
560-
.unwrap();
561-
assert!(detail.shared_lib.is_none());
516+
opt.build(get_openblas_source(), &out_dir).unwrap();
517+
let _ = LibInspect::new(out_dir.join("libopenblas.a")).unwrap();
562518
}
563519

564520
#[ignore]
565521
#[test]
566522
fn build_no_lapacke() {
567523
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
524+
let out_dir = root.join("test_build/build_no_lapacke");
568525
let mut opt = Configure::default();
569526
opt.no_lapacke = true;
570-
let detail = opt
571-
.build(
572-
get_openblas_source(),
573-
root.join("test_build/build_no_lapacke"),
574-
)
575-
.unwrap();
576-
let shared_lib = detail.shared_lib.unwrap();
577-
assert!(shared_lib.has_lapack());
578-
assert!(!shared_lib.has_lapacke());
527+
let _ = opt.build(get_openblas_source(), &out_dir).unwrap();
528+
let lib_name = if cfg!(target_os = "macos") {
529+
"libopenblas.dylib"
530+
} else {
531+
"libopenblas.so"
532+
};
533+
let lib_inspect = LibInspect::new(out_dir.join(lib_name)).unwrap();
534+
535+
assert!(lib_inspect.has_lapack());
536+
assert!(!lib_inspect.has_lapacke());
537+
}
538+
539+
#[ignore]
540+
#[test]
541+
fn build_no_cblas() {
542+
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
543+
let out_dir = root.join("test_build/build_no_cblas");
544+
let mut opt = Configure::default();
545+
opt.no_lapacke = true;
546+
let _ = opt.build(get_openblas_source(), &out_dir).unwrap();
547+
let lib_name = if cfg!(target_os = "macos") {
548+
"libopenblas.dylib"
549+
} else {
550+
"libopenblas.so"
551+
};
552+
let lib_inspect = LibInspect::new(out_dir.join(lib_name)).unwrap();
553+
554+
assert!(!lib_inspect.has_cblas());
579555
}
580556

581557
#[ignore]
582558
#[test]
583559
fn build_openmp() {
584560
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
561+
let out_dir = root.join("test_build/build_openmp");
585562
let mut opt = Configure::default();
586563
opt.use_openmp = true;
587-
let detail = opt
588-
.build(get_openblas_source(), root.join("test_build/build_openmp"))
589-
.unwrap();
590-
assert!(detail.shared_lib.unwrap().has_lib("gomp"));
564+
let _ = opt.build(get_openblas_source(), &out_dir).unwrap();
565+
let lib_name = if cfg!(target_os = "macos") {
566+
"libopenblas.dylib"
567+
} else {
568+
"libopenblas.so"
569+
};
570+
let lib_inspect = LibInspect::new(out_dir.join(lib_name)).unwrap();
571+
assert!(lib_inspect.has_lib("gomp"));
591572
}
592573
}

openblas-build/src/check.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::{
77
hash::Hash,
88
io::{self, BufRead},
99
path::*,
10-
process::Command,
1110
};
1211

1312
/// Parse compiler linker flags, `-L` and `-l`
@@ -105,18 +104,19 @@ impl MakeConf {
105104
/// - Linked shared libraries using `objdump -p` external command.
106105
/// - Global "T" symbols in the text (code) section of library using `nm -g` external command.
107106
#[derive(Debug, Clone)]
108-
#[allow(dead_code)]
109-
pub struct LibInspect {
107+
#[cfg(test)]
108+
pub(crate) struct LibInspect {
110109
pub libs: Vec<String>,
111110
pub symbols: Vec<String>,
112111
}
113112

114-
#[allow(dead_code)]
113+
#[cfg(test)]
115114
impl LibInspect {
116115
/// Inspect library file
117116
///
118117
/// Be sure that `nm -g` and `objdump -p` are executed in this function
119118
pub fn new<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
119+
use std::process::Command;
120120
let path = path.as_ref();
121121
if !path.exists() {
122122
return Err(Error::LibraryNotExist {
@@ -208,20 +208,11 @@ impl LibInspect {
208208
#[cfg(test)]
209209
mod tests {
210210
use super::*;
211-
212211
#[test]
213212
fn detail_from_makefile_conf() {
214213
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("Makefile.conf");
215214
assert!(path.exists());
216215
let detail = MakeConf::new(path).unwrap();
217216
assert!(!detail.no_fortran);
218217
}
219-
220-
#[test]
221-
fn detail_from_nofortran_conf() {
222-
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("nofortran.conf");
223-
assert!(path.exists());
224-
let detail = MakeConf::new(path).unwrap();
225-
assert!(detail.no_fortran);
226-
}
227218
}

openblas-src/build.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ fn windows_msvc_system() {
5050
env::set_var("VCPKGRS_DYNAMIC", "1");
5151
}
5252
#[cfg(target_env = "msvc")]
53-
vcpkg::find_package("openblas").unwrap();
53+
vcpkg::find_package("openblas").expect(
54+
"vcpkg failed to find OpenBLAS package , Try to install it using `vcpkg install openblas:$(ARCH)-windows(-static)(-md)`"
55+
);
5456
if !cfg!(target_env = "msvc") {
5557
unreachable!();
5658
}
@@ -194,19 +196,19 @@ fn build() {
194196
}
195197

196198
let source = openblas_build::download(&output).unwrap();
197-
let deliv = cfg.build(source, &output).unwrap();
199+
let make_conf = cfg.build(source, &output).unwrap();
198200

199201
println!("cargo:rustc-link-search={}", output.display());
200-
for search_path in &deliv.make_conf.c_extra_libs.search_paths {
202+
for search_path in &make_conf.c_extra_libs.search_paths {
201203
println!("cargo:rustc-link-search={}", search_path.display());
202204
}
203-
for lib in &deliv.make_conf.c_extra_libs.libs {
205+
for lib in &make_conf.c_extra_libs.libs {
204206
println!("cargo:rustc-link-lib={}", lib);
205207
}
206-
for search_path in &deliv.make_conf.f_extra_libs.search_paths {
208+
for search_path in &make_conf.f_extra_libs.search_paths {
207209
println!("cargo:rustc-link-search={}", search_path.display());
208210
}
209-
for lib in &deliv.make_conf.f_extra_libs.libs {
211+
for lib in &make_conf.f_extra_libs.libs {
210212
println!("cargo:rustc-link-lib={}", lib);
211213
}
212214
}

0 commit comments

Comments
 (0)