use std::path::PathBuf; fn main() { 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={}/lib", dst.display()); } fn guess_openssl_location() -> PathBuf { let mut openssl: Option = 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 = 'a'..'z'; for ver in ssl_very_minor_version.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. "# }) }