@@ -48,11 +48,17 @@ impl Targets {
48
48
}
49
49
}
50
50
51
+ #[derive(Debug)]
52
+ enum EntryTarget {
53
+ Manual(Targets),
54
+ PkgConfig,
55
+ }
56
+
51
57
/// Handler for found library
52
58
#[derive(Debug)]
53
59
pub struct Entry {
54
60
config: Config,
55
- targets: Targets ,
61
+ target: EntryTarget ,
56
62
}
57
63
58
64
impl Entry {
@@ -80,22 +86,14 @@ impl Entry {
80
86
}
81
87
82
88
// pkg-config
83
- if let Ok(lib ) = pkg_config::Config::new()
89
+ if let Ok(_ ) = pkg_config::Config::new()
84
90
.cargo_metadata(false)
85
91
.probe(&config.name())
86
92
{
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
+ });
99
97
}
100
98
101
99
// $XDG_DATA_HOME/intel-mkl-tool
@@ -125,7 +123,10 @@ impl Entry {
125
123
}
126
124
127
125
if targets.found_any() {
128
- return Ok(Self { config, targets });
126
+ return Ok(Self {
127
+ config,
128
+ target: EntryTarget::Manual(targets),
129
+ });
129
130
} else {
130
131
// None found
131
132
bail!("No library found for {}", config.name());
@@ -137,7 +138,11 @@ impl Entry {
137
138
}
138
139
139
140
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
+ }
141
146
}
142
147
143
148
pub fn available() -> Vec<Self> {
@@ -196,23 +201,32 @@ impl Entry {
196
201
}
197
202
198
203
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());
211
213
}
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
+ }
214
223
}
215
224
}
225
+ EntryTarget::PkgConfig => {
226
+ pkg_config::Config::new()
227
+ .probe(&self.config.name())
228
+ .unwrap();
229
+ }
216
230
}
217
231
}
218
232
}
0 commit comments