Skip to content

make intel-mkl-tool use pkgconfig canonically #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 45 additions & 39 deletions intel-mkl-tool/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand All @@ -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<Self> {
Expand All @@ -149,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() {
Expand Down Expand Up @@ -196,23 +201,32 @@ impl Entry {
}

pub fn print_cargo_metadata(&self) {
let paths: HashSet<PathBuf> = 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<PathBuf> = 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();
}
}
}
}
Expand All @@ -227,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();
}
}
}