Skip to content

Commit 76e74a1

Browse files
author
Charles Samuels
committed
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
1 parent 18f2357 commit 76e74a1

File tree

1 file changed

+44
-30
lines changed

1 file changed

+44
-30
lines changed

intel-mkl-tool/src/entry.rs

+44-30
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ impl Targets {
4848
}
4949
}
5050

51+
#[derive(Debug)]
52+
enum EntryTarget {
53+
Manual(Targets),
54+
PkgConfig,
55+
}
56+
5157
/// Handler for found library
5258
#[derive(Debug)]
5359
pub struct Entry {
5460
config: Config,
55-
targets: Targets,
61+
target: EntryTarget,
5662
}
5763

5864
impl Entry {
@@ -80,22 +86,14 @@ impl Entry {
8086
}
8187

8288
// pkg-config
83-
if let Ok(lib) = pkg_config::Config::new()
89+
if let Ok(_) = pkg_config::Config::new()
8490
.cargo_metadata(false)
8591
.probe(&config.name())
8692
{
87-
for path in lib.link_paths {
88-
targets.seek(&path);
89-
}
90-
91-
// assumes following directory structure:
92-
//
93-
// - mkl
94-
// - include <- lib.include_paths detects this
95-
// - lib/intel64
96-
for path in lib.include_paths {
97-
targets.seek(&path.join("../lib/intel64"));
98-
}
93+
return Ok(Self {
94+
config,
95+
target: EntryTarget::PkgConfig,
96+
});
9997
}
10098

10199
// $XDG_DATA_HOME/intel-mkl-tool
@@ -125,7 +123,10 @@ impl Entry {
125123
}
126124

127125
if targets.found_any() {
128-
return Ok(Self { config, targets });
126+
return Ok(Self {
127+
config,
128+
target: EntryTarget::Manual(targets),
129+
});
129130
} else {
130131
// None found
131132
bail!("No library found for {}", config.name());
@@ -137,7 +138,11 @@ impl Entry {
137138
}
138139

139140
pub fn found_files(&self) -> Vec<(PathBuf, String)> {
140-
self.targets.found_files()
141+
if let EntryTarget::Manual(m) = &self.target {
142+
m.found_files()
143+
} else {
144+
vec![]
145+
}
141146
}
142147

143148
pub fn available() -> Vec<Self> {
@@ -196,23 +201,32 @@ impl Entry {
196201
}
197202

198203
pub fn print_cargo_metadata(&self) {
199-
let paths: HashSet<PathBuf> = self
200-
.found_files()
201-
.into_iter()
202-
.map(|(path, _name)| path)
203-
.collect(); // must be redundant
204-
for path in paths {
205-
println!("cargo:rustc-link-search={}", path.display());
206-
}
207-
for lib in self.config.libs() {
208-
match self.config.link {
209-
LinkType::Static => {
210-
println!("cargo:rustc-link-lib=static={}", lib);
204+
match &self.target {
205+
EntryTarget::Manual(_target) => {
206+
let paths: HashSet<PathBuf> = self
207+
.found_files()
208+
.into_iter()
209+
.map(|(path, _name)| path)
210+
.collect(); // must be redundant
211+
for path in paths {
212+
println!("cargo:rustc-link-search={}", path.display());
211213
}
212-
LinkType::Shared => {
213-
println!("cargo:rustc-link-lib=dylib={}", lib);
214+
for lib in self.config.libs() {
215+
match self.config.link {
216+
LinkType::Static => {
217+
println!("cargo:rustc-link-lib=static={}", lib);
218+
}
219+
LinkType::Shared => {
220+
println!("cargo:rustc-link-lib=dylib={}", lib);
221+
}
222+
}
214223
}
215224
}
225+
EntryTarget::PkgConfig => {
226+
pkg_config::Config::new()
227+
.probe(&self.config.name())
228+
.unwrap();
229+
}
216230
}
217231
}
218232
}

0 commit comments

Comments
 (0)