From 76e74a1d75eb2e0515aa0204dfc69085cc6c7042 Mon Sep 17 00:00:00 2001 From: Charles Samuels Date: Tue, 13 Jul 2021 08:36:58 -0700 Subject: [PATCH 1/2] make intel-mkl-tool use pkgconfig canonically Do not try to detect where the paths are, instead just ask the pkg_config crate to output the linker and include lines as it normally would. This allows intel-mkl-tool to support libmkl installed directly from Debian's "nonfree" repository --- intel-mkl-tool/src/entry.rs | 74 ++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/intel-mkl-tool/src/entry.rs b/intel-mkl-tool/src/entry.rs index b8f1f2f4..ddfa487f 100644 --- a/intel-mkl-tool/src/entry.rs +++ b/intel-mkl-tool/src/entry.rs @@ -48,11 +48,17 @@ impl Targets { } } +#[derive(Debug)] +enum EntryTarget { + Manual(Targets), + PkgConfig, +} + /// Handler for found library #[derive(Debug)] pub struct Entry { config: Config, - targets: Targets, + target: EntryTarget, } impl Entry { @@ -80,22 +86,14 @@ impl Entry { } // pkg-config - if let Ok(lib) = pkg_config::Config::new() + if let Ok(_) = pkg_config::Config::new() .cargo_metadata(false) .probe(&config.name()) { - for path in lib.link_paths { - targets.seek(&path); - } - - // assumes following directory structure: - // - // - mkl - // - include <- lib.include_paths detects this - // - lib/intel64 - for path in lib.include_paths { - targets.seek(&path.join("../lib/intel64")); - } + return Ok(Self { + config, + target: EntryTarget::PkgConfig, + }); } // $XDG_DATA_HOME/intel-mkl-tool @@ -125,7 +123,10 @@ impl Entry { } if targets.found_any() { - return Ok(Self { config, targets }); + return Ok(Self { + config, + target: EntryTarget::Manual(targets), + }); } else { // None found bail!("No library found for {}", config.name()); @@ -137,7 +138,11 @@ impl Entry { } pub fn found_files(&self) -> Vec<(PathBuf, String)> { - self.targets.found_files() + if let EntryTarget::Manual(m) = &self.target { + m.found_files() + } else { + vec![] + } } pub fn available() -> Vec { @@ -196,23 +201,32 @@ impl Entry { } pub fn print_cargo_metadata(&self) { - let paths: HashSet = self - .found_files() - .into_iter() - .map(|(path, _name)| path) - .collect(); // must be redundant - for path in paths { - println!("cargo:rustc-link-search={}", path.display()); - } - for lib in self.config.libs() { - match self.config.link { - LinkType::Static => { - println!("cargo:rustc-link-lib=static={}", lib); + match &self.target { + EntryTarget::Manual(_target) => { + let paths: HashSet = self + .found_files() + .into_iter() + .map(|(path, _name)| path) + .collect(); // must be redundant + for path in paths { + println!("cargo:rustc-link-search={}", path.display()); } - LinkType::Shared => { - println!("cargo:rustc-link-lib=dylib={}", lib); + for lib in self.config.libs() { + match self.config.link { + LinkType::Static => { + println!("cargo:rustc-link-lib=static={}", lib); + } + LinkType::Shared => { + println!("cargo:rustc-link-lib=dylib={}", lib); + } + } } } + EntryTarget::PkgConfig => { + pkg_config::Config::new() + .probe(&self.config.name()) + .unwrap(); + } } } } From c1353ce67e5a33d1327e78a7c673b17e06909d0f Mon Sep 17 00:00:00 2001 From: Charles Samuels Date: Fri, 29 Jul 2022 08:33:03 -0700 Subject: [PATCH 2/2] the version function is not expected to work when pkgconfig is used --- intel-mkl-tool/src/entry.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/intel-mkl-tool/src/entry.rs b/intel-mkl-tool/src/entry.rs index ddfa487f..7339ff86 100644 --- a/intel-mkl-tool/src/entry.rs +++ b/intel-mkl-tool/src/entry.rs @@ -154,7 +154,7 @@ impl Entry { /// Get MKL version info from its C header /// - /// - This will not work for OUT_DIR or XDG_DATA_HOME entry, + /// - This will not work for OUT_DIR, XDG_DATA_HOME, or Pkgconfig entry, /// and returns Error in these cases pub fn version(&self) -> Result<(u32, u32)> { for (path, _) in &self.found_files() { @@ -241,12 +241,4 @@ mod tests { fn with_mkl_availables() { assert_eq!(Entry::available().len(), 8); } - - #[ignore] - #[test] - fn with_mkl_version() { - for entry in Entry::available() { - let _version = entry.version().unwrap(); - } - } }