Skip to content

Commit b5f2200

Browse files
committed
Seek also from XDG_DATA_HOME/intel-mkl-tool
1 parent 9e70147 commit b5f2200

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

intel-mkl-tool/src/bin/intel-mkl-tool.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ use structopt::StructOpt;
55
/// CLI tool for intel-mkl crate
66
#[derive(Debug, StructOpt)]
77
enum Opt {
8-
Download { path: Option<PathBuf> },
8+
/// Download Intel-MKL library
9+
Download {
10+
/// Install destination. Default is `$XDG_DATA_HOME/intel-mkl-tool`
11+
path: Option<PathBuf>,
12+
},
13+
/// Seek Intel-MKL library
14+
///
15+
/// 1. pkg-config
16+
/// 2. `$XDG_DATA_HOME/intel-mkl-tool`
17+
/// will be sought.
918
Seek {},
1019
}
1120

@@ -20,14 +29,13 @@ fn main() -> Fallible<()> {
2029
let path = if let Some(path) = path {
2130
path
2231
} else {
23-
let data_dir = dirs::data_local_dir().unwrap();
24-
data_dir.join("intel-mkl-tool")
32+
intel_mkl_tool::home_library_path()
2533
};
2634
intel_mkl_tool::download(&path)?;
2735
}
2836
Opt::Seek {} => {
29-
let paths = intel_mkl_tool::seek_pkg_config()?;
30-
println!("{:?}", paths);
37+
let paths = intel_mkl_tool::seek().ok_or(err_msg("MKL not found"))?;
38+
println!("{}", paths.display());
3139
}
3240
}
3341
Ok(())

intel-mkl-tool/src/lib.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,25 @@ pub fn home_library_path() -> PathBuf {
3434
dirs::data_local_dir().unwrap().join("intel-mkl-tool")
3535
}
3636

37-
/// Seek MKL library from pkg-config
38-
pub fn seek_pkg_config() -> Fallible<pkg_config::Library> {
39-
Ok(pkg_config::probe_library("mkl-dynamic-lp64-iomp")?)
37+
/// Seek MKL library from
38+
///
39+
/// 1. pkg-config
40+
/// 2. `$XDG_DATA_HOME/intel-mkl-tool`
41+
///
42+
/// returns `None` if not found.
43+
///
44+
pub fn seek() -> Option<PathBuf> {
45+
if let Ok(lib) = pkg_config::probe_library("mkl-dynamic-lp64-iomp") {
46+
if lib.libs.len() > 1 {
47+
warn!("Found {} MKL libraries. Use first found.", lib.libs.len())
48+
}
49+
return Some(PathBuf::from(lib.libs[0].clone()));
50+
}
51+
let home_lib = home_library_path();
52+
if home_lib.is_dir() {
53+
return Some(home_lib);
54+
}
55+
None
4056
}
4157

4258
pub fn download(out_dir: &Path) -> Fallible<()> {
@@ -59,7 +75,7 @@ pub fn download(out_dir: &Path) -> Fallible<()> {
5975
easy.perform()?;
6076
assert!(archive.exists());
6177
} else {
62-
info!("Use existing archive: {}", archive.display());
78+
info!("Archive already exists: {}", archive.display());
6379
}
6480

6581
let core = out_dir.join(format!("{}mkl_core.{}", mkl::PREFIX, mkl::EXT));

0 commit comments

Comments
 (0)