Skip to content

Commit 2c1141d

Browse files
committed
Pass OpenBLAS root path from openblas-src to openblas-build
1 parent a4561f1 commit 2c1141d

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

openblas-build/src/build.rs

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@ use std::{
99
};
1010
use walkdir::WalkDir;
1111

12-
fn openblas_source_dir() -> PathBuf {
13-
// FIXME This cannot work with cargo publish/package
14-
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
15-
.parent()
16-
.unwrap()
17-
.join("openblas-src/source");
18-
if !path.join("Makefile").exists() {
19-
panic!("OpenBLAS repository has not been cloned. Run `git submodule update --init`");
20-
}
21-
path
22-
}
23-
2412
/// Interface for 32-bit interger (LP64) and 64-bit integer (ILP64)
2513
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
2614
pub enum Interface {
@@ -248,7 +236,11 @@ impl Configure {
248236
/// This means that the system environment is not appropriate to execute `make`,
249237
/// e.g. LAPACK is required but there is no Fortran compiler.
250238
///
251-
pub fn build<P: AsRef<Path>>(self, out_dir: P) -> Result<Deliverables, Error> {
239+
pub fn build(
240+
self,
241+
openblas_root: impl AsRef<Path>,
242+
out_dir: impl AsRef<Path>,
243+
) -> Result<Deliverables, Error> {
252244
let out_dir = out_dir.as_ref();
253245
if !out_dir.exists() {
254246
fs::create_dir_all(out_dir)?;
@@ -260,7 +252,7 @@ impl Configure {
260252
}
261253

262254
// Copy OpenBLAS sources from this crate to `out_dir`
263-
let root = openblas_source_dir();
255+
let root = openblas_root.as_ref();
264256
for entry in WalkDir::new(&root) {
265257
let entry = entry.expect("Unknown IO error while walkdir");
266258
let dest = out_dir.join(
@@ -324,28 +316,43 @@ mod tests {
324316
#[ignore]
325317
#[test]
326318
fn build_default() {
327-
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test_build/build_default");
319+
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
328320
let opt = Configure::default();
329-
let _detail = opt.build(path).unwrap();
321+
let _detail = opt
322+
.build(
323+
root.join("../openblas-src/source"),
324+
root.join("test_build/build_default"),
325+
)
326+
.unwrap();
330327
}
331328

332329
#[ignore]
333330
#[test]
334331
fn build_no_shared() {
335-
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test_build/build_no_shared");
332+
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
336333
let mut opt = Configure::default();
337334
opt.no_shared = true;
338-
let detail = opt.build(path).unwrap();
335+
let detail = opt
336+
.build(
337+
root.join("../openblas-src/source"),
338+
root.join("test_build/build_no_shared"),
339+
)
340+
.unwrap();
339341
assert!(detail.shared_lib.is_none());
340342
}
341343

342344
#[ignore]
343345
#[test]
344346
fn build_no_lapacke() {
345-
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test_build/build_no_lapacke");
347+
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
346348
let mut opt = Configure::default();
347349
opt.no_lapacke = true;
348-
let detail = opt.build(path).unwrap();
350+
let detail = opt
351+
.build(
352+
root.join("../openblas-src/source"),
353+
root.join("test_build/build_no_lapacke"),
354+
)
355+
.unwrap();
349356
let shared_lib = detail.shared_lib.unwrap();
350357
assert!(shared_lib.has_lapack());
351358
assert!(!shared_lib.has_lapacke());
@@ -354,10 +361,15 @@ mod tests {
354361
#[ignore]
355362
#[test]
356363
fn build_openmp() {
357-
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("test_build/build_openmp");
364+
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
358365
let mut opt = Configure::default();
359366
opt.use_openmp = true;
360-
let detail = opt.build(path).unwrap();
367+
let detail = opt
368+
.build(
369+
root.join("../openblas-src/source"),
370+
root.join("test_build/build_openmp"),
371+
)
372+
.unwrap();
361373
assert!(detail.shared_lib.unwrap().has_lib("gomp"));
362374
}
363375
}

openblas-src/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ fn build() {
146146
);
147147
}
148148

149-
let deliv = cfg.build(&output).unwrap();
149+
let source = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("source");
150+
let deliv = cfg.build(&source, &output).unwrap();
150151

151152
for search_path in &deliv.make_conf.c_extra_libs.search_paths {
152153
println!("cargo:rustc-link-search={}", search_path.display());

0 commit comments

Comments
 (0)