Skip to content

Commit

Permalink
prebuilt-tdlib: crosscompile to Linux arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
eilvelia committed Jul 18, 2024
1 parent d3580a4 commit 36ebd80
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 22 deletions.
53 changes: 51 additions & 2 deletions .github/workflows/prebuilt-tdlib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ jobs:
with:
name: tdlib-linux-x86_64-glibc
path: ${{ env.TO_UPLOAD }}
build-linux-arm64:
name: 'Build TDLib / Linux arm64 glibc (cross)'
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: |
cd packages/prebuilt-tdlib/ci
./build-linux.sh ${{ inputs.tdlib }} aarch64-linux-gnu.2.22
- uses: actions/upload-artifact@v4
with:
name: tdlib-linux-arm64-glibc
path: ${{ env.TO_UPLOAD }}
build-macos-x86_64:
name: 'Build TDLib / macOS x86_64'
runs-on: macos-13
Expand Down Expand Up @@ -126,7 +142,10 @@ jobs:

test:
name: 'Test / ${{ matrix.v.bin }} / ${{ matrix.v.os }}'
needs: [build-linux-x86_64, build-macos, build-windows-x86_64]
needs:
- build-linux-x86_64
- build-macos
- build-windows-x86_64
runs-on: ${{ matrix.v.os }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -157,9 +176,39 @@ jobs:
env:
LIBDIR_PATH: '.'

test-linux-arm64:
name: 'Test / ${{ matrix.v.bin }} / ${{ matrix.v.os }} (docker arm64)'
needs: [build-linux-arm64]
runs-on: macos-14
strategy:
matrix:
v:
- os: macos-14
bin: tdlib-linux-arm64-glibc
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: ${{ matrix.v.bin }}
merge-multiple: true
- name: Start colima
run: |
brew install docker
colima start
- name: Run in docker
run: |
cat > test-linux-aarch64.sh <<EOF
set -ex
cd /usr/src/app
npm install
npm uninstall -D prebuilt-tdlib
LIBDIR_PATH=. npm run test:integration
EOF
docker run -v $(pwd):/usr/src/app node:20 bash /usr/src/app/test-linux-aarch64.sh
publish:
name: 'Publish to npm'
needs: [test]
needs: [test, ]
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ a library to create [Telegram][] clients or bots.
- The tdjson shared library (`libtdjson.so` on Linux, `libtdjson.dylib` on macOS, `tdjson.dll` on Windows), of TDLib version 1.8.0 or newer
- In rare cases, a C++ compiler and Python installed to build the node addon[^1]

[^1]: `tdl` is packaged with pre-built addons for Windows (x86_64), GNU/Linux (x86_64, arm64; glibc >= 2.22), and macOS (x86_64, arm64; v10.14+). If a pre-built binary is not available for your system, then the node addon will be built using node-gyp, requiring Python and a C++ toolchain (C++14 is required) to be installed (on Windows, MSVS or Build Tools). Pass `--build-from-source` to never use the pre-built binaries. arm64 binaries are not tested in the CI. Only Linux binaries are statically linked against libstdc++.
[^1]: `tdl` is packaged with pre-built addons for Windows (x86_64), GNU/Linux (x86_64, arm64; glibc >= 2.22), and macOS (x86_64, arm64; v10.14+). If a pre-built binary is not available for your system, then the node addon will be built using node-gyp, requiring Python and a C++ toolchain (C++14 is required) to be installed (on Windows, MSVS or Build Tools). Pass `--build-from-source` to never use the pre-built binaries. arm64 binaries are not tested in the CI. Linux binaries are statically linked against libstdc++.

<a name="installation"></a>
## Installation
Expand Down
10 changes: 6 additions & 4 deletions packages/prebuilt-tdlib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ using [npm publish --provenance][provenance].
[prebuilt-tdlib.yml]: ../../.github/workflows/prebuilt-tdlib.yml
[provenance]: https://docs.npmjs.com/generating-provenance-statements

The shared libraries are statically linked against OpenSSL and zlib, for one, to
prevent compatibility issues in Node.js.

Supported systems:
- Linux x86_64 (requires glibc >= 2.22)
- Linux x86_64, arm64 (requires glibc >= 2.22)
- macOS x86_64, arm64 (universal, requires macOS >= 10.12)
- Windows x86_64

Expand All @@ -37,6 +34,10 @@ The TDLib version is important: there is no backward compatibility and the
interface you use may significantly change after an update. It is, though,
recommended to use the latest TDLib version.

The shared libraries are statically linked against OpenSSL and zlib, for one, to
prevent compatibility issues in Node.js. libstdc++ is also linked statically
(on Linux).

## Usage

The `prebuilt-tdlib` package exports a single function `getTdjson`, which
Expand Down Expand Up @@ -142,6 +143,7 @@ The building process is significantly changed in this update.
crosscompiled anymore).
- On Linux, TDLib is now built using zig. The minimal glibc version is 2.22
instead of 2.17.
- Added a crosscompiled prebuild for Linux arm64.

### 2024-05-08

Expand Down
2 changes: 1 addition & 1 deletion packages/prebuilt-tdlib/ci/build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cp -L ./result/lib/libtdjson.so to-upload/libtdjson.so
cd to-upload

# Info
ldd libtdjson.so
ldd libtdjson.so || true

if [ -z "$GITHUB_ENV" ]; then
echo "Note: GITHUB_ENV not found"
Expand Down
17 changes: 12 additions & 5 deletions packages/prebuilt-tdlib/ci/tdlib-linux.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{ pkgs ? import <nixpkgs> {}, target, rev }:
{ target, rev }:
let
pkgs = if builtins.substring 0 7 target == "aarch64"
then import <nixpkgs> { crossSystem.config = "aarch64-unknown-linux-gnu"; }
else import <nixpkgs> {};
inherit (pkgs) lib stdenv;
zig-toolchain = import ./zig-toolchain.nix { inherit pkgs target; };
zig-toolchain = import ./zig-toolchain.nix { inherit target; pkgs = pkgs.buildPackages.buildPackages; };
zlib = pkgs.callPackage ./zlib-zig.nix { inherit zig-toolchain; };
openssl = pkgs.callPackage ./openssl-zig.nix { inherit zig-toolchain; };
in
Expand All @@ -13,12 +16,16 @@ stdenv.mkDerivation {
src = builtins.fetchTarball "https://github.com/tdlib/td/archive/${rev}.tar.gz";

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

preConfigure = ''
export CC=${pkgs.buildPackages.stdenv.cc}/bin/cc
export CXX=${pkgs.buildPackages.stdenv.cc}/bin/c++
mkdir native-build && cd native-build
cmake ..
cmake --build . --target prepare_cross_compiling
cmake -DOPENSSL_ROOT_DIR=${pkgs.buildPackages.openssl.dev} \
-DZLIB_ROOT=${pkgs.buildPackages.zlib.dev} \
..
cmake --build . --target prepare_cross_compiling -j $NIX_BUILD_CORES
cd ..
'' + zig-toolchain.env;

Expand Down
9 changes: 0 additions & 9 deletions packages/prebuilt-tdlib/ci/zlib-zig.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,4 @@
(zlib.override { static = true; shared = false; }).overrideAttrs (final: prev: {
preConfigure = prev.preConfigure + zig-toolchain.env;
doCheck = false;
# preCheck = ''
# ls
# echo ---
# ldd ./minigzip
# ./minigzip
# echo START
# make check
# echo FINISH
# '';
})
11 changes: 11 additions & 0 deletions packages/prebuilt-tdlib/prebuild-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ const prebuilds/*: PrebuildInfo[] */ = [
cpu: ['x64']
},
libc: 'glibc'
},
{
packageName: 'linux-arm64-glibc',
prebuildDir: 'tdlib-linux-arm64-glibc',
libfile: SHARED_LINUX,
descr: 'Linux arm64 (glibc)',
requirements: {
os: ['linux'],
cpu: ['arm64']
},
libc: 'glibc'
}
]

Expand Down

0 comments on commit 36ebd80

Please sign in to comment.