Skip to content

Commit fde361c

Browse files
committed
Download mkl from GitHub
1 parent 8a24161 commit fde361c

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ build = "build.rs"
1313
links = "mkl_intel_ilp64"
1414

1515
exclude = ["mkl_lib/mkl.tar.xz"]
16+
17+
[build-dependencies]
18+
git2 = "*"

build.rs

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

23+
extern crate git2;
24+
2325
use std::env;
24-
use std::path;
26+
use std::path::*;
2527
use std::process::Command;
2628

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+
2737
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])
3351
.current_dir(&out_dir)
3452
.status()
3553
.expect("Failed to start decompression (maybe 'tar' is missing?)");
36-
if !st.success() {
37-
panic!("Failed to extract MKL libraries");
38-
}
3954

40-
println!("cargo:rustc-link-search={}", out_dir);
55+
println!("cargo:rustc-link-search={}", out_dir.display());
4156
println!("cargo:rustc-link-lib=dylib=mkl_intel_lp64");
4257
println!("cargo:rustc-link-lib=dylib=mkl_gnu_thread");
4358
println!("cargo:rustc-link-lib=dylib=mkl_core");

0 commit comments

Comments
 (0)