Skip to content

Commit

Permalink
prebuilt-tdlib workflow update
Browse files Browse the repository at this point in the history
  • Loading branch information
eilvelia committed Jul 8, 2024
1 parent c7008b2 commit fe288b7
Show file tree
Hide file tree
Showing 4 changed files with 272 additions and 108 deletions.
203 changes: 95 additions & 108 deletions .github/workflows/prebuilt-tdlib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,139 +20,127 @@ on:
# NOTE: The ZLIB_USE_STATIC_LIBS option requires CMake >= 3.24
jobs:
build-linux-x64:
name: Build TDLib (GNU/Linux x86_64)
runs-on: ubuntu-latest
name: Build TDLib (Linux x86_64 glibc)
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Build TDLib
run: |
set -ex
cd packages/prebuilt-tdlib
mkdir to-upload
nix-build build-scripts/tdlib.nix --arg rev "${{ input.tdlib }}" -vv
tree result/
cp -L ./result/lib/libtdjson.so to-upload/libtdjson.so
ldd to-upload/libtdjson.so
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
if: always()
with:
limit-access-to-actor: true
- uses: actions/upload-artifact@v4
with:
name: tdlib-linux-x64
path: to-upload
build-macos-x64:
name: Build TDLib (macOS x86_64)
runs-on: macos-13
steps:
- uses: actions/checkout@v4
with:
repository: 'tdlib/td'
ref: ${{ inputs.tdlib }}
- name: Create a build script
- name: Install dependencies (homebrew)
run: HOMEBREW_NO_INSTALL_CLEANUP=1 brew install gperf zlib openssl
- name: Build TDLib
run: |
cat > prebuilt-tdlib-docker.sh <<EOF
set -e
source /hbb_shlib/activate
set -x
yum install -y gperf
cd /td
mkdir -p build && cd build
set -ex
cmake --version
# Currently, cmake in this image should be 3.22.2
cmake \
mkdir -p to-upload && mkdir -p build && cd build
MACOSX_DEPLOYMENT_TARGET=10.14 cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_OSX_ARCHITECTURES='x86_64' \
-DOPENSSL_USE_STATIC_LIBS=TRUE \
-DZLIB_LIBRARY=/hbb_shlib/lib/libz.a \
-DZLIB_INCLUDE_DIR=/hbb_shlib/include \
-DZLIB_USE_STATIC_LIBS=TRUE \
-DZLIB_LIBRARY=/usr/local/opt/zlib/lib/libz.a \
-DZLIB_INCLUDE_DIR=/usr/local/opt/zlib/include \
-DOPENSSL_ROOT_DIR=/usr/local/opt/openssl \
..
cmake --build . --target tdjson -- -j 2
strip libtdjson.so
cmake --build . --target tdjson -- -j 4
cd ..
cp -L build/libtdjson.so to-upload/libtdjson.so
cp -L build/libtdjson.dylib to-upload/libtdjson.dylib
cd to-upload
ldd libtdjson.so
touch info.txt
gcc --version | grep -i gcc >> info.txt
ldd --version | grep ldd >> info.txt
openssl version >> info.txt
sed -n 's/#define ZLIB_VERSION "\([^"]*\)"/zlib version: \1/p' /hbb_shlib/include/zlib.h >> info.txt
EOF
- name: Build in docker
run: |
mkdir to-upload
docker run -v $(pwd):/td ghcr.io/phusion/holy-build-box/hbb-64 \
bash /td/prebuilt-tdlib-docker.sh
- name: Info
working-directory: to-upload
run: |
cat info.txt
echo "-----"
du -hs libtdjson.so
ldd libtdjson.so
install_name_tool -id @rpath/libtdjson.dylib libtdjson.dylib
echo "clang:" >> info.txt && clang --version >> info.txt
echo "openssl:" >> info.txt && /usr/local/opt/openssl/bin/openssl version >> info.txt
file libtdjson.dylib
otool -L libtdjson.dylib
- uses: actions/upload-artifact@v4
with:
name: tdlib-linux-x64
name: temp-macos-x64
path: to-upload
build-macos:
name: Build TDLib (macOS universal)
runs-on: macos-12
env:
openssl_dir: /usr/local/opt/custom_openssl
openssl_tag: '1.1.2100' # OpenSSL 1.1.1u
zlib_ver: '1.2.13'
zlib_dir: /usr/local/opt/custom_zlib
build-macos-arm64:
name: Build TDLib (macOS arm64)
runs-on: macos-14
steps:
- uses: actions/checkout@v4
with:
repository: 'tdlib/td'
ref: ${{ inputs.tdlib }}
- name: Install gperf via homebrew
run: HOMEBREW_NO_INSTALL_CLEANUP=1 brew install gperf
- name: CMake version
run: cmake --version
# https://github.com/up9cloud/ios-libtdjson/blob/d4426dca16933b6178acb030955de92f040b7574/build.sh
- name: Download pre-built OpenSSL
run: |
# around 80 mb
curl -SL https://github.com/krzyzanowskim/OpenSSL/archive/refs/tags/${openssl_tag}.tar.gz -o OpenSSL.tar.gz
tar xzf OpenSSL.tar.gz
# As for now, MACOSX_DEPLOYMENT_TARGET in these pre-built openssl binaries should be 10.13
mv OpenSSL-${openssl_tag}/macosx ${openssl_dir}
- name: Download and build zlib
run: |
set -x
curl -SL https://github.com/madler/zlib/releases/download/v${zlib_ver}/zlib-${zlib_ver}.tar.gz -o zlib.tar.gz
tar xzf zlib.tar.gz
cd zlib-${zlib_ver}
MACOSX_DEPLOYMENT_TARGET=10.14 CFLAGS="-O2 -mmacosx-version-min=10.14 -arch x86_64" \
./configure --static --prefix=${zlib_dir}
MACOSX_DEPLOYMENT_TARGET=10.14 make
make install && rm ${zlib_dir}/lib/libz.a
cp libz.a libz-x86_64.a
make clean
MACOSX_DEPLOYMENT_TARGET=11.0 CFLAGS="-O2 -mmacosx-version-min=11.0 -arch arm64" \
./configure --static
MACOSX_DEPLOYMENT_TARGET=11.0 make
mv libz.a libz-arm64.a
lipo -create libz-x86_64.a libz-arm64.a -output libz.a
cp libz.a ${zlib_dir}/lib/libz.a
- name: Install dependencies (homebrew)
run: HOMEBREW_NO_INSTALL_CLEANUP=1 brew install gperf zlib openssl
- name: Build TDLib
run: |
mkdir to-upload
mkdir -p build && cd build
MACOSX_DEPLOYMENT_TARGET=10.14 cmake \
set -ex
cmake --version
mkdir -p to-upload && mkdir -p build && cd build
MACOSX_DEPLOYMENT_TARGET=11.0 cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_OSX_ARCHITECTURES='x86_64;arm64' \
-DOPENSSL_USE_STATIC_LIBS=TRUE -DZLIB_USE_STATIC_LIBS=TRUE \
-DOPENSSL_FOUND=1 \
-DOPENSSL_CRYPTO_LIBRARY=${openssl_dir}/lib/libcrypto.a \
-DOPENSSL_SSL_LIBRARY=${openssl_dir}/lib/libssl.a \
-DOPENSSL_LIBRARIES="${openssl_dir}/lib/libcrypto.a;${openssl_dir}/lib/libssl.a" \
-DOPENSSL_INCLUDE_DIR=${openssl_dir}/include \
-DZLIB_INCLUDE_DIR=${zlib_dir}/include \
-DZLIB_LIBRARY=${zlib_dir}/lib/libz.a \
-DCMAKE_OSX_ARCHITECTURES='arm64' \
-DOPENSSL_USE_STATIC_LIBS=TRUE \
-DZLIB_USE_STATIC_LIBS=TRUE \
-DZLIB_LIBRARY=/opt/homebrew/zlib/lib/libz.a \
-DZLIB_INCLUDE_DIR=/opt/homebrew/zlib/include \
-DOPENSSL_ROOT_DIR=/opt/homebrew/openssl \
..
cmake --build . --target tdjson -- -j 3
cmake --build . --target tdjson -- -j 2
cd ..
cp -L build/libtdjson.dylib to-upload/libtdjson.dylib
install_name_tool -id @rpath/libtdjson.dylib to-upload/libtdjson.dylib
- name: Info
working-directory: to-upload
run: |
touch info.txt
grep OPENSSL_VERSION_TEXT ${openssl_dir}/include/openssl/opensslv.h | sed 's/.*"\([^"]*\)"/\1/' >> info.txt
echo "zlib version: ${zlib_ver}" >> info.txt
otool -L libtdjson.dylib >> info.txt
cat info.txt
echo "-----"
uname -a
cd to-upload
install_name_tool -id @rpath/libtdjson.dylib libtdjson.dylib
echo "clang:" >> info.txt && clang --version >> info.txt
echo "openssl:" >> info.txt && /opt/homebrew/openssl/bin/openssl version >> info.txt
file libtdjson.dylib
du -hs libtdjson.dylib
otool -arch x86_64 -l libtdjson.dylib
echo "---"
otool -arch arm64 -l libtdjson.dylib
otool -L libtdjson.dylib
- uses: actions/upload-artifact@v4
with:
name: tdlib-macos
name: temp-macos-arm64
path: to-upload
build-macos:
name: Create universal macOS shared library
needs: [build-macos-x64, build-macos-arm64]
runs-on: macos-13
steps:
- uses: actions/download-artifact@v4
with:
name: temp-macos-*
merge-multiple: true
- name: Combine shared libraries
run: |
mkdir -p to-upload
lipo temp-macos-x64/libtdjson.dylib temp-macos-arm64/libtdjson.dylib \
-output to-upload/libtdjson.dylib -create
cd to-upload
echo "--x86_64--" >> info.txt
cat ../temp-macos-x64/libtdjson.dylib >> info.txt
echo "--arm64--" >> info.txt
cat ../temp-macos-arm64/libtdjson.dylib >> info.txt
- uses: actions/upload-artifact@v4
with:
name: build-macos
path: to-upload
build-windows-x64:
name: Build TDLib (Windows x86_64)
Expand Down Expand Up @@ -182,12 +170,10 @@ jobs:
-DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake `
-DVCPKG_TARGET_TRIPLET=x64-windows-static `
-DOPENSSL_USE_STATIC_LIBS=TRUE -DZLIB_USE_STATIC_LIBS=TRUE ..
cmake --build . --target tdjson --config Release --parallel 2
cmake --build . --target tdjson --config Release --parallel 4
cd ..
cp build\Release\tdjson.dll to-upload\tdjson.dll
- name: Info
# It should be possible to print the dependencies using dumpbin.exe
run: |
# It should be possible to print the dependencies using dumpbin.exe
vcpkg list | Select-String openssl,zlib > to-upload\info.txt
cat to-upload\info.txt
- uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -245,6 +231,7 @@ jobs:
pattern: tdlib-*
path: packages/prebuilt-tdlib/prebuilds
- run: tree packages/prebuilt-tdlib
- run: du -hsc packages/prebuilt-tdlib/prebuilds/*
- run: npm run test:integration
env:
PREBUILT_PATH: packages/prebuilt-tdlib
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish-tdl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
node-version: lts/*
cache: npm
- uses: goto-bus-stop/setup-zig@v2
with:
version: '0.13.0'
if: runner.os == 'Linux'
- name: Install dependencies
run: npm install
Expand Down
44 changes: 44 additions & 0 deletions packages/prebuilt-tdlib/build-scripts/tdlib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Based on https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/tdlib/default.nix
{ pkgs ? import <nixpkgs> {}, lib ? pkgs.lib, rev }:
let
zig = import ./zig-stdenv.nix {
inherit pkgs;
target = "x86_64-unknown-linux.glibc.2.22";
};
stdenv = zig.stdenv;
in
stdenv.mkDerivation {
pname = "tdlib";

src = fetchFromGitHub {
owner = "tdlib";
repo = "td";
inherit rev;
};

buildInputs = with zig.pkgs; [ openssl zlib ];
nativeBuildInputs = with pkgs; [ cmake gperf ];

cmakeFlags = [
"DCMAKE_BUILD_TYPE=Release"
"DOPENSSL_USE_STATIC_LIBS=TRUE"
"DZLIB_USE_STATIC_LIBS=TRUE"
];

buildPhase = ''
echo "Cores:" $NIX_BUILD_CORES
cmake --build --target tdjson -j$NIX_BUILD_CORES
'';

# https://github.com/tdlib/td/issues/1974
postPatch = ''
substituteInPlace CMake/GeneratePkgConfig.cmake \
--replace 'function(generate_pkgconfig' \
'include(GNUInstallDirs)
function(generate_pkgconfig' \
--replace '\$'{prefix}/'$'{CMAKE_INSTALL_LIBDIR} '$'{CMAKE_INSTALL_FULL_LIBDIR} \
--replace '\$'{prefix}/'$'{CMAKE_INSTALL_INCLUDEDIR} '$'{CMAKE_INSTALL_FULL_INCLUDEDIR}
'' + lib.optionalString (stdenv.isDarwin && stdenv.isAarch64) ''
sed -i "/vptr/d" test/CMakeLists.txt
'';
}
Loading

0 comments on commit fe288b7

Please sign in to comment.