From 7fbe1172e2e71c7f993bf70d4756679e67ac1155 Mon Sep 17 00:00:00 2001 From: John Gallagher Date: Tue, 1 Dec 2015 11:33:48 -0500 Subject: [PATCH] Make libsqlite3-sys's build script slightly more intelligent. * If SQLITE3_LIB_DIR is present in the environment, we use that. * If SQLITE3_LIB_DIR is not present, we try to use pkg-config. * If SQLITE3_LIB_DIR is not present and pkg-config fails, we fall back to /usr/lib (if it exists). --- CONTRIBUTORS.md | 1 + Changelog.md | 2 ++ libsqlite3-sys/build.rs | 23 ++++++++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index eca404b..aa0ffeb 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -9,3 +9,4 @@ rusqlite contributors (sorted alphabetically) * [Patrick Fernie](https://github.com/pfernie) * [Steve Klabnik](https://github.com/steveklabnik) * [krdln](https://github.com/krdln) +* [Andrew Straw](https://github.com/astraw) diff --git a/Changelog.md b/Changelog.md index 0af134a..4b341b4 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,8 @@ * Slight change to the closure types passed to `query_map` and `query_and_then`: * Remove the `'static` requirement on the closure's output type. * Give the closure a `&SqliteRow` instead of a `SqliteRow`. +* When building, the environment variable `SQLITE3_LIB_DIR` now takes precedence over pkg-config. +* If `pkg-config` is not available, we will try to find `libsqlite3` in `/usr/lib`. # Version 0.4.0 (2015-11-03) diff --git a/libsqlite3-sys/build.rs b/libsqlite3-sys/build.rs index c5e1e47..a1cdad4 100644 --- a/libsqlite3-sys/build.rs +++ b/libsqlite3-sys/build.rs @@ -1,5 +1,26 @@ extern crate pkg_config; +use std::env; +use std::fs; + fn main() { - pkg_config::find_library("sqlite3").unwrap(); + // Allow users to specify where to find SQLite. + let lib_dir = match env::var("SQLITE3_LIB_DIR") { + Ok(dir) => dir, + Err(_) => { + // See if pkg-config can do everything for us. + if pkg_config::find_library("sqlite3").is_ok() { + return + } + + // 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); }