@@ -122,11 +122,20 @@ pub enum Error {
122
122
/// Contains the command and the cause.
123
123
Command { command : String , cause : io:: Error } ,
124
124
125
- /// `pkg-config` did not exit sucessfully.
125
+ /// `pkg-config` did not exit sucessfully after probing a library .
126
126
///
127
127
/// Contains the command and output.
128
128
Failure { command : String , output : Output } ,
129
129
130
+ /// `pkg-config` did not exit sucessfully on the first attempt to probe a library.
131
+ ///
132
+ /// Contains the command and output.
133
+ ProbeFailure {
134
+ name : String ,
135
+ command : String ,
136
+ output : Output ,
137
+ } ,
138
+
130
139
#[ doc( hidden) ]
131
140
// please don't match on this, we're likely to add more variants over time
132
141
__Nonexhaustive,
@@ -186,30 +195,46 @@ impl fmt::Display for Error {
186
195
_ => write ! ( f, "Failed to run command `{}`, because: {}" , command, cause) ,
187
196
}
188
197
}
198
+ Error :: ProbeFailure {
199
+ ref name,
200
+ ref command,
201
+ ref output,
202
+ } => {
203
+ write ! (
204
+ f,
205
+ "`{}` did not exit successfully: {}\n error: could not find system library '{}' required by the '{}' crate\n " ,
206
+ command, output. status, name, env:: var( "CARGO_PKG_NAME" ) . unwrap_or_default( ) ,
207
+ ) ?;
208
+ format_output ( output, f)
209
+ }
189
210
Error :: Failure {
190
211
ref command,
191
212
ref output,
192
213
} => {
193
- let stdout = str:: from_utf8 ( & output. stdout ) . unwrap ( ) ;
194
- let stderr = str:: from_utf8 ( & output. stderr ) . unwrap ( ) ;
195
214
write ! (
196
215
f,
197
216
"`{}` did not exit successfully: {}" ,
198
217
command, output. status
199
218
) ?;
200
- if !stdout. is_empty ( ) {
201
- write ! ( f, "\n --- stdout\n {}" , stdout) ?;
202
- }
203
- if !stderr. is_empty ( ) {
204
- write ! ( f, "\n --- stderr\n {}" , stderr) ?;
205
- }
206
- Ok ( ( ) )
219
+ format_output ( output, f)
207
220
}
208
221
Error :: __Nonexhaustive => panic ! ( ) ,
209
222
}
210
223
}
211
224
}
212
225
226
+ fn format_output ( output : & Output , f : & mut fmt:: Formatter ) -> fmt:: Result {
227
+ let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
228
+ if !stdout. is_empty ( ) {
229
+ write ! ( f, "\n --- stdout\n {}" , stdout) ?;
230
+ }
231
+ let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
232
+ if !stderr. is_empty ( ) {
233
+ write ! ( f, "\n --- stderr\n {}" , stderr) ?;
234
+ }
235
+ Ok ( ( ) )
236
+ }
237
+
213
238
/// Deprecated in favor of the probe_library function
214
239
#[ doc( hidden) ]
215
240
pub fn find_library ( name : & str ) -> Result < Library , String > {
@@ -353,7 +378,14 @@ impl Config {
353
378
354
379
let mut library = Library :: new ( ) ;
355
380
356
- let output = run ( self . command ( name, & [ "--libs" , "--cflags" ] ) ) ?;
381
+ let output = run ( self . command ( name, & [ "--libs" , "--cflags" ] ) ) . map_err ( |e| match e {
382
+ Error :: Failure { command, output } => Error :: ProbeFailure {
383
+ name : name. to_owned ( ) ,
384
+ command,
385
+ output,
386
+ } ,
387
+ other => other,
388
+ } ) ?;
357
389
library. parse_libs_cflags ( name, & output, self ) ;
358
390
359
391
let output = run ( self . command ( name, & [ "--modversion" ] ) ) ?;
0 commit comments