Skip to content

Commit 146691c

Browse files
committed
Rewrite intel-mkl-src using intel-mkl-tool
1 parent 7f54b8d commit 146691c

File tree

2 files changed

+21
-65
lines changed

2 files changed

+21
-65
lines changed

intel-mkl-src/Cargo.toml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ links = "mkl_intel_lp64"
1515

1616
exclude = ["mkl_lib/mkl.tar.xz"]
1717

18+
[features]
19+
default = []
20+
use-shared = []
21+
1822
[build-dependencies]
19-
pkg-config = "0.3.16"
20-
failure = "0.1.6"
21-
xz2 = "0.1.6"
22-
tar = "0.4.26"
23-
curl = "0.4.25"
23+
failure = "0.1"
24+
25+
[build-dependencies.intel-mkl-tool]
26+
version = "0.1.0"
27+
path = "../intel-mkl-tool"
2428

2529
[dev-dependencies]
2630
libc = "0.2.65"

intel-mkl-src/build.rs

Lines changed: 12 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -20,70 +20,22 @@
2020
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
// SOFTWARE.
2222

23-
use curl::easy::Easy;
2423
use failure::*;
25-
use std::{
26-
env, fs,
27-
io::{self, Write},
28-
path::*,
29-
};
30-
31-
const S3_ADDR: &'static str = "https://s3-ap-northeast-1.amazonaws.com/rust-intel-mkl";
32-
33-
#[cfg(target_os = "linux")]
34-
mod mkl {
35-
pub const ARCHIVE: &'static str = "mkl_linux.tar.xz";
36-
pub const EXT: &'static str = "so";
37-
pub const PREFIX: &'static str = "lib";
38-
}
39-
40-
#[cfg(target_os = "macos")]
41-
mod mkl {
42-
pub const ARCHIVE: &'static str = "mkl_osx.tar.xz";
43-
pub const EXT: &'static str = "dylib";
44-
pub const PREFIX: &'static str = "lib";
45-
}
46-
47-
#[cfg(target_os = "windows")]
48-
mod mkl {
49-
pub const ARCHIVE: &'static str = "mkl_windows64.tar.xz";
50-
pub const EXT: &'static str = "lib";
51-
pub const PREFIX: &'static str = "";
52-
}
24+
use std::{env, path::*};
5325

5426
fn main() -> Fallible<()> {
55-
if pkg_config::find_library("mkl-dynamic-lp64-iomp").is_ok() {
56-
eprintln!("Returning early, pre-installed Intel mkl was found.");
57-
return Ok(());
58-
}
59-
60-
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
61-
62-
let archive = out_dir.join(mkl::ARCHIVE);
63-
if !archive.exists() {
64-
eprintln!("Download archive from AWS S3: {}/{}", S3_ADDR, mkl::ARCHIVE);
65-
let f = fs::File::create(&archive)?;
66-
let mut buf = io::BufWriter::new(f);
67-
let mut easy = Easy::new();
68-
easy.url(&format!("{}/{}", S3_ADDR, mkl::ARCHIVE))?;
69-
easy.write_function(move |data| Ok(buf.write(data).unwrap()))?;
70-
easy.perform()?;
71-
assert!(archive.exists());
27+
let out_dir = if let Some(path) = intel_mkl_tool::seek_pkg_config() {
28+
path
7229
} else {
73-
eprintln!("Use existing archive");
74-
}
75-
76-
let core = out_dir.join(format!("{}mkl_core.{}", mkl::PREFIX, mkl::EXT));
77-
if !core.exists() {
78-
let f = fs::File::open(&archive)?;
79-
let de = xz2::read::XzDecoder::new(f);
80-
let mut arc = tar::Archive::new(de);
81-
arc.unpack(&out_dir)?;
82-
assert!(core.exists());
83-
} else {
84-
eprintln!("Archive has already been extracted");
85-
}
86-
30+
let out_dir = if cfg!(feature = "use-shared") {
31+
intel_mkl_tool::home_library_path()
32+
} else {
33+
PathBuf::from(env::var("OUT_DIR").unwrap())
34+
};
35+
36+
intel_mkl_tool::download(&out_dir)?;
37+
out_dir
38+
};
8739
println!("cargo:rustc-link-search={}", out_dir.display());
8840
println!("cargo:rustc-link-lib=mkl_intel_lp64");
8941
println!("cargo:rustc-link-lib=mkl_sequential");

0 commit comments

Comments
 (0)