@@ -326,22 +326,25 @@ impl fmt::Display for Error {
326
326
327
327
// There will be no status code if terminated by signal
328
328
if let Some ( _code) = output. status . code ( ) {
329
- // NixOS uses a wrapper script for pkg-config that sets the custom
329
+ // Nix uses a wrapper script for pkg-config that sets the custom
330
330
// environment variable PKG_CONFIG_PATH_FOR_TARGET
331
- let search_path =
332
- if let Ok ( path_for_target) = env:: var ( "PKG_CONFIG_PATH_FOR_TARGET" ) {
333
- Some ( path_for_target)
334
- } else if let Ok ( path) = env:: var ( "PKG_CONFIG_PATH" ) {
335
- Some ( path)
336
- } else {
337
- None
338
- } ;
331
+ let search_locations = [ "PKG_CONFIG_PATH_FOR_TARGET" , "PKG_CONFIG_PATH" ] ;
332
+
333
+ // Find a search path to use
334
+ let mut search_data = None ;
335
+ for location in search_locations {
336
+ if let Ok ( search_path) = env:: var ( location) {
337
+ search_data = Some ( ( location, search_path) ) ;
338
+ break ;
339
+ }
340
+ }
339
341
340
342
// Guess the most reasonable course of action
341
- let hint = if let Some ( search_path) = search_path {
343
+ let hint = if let Some ( ( search_location , search_path) ) = search_data {
342
344
writeln ! (
343
345
f,
344
- "PKG_CONFIG_PATH contains the following:\n {}" ,
346
+ "{} contains the following:\n {}" ,
347
+ search_location,
345
348
search_path
346
349
. split( ':' )
347
350
. map( |path| format!( " - {}" , path) )
@@ -351,8 +354,13 @@ impl fmt::Display for Error {
351
354
352
355
format ! ( "you may need to install a package such as {name}, {name}-dev or {name}-devel." , name=name)
353
356
} else {
354
- writeln ! ( f, "PKG_CONFIG_PATH environment variable is not set" ) ?;
355
- format ! ( "If you have installed the library, try adding its parent directory to your PATH." )
357
+ // Even on Nix, setting PKG_CONFIG_PATH seems to be a viable option
358
+ writeln ! ( f, "The PKG_CONFIG_PATH environment variable is not set." ) ?;
359
+
360
+ format ! (
361
+ "if you have installed the library, try setting PKG_CONFIG_PATH to the directory containing `{}.pc`." ,
362
+ name
363
+ )
356
364
} ;
357
365
358
366
// Try and nudge the user in the right direction so they don't get stuck
0 commit comments