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 17, 2024
1 parent d3580a4 commit 3e6ae4b
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 17 deletions.
22 changes: 21 additions & 1 deletion .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,11 @@ 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-linux-arm64
- build-macos
- build-windows-x86_64
runs-on: ${{ matrix.v.os }}
strategy:
fail-fast: false
Expand Down
4 changes: 3 additions & 1 deletion packages/prebuilt-tdlib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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 Down Expand Up @@ -142,6 +142,8 @@ 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. However, this prebuild is
not tested to work in CI.

### 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 3e6ae4b

Please sign in to comment.