Skip to content

Commit 99d72ec

Browse files
committed
Drop LAPACK symbol inspection
1 parent a12e707 commit 99d72ec

File tree

5 files changed

+36
-234
lines changed

5 files changed

+36
-234
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: 31 additions & 70 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

openblas-build/src/check.rs

Lines changed: 0 additions & 114 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`
@@ -100,111 +99,6 @@ impl MakeConf {
10099
}
101100
}
102101

103-
/// Library inspection using binutils (`nm` and `objdump`) as external command
104-
///
105-
/// - Linked shared libraries using `objdump -p` external command.
106-
/// - Global "T" symbols in the text (code) section of library using `nm -g` external command.
107-
#[derive(Debug, Clone)]
108-
#[allow(dead_code)]
109-
pub struct LibInspect {
110-
pub libs: Vec<String>,
111-
pub symbols: Vec<String>,
112-
}
113-
114-
#[allow(dead_code)]
115-
impl LibInspect {
116-
/// Inspect library file
117-
///
118-
/// Be sure that `nm -g` and `objdump -p` are executed in this function
119-
pub fn new<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
120-
let path = path.as_ref();
121-
if !path.exists() {
122-
return Err(Error::LibraryNotExist {
123-
path: path.to_owned(),
124-
});
125-
}
126-
127-
let nm_out = Command::new("nm").arg("-g").arg(path).output()?;
128-
129-
// assumes `nm` output like following:
130-
//
131-
// ```
132-
// 0000000000909b30 T zupmtr_
133-
// ```
134-
let mut symbols: Vec<_> = nm_out
135-
.stdout
136-
.lines()
137-
.flat_map(|line| {
138-
let line = line.expect("nm output should not include non-UTF8 output");
139-
let entry: Vec<_> = line.trim().split(' ').collect();
140-
if entry.len() == 3 && entry[1] == "T" {
141-
Some(entry[2].into())
142-
} else {
143-
None
144-
}
145-
})
146-
.collect();
147-
symbols.sort(); // sort alphabetically
148-
149-
let mut libs: Vec<_> = Command::new("objdump")
150-
.arg("-p")
151-
.arg(path)
152-
.output()?
153-
.stdout
154-
.lines()
155-
.flat_map(|line| {
156-
let line = line.expect("objdump output should not include non-UTF8 output");
157-
if line.trim().starts_with("NEEDED") {
158-
Some(line.trim().trim_start_matches("NEEDED").trim().to_string())
159-
} else {
160-
None
161-
}
162-
})
163-
.collect();
164-
libs.sort();
165-
166-
Ok(LibInspect { libs, symbols })
167-
}
168-
169-
pub fn has_cblas(&self) -> bool {
170-
for sym in &self.symbols {
171-
if sym.starts_with("cblas_") {
172-
return true;
173-
}
174-
}
175-
false
176-
}
177-
178-
pub fn has_lapack(&self) -> bool {
179-
for sym in &self.symbols {
180-
if sym == "dsyev_" {
181-
return true;
182-
}
183-
}
184-
false
185-
}
186-
187-
pub fn has_lapacke(&self) -> bool {
188-
for sym in &self.symbols {
189-
if sym.starts_with("LAPACKE_") {
190-
return true;
191-
}
192-
}
193-
false
194-
}
195-
196-
pub fn has_lib(&self, name: &str) -> bool {
197-
for lib in &self.libs {
198-
if let Some(stem) = lib.split('.').next() {
199-
if stem == format!("lib{}", name) {
200-
return true;
201-
}
202-
};
203-
}
204-
false
205-
}
206-
}
207-
208102
#[cfg(test)]
209103
mod tests {
210104
use super::*;
@@ -216,12 +110,4 @@ mod tests {
216110
let detail = MakeConf::new(path).unwrap();
217111
assert!(!detail.no_fortran);
218112
}
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-
}
227113
}

openblas-src/build.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,19 +194,19 @@ fn build() {
194194
}
195195

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

199199
println!("cargo:rustc-link-search={}", output.display());
200-
for search_path in &deliv.make_conf.c_extra_libs.search_paths {
200+
for search_path in &make_conf.c_extra_libs.search_paths {
201201
println!("cargo:rustc-link-search={}", search_path.display());
202202
}
203-
for lib in &deliv.make_conf.c_extra_libs.libs {
203+
for lib in &make_conf.c_extra_libs.libs {
204204
println!("cargo:rustc-link-lib={}", lib);
205205
}
206-
for search_path in &deliv.make_conf.f_extra_libs.search_paths {
206+
for search_path in &make_conf.f_extra_libs.search_paths {
207207
println!("cargo:rustc-link-search={}", search_path.display());
208208
}
209-
for lib in &deliv.make_conf.f_extra_libs.libs {
209+
for lib in &make_conf.f_extra_libs.libs {
210210
println!("cargo:rustc-link-lib={}", lib);
211211
}
212212
}

0 commit comments

Comments
 (0)