Merge pull request #444 from thomcc/allow-build-staticlib

Add support for forcing cargo:rustc-link-lib to link as native
This commit is contained in:
gwenn 2018-12-15 09:56:36 +01:00 committed by GitHub
commit edc5a6a5a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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
} }
} }