|
20 | 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21 | 21 | // SOFTWARE.
|
22 | 22 |
|
23 |
| -use curl::easy::Easy; |
24 | 23 | 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::*}; |
53 | 25 |
|
54 | 26 | 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 |
72 | 29 | } 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 | + }; |
87 | 39 | println!("cargo:rustc-link-search={}", out_dir.display());
|
88 | 40 | println!("cargo:rustc-link-lib=mkl_intel_lp64");
|
89 | 41 | println!("cargo:rustc-link-lib=mkl_sequential");
|
|
0 commit comments