diff options
Diffstat (limited to 'build.rs')
-rw-r--r-- | build.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..619ad4c --- /dev/null +++ b/build.rs @@ -0,0 +1,51 @@ +use std::path::PathBuf; + +fn main() { + //let crate_root: PathBuf = env::var("CARGO_MANIFEST_DIR").unwrap().into(); + /*let tdlib_path: PathBuf = { + env::var("TDLIB_LIBRARY_PATH") + .map_or_else(|_err| crate_root.join("td/build"), PathBuf::from) + };*/ + + if cfg!(not(feature = "tdlib-provided")) { + build_tdlib(); + } +} + +fn build_tdlib() { + let mut config = cmake::Config::new("td"); + config.very_verbose(true); + + if cfg!(not(feature = "openssl-provided")) { + let openssl = guess_openssl_location(); + config.define("OPENSSL_ROOT_DIR", openssl); + } + + let dst = config.build(); + println!("cargo:rustc-link-search={}", dst.display()); // tdlib_path.to_string_lossy()); +} + +fn guess_openssl_location() -> PathBuf { + let mut openssl: Option<PathBuf> = std::env::var("OPENSSL_ROOT_DIR") + .map(std::convert::Into::into) + .ok(); + + if cfg!(target_os = "macos") && openssl.is_none() { + let ssl_very_minor_version = "abcdefghi"; + for ver in ssl_very_minor_version.chars().rev() { + let maybe_path = PathBuf::from(format!("/usr/local/Cellar/openssl@1.1/1.1.1{}", ver)); + if maybe_path.is_dir() { + openssl = Some(maybe_path); + break; + } + } + } + + openssl.expect(indoc::indoc! {r#" + Could not find openssl. + You must either use feature \"openssl-provided\" + or provide "OPENSSL_ROOT_DIR" env variable, so tdlib-sys can build + TDLib from sources. + "# + }) +} |