Skip to content

Commit

Permalink
* Changed file structure for prebuilt binaries
Browse files Browse the repository at this point in the history
* Updated CHANGELOG
  • Loading branch information
pylakey committed Aug 28, 2021
1 parent e757c55 commit 6697be1
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#### Updated

* Slightly improved generator. Nullable parameters of some api functions now have Optional type

* Changed file structure for prebuilt binaries

* TDLib binaries upgraded to
latest [available version](https://github.com/tdlib/td/commit/97fccf7f27c84009460389fdd294739db510f47f)

Expand Down
3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
include README.md requirements.txt
recursive-include aiotdlib/tdlib libtdjson.1.7.6.dylib
recursive-include aiotdlib/tdlib libtdjson.so.1.7.6
recursive-include aiotdlib/tdlib *
31 changes: 23 additions & 8 deletions aiotdlib/tdjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
import pkg_resources
import ujson

TDLIB_VERSION = '1.7.6'
TDLIB_MAX_INT = 2 ** 63 - 1
log_message_callback_type = CFUNCTYPE(None, c_int, c_char_p)
LINUX_MACHINE_SYNONYMS = {
"x86_64": "amd64",
"aarch64": "arm64"
}


def _get_tdjson_lib_path() -> str:
Expand All @@ -20,15 +23,27 @@ def _get_tdjson_lib_path() -> str:
if tdjson_path is not None:
return tdjson_path

if platform.system().lower() == 'darwin':
lib_name = f"libtdjson.{TDLIB_VERSION}.dylib"
elif platform.system().lower() == 'windows':
lib_name = f"libtdjson.{TDLIB_VERSION}.dll"
uname = platform.uname()
system_name = uname.system.lower()
machine_name = uname.machine

if system_name == 'darwin':
extension = f"dylib"
elif system_name == 'linux':
extension = f"so"

if machine_name in LINUX_MACHINE_SYNONYMS.keys():
machine_name = LINUX_MACHINE_SYNONYMS[machine_name]
else:
# By default tdlib is built with this name
lib_name = f"libtdjson.so.{TDLIB_VERSION}"
raise RuntimeError('Prebuilt TDLib binary is not include for this system')

binary_path = f'tdlib/{system_name}/{machine_name}/libtdjson.{extension}'

if not pkg_resources.resource_exists('aiotdlib', binary_path):
# Binary for arm64 machines will be always provided for both Darwin and Linux
binary_path = f"tdlib/{system_name}/arm64/libtdjson.{extension}"

return pkg_resources.resource_filename('aiotdlib', f'tdlib/{lib_name}')
return pkg_resources.resource_filename('aiotdlib', binary_path)


class TDLibLogVerbosity(IntEnum):
Expand Down
2 changes: 2 additions & 0 deletions aiotdlib/tdlib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
!**/libtdjson.so
!**/libtdjson.dylib
Binary file not shown.
Binary file not shown.
Binary file added aiotdlib/tdlib/linux/arm64/libtdjson.so
Binary file not shown.
38 changes: 38 additions & 0 deletions builder/Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM debian:buster

ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true

# install build dependencies, then clean up system packages
RUN apt-get update && apt-get -y install \
make \
zlib1g-dev \
libssl-dev \
gperf \
cmake \
clang \
libc++-dev \
libc++abi-dev \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /build

code:
GIT CLONE https://github.com/pylakey/td /code

build:
FROM +code
ARG TARGETARCH

RUN CXXFLAGS="-stdlib=libc++" \
CC=/usr/bin/clang \
CXX=/usr/bin/clang++ \
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX:PATH=/tdlib \
-S /code \
-B /build

RUN cmake --build /build --target install

SAVE ARTIFACT /tdlib/lib/libtdjson.so.1.7.6 AS LOCAL ../aiotdlib/tdlib/linux/${TARGETARCH}/libtdjson.so
4 changes: 4 additions & 0 deletions builder/build_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
set -e
earthly --platform="linux/arm64" +build
earthly --platform="linux/amd64" +build
17 changes: 17 additions & 0 deletions builder/build_mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env sh
set -e
git clone https://github.com/pylakey/td
cd td
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release \
-DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl/ \
-DCMAKE_INSTALL_PREFIX:PATH=../tdlib \
-DTD_ENABLE_LTO=ON \
..
cmake --build . --target install
cd ../..
BINARY_DIR="../aiotdlib/tdlib/darwin/$(uname -m)"
mkdir -p "$BINARY_DIR"
mv td/tdlib/lib/libtdjson.1.7.6.dylib "$BINARY_DIR/libtdjson.dylib"
rm -rf td

0 comments on commit 6697be1

Please sign in to comment.