summaryrefslogtreecommitdiffstats
path: root/build.rs
diff options
context:
space:
mode:
authorsyn <isaqtm@gmail.com>2021-01-03 11:59:24 +0300
committersyn <isaqtm@gmail.com>2021-01-03 11:59:24 +0300
commitef2b020d504a62c2c6ed234b3a93ba61b051b66e (patch)
tree4a3fdbdef741bf4527c4fd994e11290f7a85ee7a /build.rs
downloadtdlib-sys-ef2b020d504a62c2c6ed234b3a93ba61b051b66e.tar.gz
can automatically find brew's openssl
looking up /usr/local/Cellar/openssl@1.1/1.1.1x where x is any letter in 'a'..'i'
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs51
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.
+ "#
+ })
+}