diff --git a/.github/workflows/prebuilt-tdlib.yml b/.github/workflows/prebuilt-tdlib.yml index cd870fc..98eb47e 100644 --- a/.github/workflows/prebuilt-tdlib.yml +++ b/.github/workflows/prebuilt-tdlib.yml @@ -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 @@ -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 @@ -157,9 +176,38 @@ jobs: env: LIBDIR_PATH: '.' + test-linux-arm64: + name: 'Test / ${{ matrix.v.bin }} / ${{ matrix.v.os }} (docker arm64)' + needs: [build-linux-arm64] + runs-on: ${{ matrix.v.os }} + strategy: + matrix: + v: + - os: ubuntu-latest + bin: tdlib-linux-arm64-glibc + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: ${{ matrix.v.bin }} + merge-multiple: true + - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + - name: Run in docker + run: | + cat > test-linux-aarch64.sh <= 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++. ## Installation @@ -49,11 +49,12 @@ The tdjson shared library should be present in the system search paths Instead of building TDLib from source, you can possibly install pre-built TDLib libraries distributed through the `prebuilt-tdlib` npm package. An example of using libraries from `prebuilt-tdlib` is present in the section below. The -supported systems are x86_64 GNU/Linux, x86_64 & arm64 macOS, and x86_64 -Windows. To install `prebuilt-tdlib` for a specific TDLib version, for example -v1.8.30, run `npm install prebuilt-tdlib@td-1.8.30`. The available versions of -`prebuilt-tdlib` can be found by running `npm info prebuilt-tdlib dist-tags`. -See the README of [prebuilt-tdlib][] for additional information. +supported systems are x86_64 & arm64 GNU/Linux, x86_64 & arm64 macOS, and +x86_64s Windows. To install `prebuilt-tdlib` for a specific TDLib version +instead of latest, for example v1.8.30, run `npm i prebuilt-tdlib@td-1.8.30`. +The available versions of `prebuilt-tdlib` can be found by running +`npm info prebuilt-tdlib dist-tags`. See the README of [prebuilt-tdlib][] for +additional information. [prebuilt-tdlib]: packages/prebuilt-tdlib/README.md diff --git a/packages/prebuilt-tdlib/README.md b/packages/prebuilt-tdlib/README.md index cfd6809..e3373e6 100644 --- a/packages/prebuilt-tdlib/README.md +++ b/packages/prebuilt-tdlib/README.md @@ -2,17 +2,14 @@ This package distributes pre-built [TDLib][] shared libraries through npm. The libraries are built on GitHub Actions ([prebuilt-tdlib.yml][]) and published -using [npm publish --provenance][provenance]. +using [npm publish --provenance][npm-provenance]. [TDLib]: https://github.com/tdlib/td [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. +[npm-provenance]: https://docs.npmjs.com/generating-provenance-statements 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 @@ -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 @@ -123,9 +124,9 @@ An incomplete list is available below (mostly exceptions or "notable" versions): Changes to the building process of `prebuilt-tdlib` are noted below. -### (unreleased) +### 2024-07-19 -First published as ``. +First published as `prebuilt-tdlib@td-1.8.33`. The building process is significantly changed in this update. @@ -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 diff --git a/packages/prebuilt-tdlib/ci/build-linux.sh b/packages/prebuilt-tdlib/ci/build-linux.sh index 90ba87d..8654b94 100755 --- a/packages/prebuilt-tdlib/ci/build-linux.sh +++ b/packages/prebuilt-tdlib/ci/build-linux.sh @@ -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" diff --git a/packages/prebuilt-tdlib/ci/tdlib-linux.nix b/packages/prebuilt-tdlib/ci/tdlib-linux.nix index 42da1ed..ec1924a 100644 --- a/packages/prebuilt-tdlib/ci/tdlib-linux.nix +++ b/packages/prebuilt-tdlib/ci/tdlib-linux.nix @@ -1,7 +1,10 @@ -{ pkgs ? import {}, target, rev }: +{ target, rev }: let + pkgs = if builtins.substring 0 7 target == "aarch64" + then import { crossSystem.config = "aarch64-unknown-linux-gnu"; } + else import {}; 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 @@ -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; diff --git a/packages/prebuilt-tdlib/ci/zlib-zig.nix b/packages/prebuilt-tdlib/ci/zlib-zig.nix index 948b5cb..40443b0 100644 --- a/packages/prebuilt-tdlib/ci/zlib-zig.nix +++ b/packages/prebuilt-tdlib/ci/zlib-zig.nix @@ -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 - # ''; }) diff --git a/packages/prebuilt-tdlib/prebuild-list.js b/packages/prebuilt-tdlib/prebuild-list.js index e71e818..28a3ea0 100644 --- a/packages/prebuilt-tdlib/prebuild-list.js +++ b/packages/prebuilt-tdlib/prebuild-list.js @@ -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' } ]