@@ -196,8 +196,44 @@ impl Library {
196
196
///
197
197
/// and this corresponds to `(2020, 0, 1)`
198
198
///
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
+ }
201
237
}
202
238
}
203
239
@@ -428,8 +464,8 @@ mod tests {
428
464
#[ test]
429
465
fn seek_opt_intel ( ) {
430
466
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 ( ) ) ;
433
469
}
434
470
}
435
471
@@ -438,7 +474,7 @@ mod tests {
438
474
fn pkg_config ( ) {
439
475
for cfg in Config :: possibles ( ) {
440
476
let lib = Library :: pkg_config ( cfg) . unwrap ( ) ;
441
- dbg ! ( lib) ;
477
+ dbg ! ( lib. version ( ) . unwrap ( ) ) ;
442
478
}
443
479
}
444
480
}
0 commit comments