Skip to content

Commit a2c2de0

Browse files
committed
Rewrite seek_directory
1 parent 7d3f649 commit a2c2de0

File tree

1 file changed

+40
-43
lines changed

1 file changed

+40
-43
lines changed

intel-mkl-tool/src/entry.rs

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl Library {
168168
let mut library_dir = None;
169169
let mut include_dir = None;
170170
let mut iomp5_dir = None;
171-
for path in walkdir::WalkDir::new(root_dir)
171+
for (dir, file_name) in walkdir::WalkDir::new(root_dir)
172172
.into_iter()
173173
.flatten() // skip unreadable directories
174174
.flat_map(|entry| {
@@ -190,59 +190,56 @@ impl Library {
190190
}) {
191191
return None;
192192
}
193-
Some(path)
194-
})
195-
{
196-
let dir = path
197-
.parent()
198-
.expect("parent must exist here since this is under `root_dir`")
199-
.to_owned();
200193

201-
let (stem, ext) = match (path.file_stem(), path.extension()) {
202-
(Some(stem), Some(ext)) => (
203-
stem.to_str().context("Non UTF8 filename")?,
204-
ext.to_str().context("Non UTF8 filename")?,
205-
),
206-
_ => continue,
207-
};
194+
let dir = path
195+
.parent()
196+
.expect("parent must exist here since this is under `root_dir`")
197+
.to_owned();
208198

209-
if stem == "mkl" && ext == "h" {
210-
log::info!("Found mkl.h: {}", path.display());
199+
if let Some(Some(file_name)) = path.file_name().map(|f| f.to_str()) {
200+
Some((dir, file_name.to_string()))
201+
} else {
202+
None
203+
}
204+
})
205+
{
206+
if include_dir.is_none() && file_name == "mkl.h" {
207+
log::info!("Found mkl.h at {}", dir.display());
211208
include_dir = Some(dir);
212209
continue;
213210
}
214211

215-
let name = if let Some(name) = stem.strip_prefix(std::env::consts::DLL_PREFIX) {
216-
name
217-
} else {
218-
continue;
219-
};
220-
221-
match name {
222-
"mkl_core" => {
223-
match (config.link, ext) {
224-
(LinkType::Static, STATIC_EXTENSION)
225-
| (LinkType::Dynamic, std::env::consts::DLL_EXTENSION) => {}
226-
_ => continue,
212+
if library_dir.is_none() {
213+
for name in mkl_libs(config) {
214+
if file_name == as_filename(config.link, &name) {
215+
log::info!("Found {} at {}", file_name, dir.display());
216+
library_dir = Some(dir.clone());
217+
continue;
227218
}
228-
log::info!("Found: {}", path.display());
229-
library_dir = Some(dir);
230219
}
231-
"iomp5" => {
232-
// Allow both dynamic/static library by default
233-
//
234-
// This is due to some distribution does not provide libiomp5.a
235-
if cfg!(feature = "openmp-strict-link-type") {
236-
match (config.link, ext) {
237-
(LinkType::Static, STATIC_EXTENSION)
238-
| (LinkType::Dynamic, std::env::consts::DLL_EXTENSION) => {}
239-
_ => continue,
220+
}
221+
222+
if file_name.starts_with(OPENMP_RUNTIME_LIB) {
223+
// Allow both dynamic/static library by default
224+
//
225+
// This is due to some distribution does not provide libiomp5.a
226+
if cfg!(feature = "openmp-strict-link-type") {
227+
let ext = match config.link {
228+
LinkType::Static => {
229+
if cfg!(any(target_os = "linux", target_os = "macos")) {
230+
"a"
231+
} else {
232+
"lib"
233+
}
240234
}
235+
LinkType::Dynamic => std::env::consts::DLL_EXTENSION,
236+
};
237+
if !file_name.ends_with(ext) {
238+
continue;
241239
}
242-
log::info!("Found: {}", path.display());
243-
iomp5_dir = Some(dir);
244240
}
245-
_ => {}
241+
log::info!("Found OpenMP runtime ({}): {}", file_name, dir.display());
242+
iomp5_dir = Some(dir);
246243
}
247244
}
248245
if config.parallel == Threading::OpenMP && iomp5_dir.is_none() {

0 commit comments

Comments
 (0)