@@ -47,10 +47,60 @@ impl Library {
47
47
/// Seek MKL libraries in the given directory.
48
48
///
49
49
/// This will seek the directory recursively until finding MKL libraries.
50
- /// Returns `Ok(None)` if not found. `Err` means IO error while seeking .
50
+ /// This do not follow symbolic links .
51
51
///
52
- pub fn seek_directory ( config : Config , root_dir : impl AsRef < Path > ) -> Result < Option < Self > > {
53
- todo ! ( )
52
+ pub fn seek_directory ( config : Config , root_dir : impl AsRef < Path > ) -> Option < Self > {
53
+ let mut library_dir = None ;
54
+ let mut include_dir = None ;
55
+ let mut iomp5_dir = None ;
56
+ for entry in walkdir:: WalkDir :: new ( root_dir) {
57
+ let path = entry. unwrap ( ) . into_path ( ) ;
58
+ if path. is_dir ( ) {
59
+ continue ;
60
+ }
61
+ let ( stem, ext) = match ( path. file_stem ( ) , path. extension ( ) ) {
62
+ ( Some ( stem) , Some ( ext) ) => (
63
+ stem. to_str ( ) . expect ( "Non UTF8 filename" ) ,
64
+ ext. to_str ( ) . expect ( "Non UTF8 filename" ) ,
65
+ ) ,
66
+ _ => continue ,
67
+ } ;
68
+ let dir = path. parent ( ) . unwrap ( ) . to_owned ( ) ;
69
+ if stem == "mkl" && ext == "h" {
70
+ include_dir = Some ( dir) ;
71
+ continue ;
72
+ }
73
+ let name = if let Some ( name) = stem. strip_prefix ( mkl:: PREFIX ) {
74
+ name
75
+ } else {
76
+ continue ;
77
+ } ;
78
+ match ( config. link , ext) {
79
+ ( LinkType :: Static , mkl:: EXTENSION_STATIC ) => match name {
80
+ "mkl_core" => library_dir = Some ( dir) ,
81
+ "iomp5" => iomp5_dir = Some ( dir) ,
82
+ _ => { }
83
+ } ,
84
+ ( LinkType :: Dynamic , mkl:: EXTENSION_SHARED ) => match name {
85
+ "mkl_rt" => library_dir = Some ( dir) ,
86
+ "iomp5" => iomp5_dir = Some ( dir) ,
87
+ _ => { }
88
+ } ,
89
+ _ => { }
90
+ }
91
+ }
92
+ if library_dir == iomp5_dir {
93
+ iomp5_dir = None ;
94
+ }
95
+ match ( library_dir, include_dir) {
96
+ ( Some ( library_dir) , Some ( include_dir) ) => Some ( Library :: Directory {
97
+ config,
98
+ include_dir,
99
+ library_dir,
100
+ iomp5_dir,
101
+ } ) ,
102
+ _ => None ,
103
+ }
54
104
}
55
105
56
106
/// Seek MKL in system
@@ -319,4 +369,13 @@ mod tests {
319
369
fn with_mkl_availables ( ) {
320
370
assert_eq ! ( Entry :: available( ) . len( ) , 8 ) ;
321
371
}
372
+
373
+ /// Seek /opt/intel in Linux system
374
+ #[ ignore]
375
+ #[ test]
376
+ fn seek_opt_intel ( ) {
377
+ let cfg = Config :: from_str ( "mkl-static-lp64-seq" ) . unwrap ( ) ;
378
+ let lib = Library :: seek_directory ( cfg, "/opt/intel" ) . unwrap ( ) ;
379
+ dbg ! ( lib) ;
380
+ }
322
381
}
0 commit comments