Add support for forcing cargo:rustc-link-lib to link as native

This commit is contained in:
Thom Chiovoloni 2018-12-14 17:12:31 -08:00
parent 372291c65e
commit 4fd00a6311

View File

@ -108,18 +108,27 @@ mod build {
bindings::write_to_out_dir(header, out_path); bindings::write_to_out_dir(header, out_path);
} }
fn find_link_mode() -> &'static str {
// If the user specifies SQLITE_STATIC (or SQLCIPHER_STATIC), do static
// linking, unless it's explicitly set to 0.
match &env::var(format!("{}_STATIC", env_prefix())) {
Ok(v) if v != "0" => "static",
_ => "dylib",
}
}
// Prints the necessary cargo link commands and returns the path to the header. // Prints the necessary cargo link commands and returns the path to the header.
fn find_sqlite() -> HeaderLocation { fn find_sqlite() -> HeaderLocation {
let link_lib = link_lib(); let link_lib = link_lib();
println!("cargo:rerun-if-env-changed={}_INCLUDE_DIR", env_prefix()); println!("cargo:rerun-if-env-changed={}_INCLUDE_DIR", env_prefix());
println!("cargo:rerun-if-env-changed={}_LIB_DIR", env_prefix()); println!("cargo:rerun-if-env-changed={}_LIB_DIR", env_prefix());
println!("cargo:rerun-if-env-changed={}_STATIC", env_prefix());
if cfg!(target_os = "windows") { if cfg!(target_os = "windows") {
println!("cargo:rerun-if-env-changed=PATH"); println!("cargo:rerun-if-env-changed=PATH");
} }
// Allow users to specify where to find SQLite. // Allow users to specify where to find SQLite.
if let Ok(dir) = env::var(format!("{}_LIB_DIR", env_prefix())) { if let Ok(dir) = env::var(format!("{}_LIB_DIR", env_prefix())) {
println!("cargo:rustc-link-lib={}", link_lib); println!("cargo:rustc-link-lib={}={}", find_link_mode(), link_lib);
println!("cargo:rustc-link-search={}", dir); println!("cargo:rustc-link-search={}", dir);
return HeaderLocation::FromEnvironment; return HeaderLocation::FromEnvironment;
} }
@ -146,7 +155,7 @@ mod build {
// request and hope that the library exists on the system paths. We used to // 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; // output /usr/lib explicitly, but that can introduce other linking problems;
// see https://github.com/jgallagher/rusqlite/issues/207. // see https://github.com/jgallagher/rusqlite/issues/207.
println!("cargo:rustc-link-lib={}", link_lib); println!("cargo:rustc-link-lib={}={}", find_link_mode(), link_lib);
HeaderLocation::Wrapper HeaderLocation::Wrapper
} }
} }