@@ -296,11 +296,18 @@ mod build_linked {
296
296
// Try to use pkg-config to determine link commands
297
297
let pkgconfig_path = Path :: new ( & dir) . join ( "pkgconfig" ) ;
298
298
env:: set_var ( "PKG_CONFIG_PATH" , pkgconfig_path) ;
299
- if pkg_config:: Config :: new ( ) . probe ( link_lib) . is_err ( ) {
299
+
300
+ #[ cfg( feature = "pkg-config" ) ]
301
+ let lib_found = pkg_config:: Config :: new ( ) . probe ( link_lib) . is_ok ( ) ;
302
+ #[ cfg( not( feature = "pkg-config" ) ) ]
303
+ let lib_found = false ;
304
+
305
+ if !lib_found {
300
306
// Otherwise just emit the bare minimum link commands.
301
307
println ! ( "cargo:rustc-link-lib={}={}" , find_link_mode( ) , link_lib) ;
302
308
println ! ( "cargo:rustc-link-search={dir}" ) ;
303
309
}
310
+
304
311
return HeaderLocation :: FromEnvironment ;
305
312
}
306
313
@@ -309,39 +316,50 @@ mod build_linked {
309
316
}
310
317
311
318
// See if pkg-config can do everything for us.
312
- match pkg_config:: Config :: new ( ) . print_system_libs ( false ) . probe ( link_lib) {
313
- Ok ( mut lib) => {
314
- if let Some ( header) = lib. include_paths . pop ( ) {
315
- HeaderLocation :: FromPath ( header. to_string_lossy ( ) . into ( ) )
316
- } else {
319
+ #[ cfg( feature = "pkg-config" ) ]
320
+ {
321
+ match pkg_config:: Config :: new ( ) . print_system_libs ( false ) . probe ( link_lib) {
322
+ Ok ( mut lib) => {
323
+ if let Some ( header) = lib. include_paths . pop ( ) {
324
+ HeaderLocation :: FromPath ( header. to_string_lossy ( ) . into ( ) )
325
+ } else {
326
+ HeaderLocation :: Wrapper
327
+ }
328
+ }
329
+ Err ( _) => {
330
+ // No env var set and pkg-config couldn't help; just output the link-lib
331
+ // request and hope that the library exists on the system paths. We used to
332
+ // output /usr/lib explicitly, but that can introduce other linking problems;
333
+ // see https://github.com/rusqlite/rusqlite/issues/207.
334
+ if !cfg ! ( feature = "loadable-extension" ) {
335
+ println ! ( "cargo:rustc-link-lib={}={}" , find_link_mode( ) , link_lib) ;
336
+ }
317
337
HeaderLocation :: Wrapper
318
338
}
319
339
}
320
- Err ( _) => {
321
- // No env var set and pkg-config couldn't help; just output the link-lib
322
- // request and hope that the library exists on the system paths. We used to
323
- // output /usr/lib explicitly, but that can introduce other linking problems;
324
- // see https://github.com/rusqlite/rusqlite/issues/207.
325
- if !cfg ! ( feature = "loadable-extension" ) {
326
- println ! ( "cargo:rustc-link-lib={}={}" , find_link_mode( ) , link_lib) ;
327
- }
328
- HeaderLocation :: Wrapper
340
+ }
341
+ #[ cfg( not( feature = "pkg-config" ) ) ]
342
+ {
343
+ // No pkg-config available; just output the link-lib request and hope
344
+ // that the library exists on the system paths.
345
+ if !cfg ! ( feature = "loadable-extension" ) {
346
+ println ! ( "cargo:rustc-link-lib={}={}" , find_link_mode( ) , link_lib) ;
329
347
}
348
+ HeaderLocation :: Wrapper
330
349
}
331
350
}
332
351
333
352
fn try_vcpkg ( ) -> Option < HeaderLocation > {
334
- if cfg ! ( feature = "vcpkg" ) && is_compiler ( "msvc" ) {
353
+ #[ cfg( feature = "vcpkg" ) ]
354
+ if is_compiler ( "msvc" ) {
335
355
// See if vcpkg can find it.
336
356
if let Ok ( mut lib) = vcpkg:: Config :: new ( ) . probe ( lib_name ( ) ) {
337
357
if let Some ( header) = lib. include_paths . pop ( ) {
338
358
return Some ( HeaderLocation :: FromPath ( header. to_string_lossy ( ) . into ( ) ) ) ;
339
359
}
340
360
}
341
- None
342
- } else {
343
- None
344
361
}
362
+ None
345
363
}
346
364
}
347
365
@@ -485,12 +503,11 @@ mod bindings {
485
503
. write ( Box :: new ( & mut output) )
486
504
. expect ( "could not write output of bindgen" ) ;
487
505
506
+ #[ allow( unused_mut) ]
488
507
let mut output = String :: from_utf8 ( output) . expect ( "bindgen output was not UTF-8?!" ) ;
489
508
490
509
#[ cfg( feature = "loadable-extension" ) ]
491
- {
492
- generate_functions ( & mut output) ;
493
- }
510
+ generate_functions ( & mut output) ;
494
511
495
512
let mut file = OpenOptions :: new ( )
496
513
. write ( true )
0 commit comments