summaryrefslogtreecommitdiffstats
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
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'
-rw-r--r--.gitignore2
-rw-r--r--.gitmodules3
-rw-r--r--Cargo.toml14
-rw-r--r--build.rs51
-rw-r--r--src/lib.rs20
m---------td0
6 files changed, 90 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..96ef6c0
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/target
+Cargo.lock
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..01ad750
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "td"]
+ path = td
+ url = git@github.com:tdlib/td.git
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..378e1af
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,14 @@
+[package]
+name = "tdlib-sys"
+version = "1.7.0"
+authors = ["syn <isaqtm@gmail.com>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+libc = "0.2"
+
+[build-dependencies]
+cmake = "0.1"
+indoc = "1.0" \ No newline at end of file
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.
+ "#
+ })
+}
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..8bdb227
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,20 @@
+use libc::{c_char, c_double, c_int, c_longlong};
+
+// https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs
+#[repr(C)]
+pub struct TdLibRawPtr {
+ _private: [u8; 0],
+}
+
+#[link(name = "tdjson")]
+extern "C" {
+ pub fn td_json_client_create() -> *mut TdLibRawPtr;
+ pub fn td_json_client_send(client: *mut TdLibRawPtr, request: *const c_char);
+ pub fn td_json_client_receive(client: *mut TdLibRawPtr, timeout: c_double) -> *mut c_char;
+ pub fn td_json_client_execute(client: *mut TdLibRawPtr, request: *const c_char) -> *mut c_char;
+ pub fn td_json_client_destroy(client: *mut TdLibRawPtr);
+
+ pub fn td_set_log_verbosity_level(level: c_int);
+ pub fn td_set_log_file_path(path: *const c_char) -> c_int;
+ pub fn td_set_log_max_file_size(size: c_longlong);
+}
diff --git a/td b/td
new file mode 160000
+Subproject 82f0386e73b7128a8aafec5bfa7dd825fe94ac3