|
20 | 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21 | 21 | // SOFTWARE.
|
22 | 22 |
|
| 23 | +extern crate git2; |
| 24 | + |
23 | 25 | use std::env;
|
24 |
| -use std::path; |
| 26 | +use std::path::*; |
25 | 27 | use std::process::Command;
|
26 | 28 |
|
| 29 | +const MKL_ARCHIVE: &'static str = "mkl.tar.xz"; |
| 30 | + |
| 31 | +fn get_branch_name<P: AsRef<Path>>(crate_dir: P) -> String { |
| 32 | + let repo = git2::Repository::open(crate_dir).unwrap(); |
| 33 | + let head = repo.head().unwrap(); |
| 34 | + head.shorthand().unwrap().to_string() |
| 35 | +} |
| 36 | + |
27 | 37 | fn main() {
|
28 |
| - let mkl_dir = path::Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join("mkl_lib"); |
29 |
| - let tar = mkl_dir.join("mkl.tar.xz"); |
30 |
| - let out_dir = env::var("OUT_DIR").unwrap(); |
31 |
| - let st = Command::new("tar") |
32 |
| - .args(&["Jxvf", &tar.to_str().unwrap()]) |
| 38 | + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); |
| 39 | + let crate_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); |
| 40 | + let branch_name = get_branch_name(&crate_dir); |
| 41 | + if !out_dir.join(MKL_ARCHIVE).exists() { |
| 42 | + Command::new("wget") |
| 43 | + .arg(format!("https://github.com/termoshtt/rust-intel-mkl/raw/{}/mkl_lib/mkl.tar.xz", |
| 44 | + branch_name)) |
| 45 | + .current_dir(&out_dir) |
| 46 | + .status() |
| 47 | + .expect("Failed to start download (maybe 'wget' is missing?)"); |
| 48 | + } |
| 49 | + Command::new("tar") |
| 50 | + .args(&["Jxvf", MKL_ARCHIVE]) |
33 | 51 | .current_dir(&out_dir)
|
34 | 52 | .status()
|
35 | 53 | .expect("Failed to start decompression (maybe 'tar' is missing?)");
|
36 |
| - if !st.success() { |
37 |
| - panic!("Failed to extract MKL libraries"); |
38 |
| - } |
39 | 54 |
|
40 |
| - println!("cargo:rustc-link-search={}", out_dir); |
| 55 | + println!("cargo:rustc-link-search={}", out_dir.display()); |
41 | 56 | println!("cargo:rustc-link-lib=dylib=mkl_intel_lp64");
|
42 | 57 | println!("cargo:rustc-link-lib=dylib=mkl_gnu_thread");
|
43 | 58 | println!("cargo:rustc-link-lib=dylib=mkl_core");
|
|
0 commit comments