Skip to content

Commit 7dd45b9

Browse files
authored
Merge pull request #16 from rust-math/windows
Support Windows
2 parents 6b7d672 + 86004da commit 7dd45b9

File tree

4 files changed

+86
-96
lines changed

4 files changed

+86
-96
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ exclude = ["mkl_lib/mkl.tar.xz"]
1616

1717
[build-dependencies]
1818
pkg-config = "0.3"
19-
rust-crypto = "0.2"
19+
failure = "0.1"
20+
reqwest = "0.9"
21+
xz2 = "0.1"
22+
tar = "0.4"
2023

2124
[dev-dependencies]
2225
libc = "0.2"

azure-pipelines.yml

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,45 @@ resources:
44
image: rustmath/mkl:latest
55

66
jobs:
7-
- template: ci/job.yml
8-
parameters:
9-
name: Linux
10-
pool:
11-
vmImage: 'ubuntu-16.04'
12-
13-
- template: ci/job.yml
14-
parameters:
15-
name: macOS
16-
pool:
17-
vmImage: 'macOS-10.14'
18-
197
- job: 'pkg_config'
208
pool:
219
vmImage: 'ubuntu-16.04'
2210
container: rust-mkl
2311
steps:
24-
- script: cargo test --verbose
12+
- script: cargo test -v
13+
displayName: run test
14+
15+
- job: Linux
16+
pool:
17+
vmImage: 'ubuntu-16.04'
18+
steps:
19+
- script: |
20+
curl -sSf https://sh.rustup.rs | sh -s -- -y
21+
echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin"
22+
displayName: install rustup
23+
- script: cargo test -v
24+
displayName: run test
25+
26+
- job: macOS
27+
pool:
28+
vmImage: 'macOS-10.14'
29+
steps:
30+
- script: |
31+
curl -sSf https://sh.rustup.rs | sh -s -- -y
32+
echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin"
33+
displayName: install rustup
34+
- script: cargo test -v
35+
displayName: run test
36+
37+
- job: Windows
38+
pool:
39+
vmImage: 'windows-2019'
40+
steps:
41+
- script: |
42+
curl -sSf -o rustup-init.exe https://win.rustup.rs
43+
rustup-init.exe -y 2>&1
44+
set PATH=%PATH%;%USERPROFILE%\.cargo\bin
45+
echo '##vso[task.setvariable variable=PATH;]%PATH%;%USERPROFILE%\.cargo\bin'
46+
displayName: install rustup on Windows
47+
- script: cargo test -v 2>&1
48+
displayName: run test

build.rs

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

23-
extern crate crypto;
23+
extern crate failure;
2424
extern crate pkg_config;
25+
extern crate reqwest;
26+
extern crate tar;
27+
extern crate xz2;
2528

26-
use crypto::digest::Digest;
27-
use crypto::md5;
29+
use failure::*;
30+
use std::{env, fs, io, path::*};
2831

29-
use std::env::var;
30-
use std::fs;
31-
use std::io::*;
32-
use std::path::*;
33-
use std::process::Command;
32+
const S3_ADDR: &'static str = "https://s3-ap-northeast-1.amazonaws.com/rust-intel-mkl";
3433

3534
#[cfg(target_os = "linux")]
3635
mod mkl {
3736
pub const ARCHIVE: &'static str = "mkl_linux.tar.xz";
38-
pub const MD5SUM: &'static str = "03aa6b3918da6046b1225aacd244363a";
39-
pub const URI: &'static str = "https://www.dropbox.com/s/nnlfdio0ka9yeo1/mkl_linux.tar.xz";
37+
pub const EXT: &'static str = "so";
38+
pub const PREFIX: &'static str = "lib";
4039
}
4140

4241
#[cfg(target_os = "macos")]
4342
mod mkl {
4443
pub const ARCHIVE: &'static str = "mkl_osx.tar.xz";
45-
pub const MD5SUM: &'static str = "3774e0c8b4ebcb8639a4f293d749bd32";
46-
pub const URI: &'static str = "https://www.dropbox.com/s/fw74msh8udjdv28/mkl_osx.tar.xz";
44+
pub const EXT: &'static str = "dylib";
45+
pub const PREFIX: &'static str = "lib";
4746
}
4847

49-
fn download(uri: &str, filename: &str, out_dir: &Path) {
50-
let out = out_dir.join(filename);
51-
let mut f = BufWriter::new(fs::File::create(out).unwrap());
52-
let p = Command::new("curl")
53-
.args(&["-L", uri])
54-
.output()
55-
.expect("Failed to start download");
56-
f.write(&p.stdout).unwrap();
57-
}
58-
59-
fn calc_md5(path: &Path) -> String {
60-
let mut sum = md5::Md5::new();
61-
let mut f = BufReader::new(fs::File::open(path).unwrap());
62-
let mut buf = Vec::new();
63-
f.read_to_end(&mut buf).unwrap();
64-
sum.input(&buf);
65-
sum.result_str()
66-
}
67-
68-
fn expand(archive: &Path, out_dir: &Path) {
69-
let st = Command::new("tar")
70-
.args(&["xvf", archive.to_str().unwrap()])
71-
.current_dir(&out_dir)
72-
.status()
73-
.expect("Failed to start expanding archive");
74-
if !st.success() {
75-
panic!("Failed to expand archive");
76-
}
48+
#[cfg(target_os = "windows")]
49+
mod mkl {
50+
pub const ARCHIVE: &'static str = "mkl_windows64.tar.xz";
51+
pub const EXT: &'static str = "lib";
52+
pub const PREFIX: &'static str = "";
7753
}
7854

79-
fn main() {
55+
fn main() -> Fallible<()> {
8056
if pkg_config::find_library("mkl-dynamic-lp64-iomp").is_ok() {
81-
println!("Returning early, pre-installed Intel MKL was found.");
82-
return;
57+
eprintln!("Returning early, pre-installed Intel mkl was found.");
58+
return Ok(());
8359
}
8460

85-
let out_dir = PathBuf::from(var("OUT_DIR").unwrap());
86-
let archive_path = out_dir.join(mkl::ARCHIVE);
61+
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
8762

88-
if archive_path.exists() && calc_md5(&archive_path) == mkl::MD5SUM {
89-
println!("Use existings archive");
90-
} else {
91-
println!("Download archive");
92-
download(mkl::URI, mkl::ARCHIVE, &out_dir);
93-
let sum = calc_md5(&archive_path);
94-
if sum != mkl::MD5SUM {
95-
panic!(
96-
"check sum of downloaded archive is incorrect: md5sum={}",
97-
sum
98-
);
63+
let archive = out_dir.join(mkl::ARCHIVE);
64+
if !archive.exists() {
65+
eprintln!("Download archive from AWS S3: {}/{}", S3_ADDR, mkl::ARCHIVE);
66+
let mut res = reqwest::get(&format!("{}/{}", S3_ADDR, mkl::ARCHIVE))?;
67+
if !res.status().is_success() {
68+
bail!("HTTP access failed: {}", res.status());
9969
}
70+
let f = fs::File::create(&archive)?;
71+
let mut buf = io::BufWriter::new(f);
72+
res.copy_to(&mut buf)?;
73+
assert!(archive.exists());
74+
} else {
75+
eprintln!("Use existing archive");
76+
}
77+
78+
let core = out_dir.join(format!("{}mkl_core.{}", mkl::PREFIX, mkl::EXT));
79+
if !core.exists() {
80+
let f = fs::File::open(&archive)?;
81+
let de = xz2::read::XzDecoder::new(f);
82+
let mut arc = tar::Archive::new(de);
83+
arc.unpack(&out_dir)?;
84+
assert!(core.exists());
85+
} else {
86+
eprintln!("Archive has already been extracted");
10087
}
101-
expand(&archive_path, &out_dir);
10288

10389
println!("cargo:rustc-link-search={}", out_dir.display());
10490
println!("cargo:rustc-link-lib=mkl_intel_lp64");
105-
println!("cargo:rustc-link-lib=mkl_intel_thread");
91+
println!("cargo:rustc-link-lib=mkl_sequential");
10692
println!("cargo:rustc-link-lib=mkl_core");
107-
println!("cargo:rustc-link-lib=iomp5");
108-
println!("cargo:rustc-link-lib=m");
93+
Ok(())
10994
}

ci/job.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)