Skip to content

Commit 6e40e0a

Browse files
committed
Move download to openblas_build crate
1 parent 3ca6bd2 commit 6e40e0a

File tree

6 files changed

+35
-40
lines changed

6 files changed

+35
-40
lines changed

openblas-build/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,9 @@ exclude = [
1616
]
1717

1818
[dependencies]
19+
anyhow = "1.0.68"
20+
flate2 = "1.0.25"
21+
tar = "0.4.38"
1922
thiserror = "1.0.22"
23+
ureq = "2.5.0"
2024
walkdir = "2.3.1"

openblas-build/src/build.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -436,17 +436,7 @@ mod tests {
436436

437437
fn get_openblas_source() -> PathBuf {
438438
let openblas_src_root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../openblas-src");
439-
let openblas_version = "0.3.21";
440-
let source = openblas_src_root.join(format!("OpenBLAS-{}", openblas_version));
441-
if !source.exists() {
442-
Command::new("tar")
443-
.arg("xf")
444-
.arg(format!("OpenBLAS-{}.tar.gz", openblas_version))
445-
.current_dir(openblas_src_root)
446-
.status()
447-
.expect("tar command not found");
448-
}
449-
source
439+
crate::download(&openblas_src_root).unwrap()
450440
}
451441

452442
#[ignore]

openblas-build/src/download.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use anyhow::Result;
2+
use std::path::{Path, PathBuf};
3+
4+
const OPENBLAS_VERSION: &str = "0.3.21";
5+
6+
pub fn openblas_source_url() -> String {
7+
format!(
8+
"https://github.com/xianyi/OpenBLAS/releases/download/v{}/OpenBLAS-{}.tar.gz",
9+
OPENBLAS_VERSION, OPENBLAS_VERSION
10+
)
11+
}
12+
13+
pub fn download(out_dir: &Path) -> Result<PathBuf> {
14+
let dest = out_dir.join(format!("OpenBLAS-{}", OPENBLAS_VERSION));
15+
if !dest.exists() {
16+
let buf = ureq::get(&openblas_source_url()).call()?.into_reader();
17+
let gz_stream = flate2::read::GzDecoder::new(buf);
18+
let mut ar = tar::Archive::new(gz_stream);
19+
ar.unpack(&out_dir)?;
20+
assert!(dest.exists());
21+
}
22+
Ok(dest)
23+
}

openblas-build/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
1515
mod build;
1616
mod check;
17+
mod download;
1718
pub mod error;
1819
pub use build::*;
1920
pub use check::*;
21+
pub use download::*;

openblas-src/Cargo.toml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,9 @@ libc = "0.2"
3737

3838
[build-dependencies]
3939
dirs = "3.0.1"
40-
flate2 = "1.0.25"
41-
tar = "0.4.38"
42-
ureq = "2.5.0"
40+
41+
[target.'cfg(not(target_os="windows"))'.build-dependencies]
42+
openblas-build = { version = "0.10.6", path = "../openblas-build" }
4343

4444
[target.'cfg(target_os="windows")'.build-dependencies]
4545
vcpkg = "0.2"
46-
47-
[target.'cfg(target_os="linux")'.build-dependencies.openblas-build]
48-
version = "0.10.6"
49-
path = "../openblas-build"

openblas-src/build.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
use std::{env, path::*, process::Command};
22

3-
const OPENBLAS_SOURCE_URL: &str =
4-
"https://github.com/xianyi/OpenBLAS/releases/download/v0.3.21/OpenBLAS-0.3.21.tar.gz";
5-
const OPENBLAS_VERSION: &str = "0.3.21";
6-
73
#[allow(unused)]
84
fn run(command: &mut Command) {
95
println!("Running: `{:?}`", command);
@@ -177,13 +173,7 @@ fn build() {
177173
);
178174
}
179175

180-
let source = output.join(format!("OpenBLAS-{}", OPENBLAS_VERSION));
181-
if !source.exists() {
182-
let buf = ureq::get(OPENBLAS_SOURCE_URL).call().unwrap().into_reader();
183-
let gz_stream = flate2::read::GzDecoder::new(buf);
184-
let mut ar = tar::Archive::new(gz_stream);
185-
ar.unpack(&output).unwrap();
186-
}
176+
let source = openblas_build::download(&output).unwrap();
187177
let deliv = cfg.build(&source, &output).unwrap();
188178

189179
println!("cargo:rustc-link-search={}", output.display());
@@ -254,17 +244,7 @@ fn build() {
254244
};
255245

256246
if !source.exists() {
257-
let source_tmp = PathBuf::from(format!("{}_tmp", source.display()));
258-
if source_tmp.exists() {
259-
fs::remove_dir_all(&source_tmp).unwrap();
260-
}
261-
run(Command::new("tar")
262-
.arg("xf")
263-
.arg(format!("OpenBLAS-{}.tar.gz", OPENBLAS_VERSION)));
264-
run(Command::new("cp")
265-
.arg("-R")
266-
.arg(format!("OpenBLAS-{}", OPENBLAS_VERSION))
267-
.arg(&source_tmp));
247+
let source_tmp = openblas_build::download(&output).unwrap();
268248
fs::rename(&source_tmp, &source).unwrap();
269249
}
270250
for name in &vec!["CC", "FC", "HOSTCC"] {

0 commit comments

Comments
 (0)