From f130f62b1ac66bc7ab3032c6f6794c95b705fcae Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Mon, 23 Jan 2017 20:17:14 -0500 Subject: [PATCH] Don't ask to link to /usr/lib directly if pkg-config fails to find SQLite. --- libsqlite3-sys/build.rs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/libsqlite3-sys/build.rs b/libsqlite3-sys/build.rs index 7d15629..15528d3 100644 --- a/libsqlite3-sys/build.rs +++ b/libsqlite3-sys/build.rs @@ -4,27 +4,24 @@ extern crate pkg_config; #[cfg(not(feature = "bundled"))] fn main() { use std::env; - use std::fs; // Allow users to specify where to find SQLite. - let lib_dir = match env::var("SQLITE3_LIB_DIR") { - Ok(dir) => dir, + match env::var("SQLITE3_LIB_DIR") { + Ok(dir) => { + println!("cargo:rustc-link-lib=sqlite3"); + println!("cargo:rustc-link-search={}", dir); + } Err(_) => { // See if pkg-config can do everything for us. - if pkg_config::find_library("sqlite3").is_ok() { - return + if !pkg_config::find_library("sqlite3").is_ok() { + // No env var set and pkg-config couldn't help; just output the link-lib + // request and hope that the library exists on the system paths. We used to + // output /usr/lib explicitly, but that can introduce other linking problems; see + // https://github.com/jgallagher/rusqlite/issues/207. + println!("cargo:rustc-link-lib=sqlite3"); } - - // Try to fall back to /usr/lib if pkg-config failed. - match fs::metadata("/usr/lib") { - Ok(ref attr) if attr.is_dir() => "/usr/lib".to_owned(), - _ => panic!("Could not find sqlite3. Try setting SQLITE3_LIB_DIR."), - } - }, + } }; - - println!("cargo:rustc-link-lib=sqlite3"); - println!("cargo:rustc-link-search={}", lib_dir); } #[cfg(feature = "bundled")]