Skip to content

Commit 47f20b9

Browse files
committed
Library::version
1 parent 7dbcd06 commit 47f20b9

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

intel-mkl-tool/src/entry.rs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,44 @@ impl Library {
196196
///
197197
/// and this corresponds to `(2020, 0, 1)`
198198
///
199-
pub fn version(&self) -> (u32, u32, u32) {
200-
todo!()
199+
pub fn version(&self) -> Result<(u32, u32, u32)> {
200+
let version_h = match self {
201+
Library::PkgConfig { lib, .. } => {
202+
let mut version_h = None;
203+
for path in &lib.include_paths {
204+
let candidate = path.join("mkl_version.h");
205+
if candidate.exists() {
206+
version_h = Some(candidate);
207+
}
208+
}
209+
version_h.context("mkl_version.h not found in pkg-config")?
210+
}
211+
Library::Directory { include_dir, .. } => include_dir.join("mkl_version.h"),
212+
};
213+
214+
let f = fs::File::open(version_h).context("Failed to open mkl_version.h")?;
215+
let f = io::BufReader::new(f);
216+
let mut year = None;
217+
let mut minor = None;
218+
let mut update = None;
219+
for line in f.lines() {
220+
if let Ok(line) = line {
221+
if !line.starts_with("#define") {
222+
continue;
223+
}
224+
let ss: Vec<&str> = line.split(' ').collect();
225+
match ss[1] {
226+
"__INTEL_MKL__" => year = Some(ss[2].parse()?),
227+
"__INTEL_MKL_MINOR__" => minor = Some(ss[2].parse()?),
228+
"__INTEL_MKL_UPDATE__" => update = Some(ss[2].parse()?),
229+
_ => continue,
230+
}
231+
}
232+
}
233+
match (year, minor, update) {
234+
(Some(year), Some(minor), Some(update)) => Ok((year, minor, update)),
235+
_ => bail!("Invalid mkl_version.h"),
236+
}
201237
}
202238
}
203239

@@ -428,8 +464,8 @@ mod tests {
428464
#[test]
429465
fn seek_opt_intel() {
430466
for cfg in Config::possibles() {
431-
let lib = Library::seek_directory(cfg, "/opt/intel").unwrap();
432-
dbg!(lib);
467+
let lib = Library::seek_directory(cfg, "/opt/intel").unwrap().unwrap();
468+
dbg!(lib.version().unwrap());
433469
}
434470
}
435471

@@ -438,7 +474,7 @@ mod tests {
438474
fn pkg_config() {
439475
for cfg in Config::possibles() {
440476
let lib = Library::pkg_config(cfg).unwrap();
441-
dbg!(lib);
477+
dbg!(lib.version().unwrap());
442478
}
443479
}
444480
}

0 commit comments

Comments
 (0)