Skip to content

Commit 8166537

Browse files
committed
Library::seek_directory
1 parent 1fcc4c4 commit 8166537

File tree

3 files changed

+80
-3
lines changed

3 files changed

+80
-3
lines changed

.github/workflows/intel-mkl-tool.yml

+17
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,20 @@ jobs:
4545
- uses: actions/checkout@v1
4646
- name: Test with mkl-rust container
4747
run: make -C intel-mkl-tool ${{ matrix.target }}
48+
49+
seek-opt-intel:
50+
runs-on: ubuntu-22.04
51+
container:
52+
image: ghcr.io/rust-math/intel-mkl-src/mkl-rust:1.56.0
53+
steps:
54+
- uses: actions/checkout@v1
55+
- uses: actions-rs/cargo@v1
56+
name: cargo test seek_opt_intel
57+
with:
58+
command: test
59+
args: >
60+
--manifest-path=intel-mkl-tool/Cargo.toml
61+
seek_opt_intel
62+
--
63+
--ignored
64+
--show-output

intel-mkl-tool/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ zstd = { version = "0.11.2", optional = true }
2929

3030
# CLI
3131
structopt = { version = "0.3.26", optional = true }
32+
walkdir = "2.3.2"
3233

3334
[dev-dependencies]
3435
paste = "1.0.7"

intel-mkl-tool/src/entry.rs

+62-3
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,60 @@ impl Library {
4747
/// Seek MKL libraries in the given directory.
4848
///
4949
/// This will seek the directory recursively until finding MKL libraries.
50-
/// Returns `Ok(None)` if not found. `Err` means IO error while seeking.
50+
/// This do not follow symbolic links.
5151
///
52-
pub fn seek_directory(config: Config, root_dir: impl AsRef<Path>) -> Result<Option<Self>> {
53-
todo!()
52+
pub fn seek_directory(config: Config, root_dir: impl AsRef<Path>) -> Option<Self> {
53+
let mut library_dir = None;
54+
let mut include_dir = None;
55+
let mut iomp5_dir = None;
56+
for entry in walkdir::WalkDir::new(root_dir) {
57+
let path = entry.unwrap().into_path();
58+
if path.is_dir() {
59+
continue;
60+
}
61+
let (stem, ext) = match (path.file_stem(), path.extension()) {
62+
(Some(stem), Some(ext)) => (
63+
stem.to_str().expect("Non UTF8 filename"),
64+
ext.to_str().expect("Non UTF8 filename"),
65+
),
66+
_ => continue,
67+
};
68+
let dir = path.parent().unwrap().to_owned();
69+
if stem == "mkl" && ext == "h" {
70+
include_dir = Some(dir);
71+
continue;
72+
}
73+
let name = if let Some(name) = stem.strip_prefix(mkl::PREFIX) {
74+
name
75+
} else {
76+
continue;
77+
};
78+
match (config.link, ext) {
79+
(LinkType::Static, mkl::EXTENSION_STATIC) => match name {
80+
"mkl_core" => library_dir = Some(dir),
81+
"iomp5" => iomp5_dir = Some(dir),
82+
_ => {}
83+
},
84+
(LinkType::Dynamic, mkl::EXTENSION_SHARED) => match name {
85+
"mkl_rt" => library_dir = Some(dir),
86+
"iomp5" => iomp5_dir = Some(dir),
87+
_ => {}
88+
},
89+
_ => {}
90+
}
91+
}
92+
if library_dir == iomp5_dir {
93+
iomp5_dir = None;
94+
}
95+
match (library_dir, include_dir) {
96+
(Some(library_dir), Some(include_dir)) => Some(Library::Directory {
97+
config,
98+
include_dir,
99+
library_dir,
100+
iomp5_dir,
101+
}),
102+
_ => None,
103+
}
54104
}
55105

56106
/// Seek MKL in system
@@ -319,4 +369,13 @@ mod tests {
319369
fn with_mkl_availables() {
320370
assert_eq!(Entry::available().len(), 8);
321371
}
372+
373+
/// Seek /opt/intel in Linux system
374+
#[ignore]
375+
#[test]
376+
fn seek_opt_intel() {
377+
let cfg = Config::from_str("mkl-static-lp64-seq").unwrap();
378+
let lib = Library::seek_directory(cfg, "/opt/intel").unwrap();
379+
dbg!(lib);
380+
}
322381
}

0 commit comments

Comments
 (0)