1
1
use crate :: { Config , LinkType , Threading } ;
2
- use anyhow:: { bail, ensure , Context , Result } ;
2
+ use anyhow:: { bail, Context , Result } ;
3
3
use std:: {
4
4
fs,
5
5
io:: { self , BufRead } ,
@@ -67,13 +67,15 @@ impl Library {
67
67
if out. status . success ( ) {
68
68
let path = String :: from_utf8 ( out. stdout ) . context ( "Non-UTF8 MKL prefix" ) ?;
69
69
let prefix = Path :: new ( path. trim ( ) ) ;
70
+ let prefix = fs:: canonicalize ( prefix) ?;
71
+ log:: info!( "pkg-config found {} on {}" , config, prefix. display( ) ) ;
70
72
Self :: seek_directory ( config, prefix)
71
73
} else {
72
- // pkg-config does not find MKL
74
+ log :: info! ( " pkg-config does not find {}" , config ) ;
73
75
Ok ( None )
74
76
}
75
77
} else {
76
- // pkg-config is not found
78
+ log :: info! ( " pkg-config itself is not found" ) ;
77
79
Ok ( None )
78
80
}
79
81
}
@@ -94,87 +96,87 @@ impl Library {
94
96
let mut library_dir = None ;
95
97
let mut include_dir = None ;
96
98
let mut iomp5_dir = None ;
97
- for entry in walkdir:: WalkDir :: new ( root_dir) . into_iter ( ) . flatten ( ) {
98
- if entry. path_is_symlink ( ) {
99
- continue ;
100
- }
101
- let path = entry. into_path ( ) ;
102
- if path. is_dir ( ) {
103
- continue ;
104
- }
99
+ for path in walkdir:: WalkDir :: new ( root_dir)
100
+ . into_iter ( )
101
+ . flatten ( ) // skip unreadable directories
102
+ . flat_map ( |entry| {
103
+ let path = entry. into_path ( ) ;
104
+ // Skip directory
105
+ if path. is_dir ( ) {
106
+ return None ;
107
+ }
108
+ // Skip files under directory for ia32
109
+ if path. components ( ) . any ( |c| {
110
+ if let std:: path:: Component :: Normal ( c) = c {
111
+ if let Some ( c) = c. to_str ( ) {
112
+ if c. starts_with ( "ia32" ) {
113
+ return true ;
114
+ }
115
+ }
116
+ }
117
+ false
118
+ } ) {
119
+ return None ;
120
+ }
121
+ Some ( path)
122
+ } )
123
+ {
124
+ let dir = path
125
+ . parent ( )
126
+ . expect ( "parent must exist here since this is under `root_dir`" )
127
+ . to_owned ( ) ;
128
+
105
129
let ( stem, ext) = match ( path. file_stem ( ) , path. extension ( ) ) {
106
130
( Some ( stem) , Some ( ext) ) => (
107
131
stem. to_str ( ) . context ( "Non UTF8 filename" ) ?,
108
132
ext. to_str ( ) . context ( "Non UTF8 filename" ) ?,
109
133
) ,
110
134
_ => continue ,
111
135
} ;
112
- // Skip directory for ia32
113
- if path. components ( ) . any ( |c| {
114
- if let std:: path:: Component :: Normal ( c) = c {
115
- if let Some ( c) = c. to_str ( ) {
116
- if c. starts_with ( "ia32" ) {
117
- return true ;
118
- }
119
- }
120
- }
121
- false
122
- } ) {
123
- continue ;
124
- }
125
136
126
- let dir = path
127
- . parent ( )
128
- . expect ( "parent must exist here since this is under `root_dir`" )
129
- . to_owned ( ) ;
130
137
if stem == "mkl" && ext == "h" {
138
+ log:: info!( "Found mkl.h: {}" , path. display( ) ) ;
131
139
include_dir = Some ( dir) ;
132
140
continue ;
133
141
}
142
+
134
143
let name = if let Some ( name) = stem. strip_prefix ( std:: env:: consts:: DLL_PREFIX ) {
135
144
name
136
145
} else {
137
146
continue ;
138
147
} ;
139
- match ( config. link , ext) {
140
- ( LinkType :: Static , STATIC_EXTENSION ) => match name {
141
- "mkl_core" => {
142
- ensure ! (
143
- library_dir. replace( dir) . is_none( ) ,
144
- "Two or more MKL found in {}" ,
145
- root_dir. display( )
146
- )
147
- }
148
- "iomp5" => {
149
- ensure ! (
150
- iomp5_dir. replace( dir) . is_none( ) ,
151
- "Two or more MKL found in {}" ,
152
- root_dir. display( )
153
- )
154
- }
155
- _ => { }
156
- } ,
157
- ( LinkType :: Dynamic , std:: env:: consts:: DLL_EXTENSION ) => match name {
158
- "mkl_core" => {
159
- ensure ! (
160
- library_dir. replace( dir) . is_none( ) ,
161
- "Two or more MKL found in {}" ,
162
- root_dir. display( )
163
- )
148
+
149
+ match name {
150
+ "mkl_core" => {
151
+ match ( config. link , ext) {
152
+ ( LinkType :: Static , STATIC_EXTENSION )
153
+ | ( LinkType :: Dynamic , std:: env:: consts:: DLL_EXTENSION ) => { }
154
+ _ => continue ,
164
155
}
165
- "iomp5" => {
166
- ensure ! (
167
- iomp5_dir. replace( dir) . is_none( ) ,
168
- "Two or more MKL found in {}" ,
169
- root_dir. display( )
170
- )
156
+ log:: info!( "Found: {}" , path. display( ) ) ;
157
+ library_dir = Some ( dir) ;
158
+ }
159
+ "iomp5" => {
160
+ // Allow both dynamic/static library by default
161
+ //
162
+ // This is due to some distribution does not provide libiomp5.a
163
+ if cfg ! ( feature = "openmp-strict-link-type" ) {
164
+ match ( config. link , ext) {
165
+ ( LinkType :: Static , STATIC_EXTENSION )
166
+ | ( LinkType :: Dynamic , std:: env:: consts:: DLL_EXTENSION ) => { }
167
+ _ => continue ,
168
+ }
171
169
}
172
- _ => { }
173
- } ,
170
+ log:: info!( "Found: {}" , path. display( ) ) ;
171
+ iomp5_dir = Some ( dir) ;
172
+ }
174
173
_ => { }
175
174
}
176
175
}
177
176
if config. parallel == Threading :: OpenMP && iomp5_dir. is_none ( ) {
177
+ if let Some ( ref lib) = library_dir {
178
+ log:: warn!( "iomp5 not found while MKL found at {}" , lib. display( ) ) ;
179
+ }
178
180
return Ok ( None ) ;
179
181
}
180
182
Ok ( match ( library_dir, include_dir) {
0 commit comments