Skip to content

Commit

Permalink
prebuilt-tdlib: refactor ci
Browse files Browse the repository at this point in the history
- Refactor and simplify nix files
- Use new ubuntu-24.04-arm runner for testing
  • Loading branch information
eilvelia committed Jan 17, 2025
1 parent 6930178 commit ad0dea2
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 168 deletions.
54 changes: 15 additions & 39 deletions .github/workflows/prebuilt-tdlib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ on:
type: string
required: false
default: 'latest'
# NOTE: The ZLIB_USE_STATIC_LIBS option requires CMake >= 3.24
jobs:
build-linux-x86_64:
build-linux-x86_64-glibc:
name: 'Build TDLib / Linux x86_64 glibc'
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
Expand All @@ -30,15 +29,15 @@ jobs:
- name: Build TDLib
run: |
cd packages/prebuilt-tdlib/ci
./build-linux.sh ${{ inputs.tdlib }} x86_64-linux-gnu.2.22
./build-linux.sh ${{ inputs.tdlib }} x86_64 gnu
- uses: actions/upload-artifact@v4
with:
name: tdlib-linux-x86_64-glibc
path: ${{ env.TO_UPLOAD }}

build-linux-arm64:
build-linux-arm64-glibc:
name: 'Build TDLib / Linux arm64 glibc (cross)'
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
Expand All @@ -47,7 +46,7 @@ jobs:
- name: Build TDLib
run: |
cd packages/prebuilt-tdlib/ci
./build-linux.sh ${{ inputs.tdlib }} aarch64-linux-gnu.2.22
./build-linux.sh ${{ inputs.tdlib }} aarch64 gnu
- uses: actions/upload-artifact@v4
with:
name: tdlib-linux-arm64-glibc
Expand Down Expand Up @@ -108,6 +107,7 @@ jobs:
run: vcpkg install gperf:x64-windows-static openssl:x64-windows-static zlib:x64-windows-static
- name: CMake version
run: cmake --version
# NOTE: The ZLIB_USE_STATIC_LIBS option requires CMake >= 3.24
- name: Build TDLib
run: |
mkdir to-upload
Expand All @@ -129,7 +129,8 @@ jobs:
test:
name: 'Test / ${{ matrix.v.bin }} / ${{ matrix.v.os }}'
needs:
- build-linux-x86_64
- build-linux-x86_64-glibc
- build-linux-arm64-glibc
- build-macos-x86_64
- build-macos-arm64
- build-windows-x86_64
Expand All @@ -138,11 +139,15 @@ jobs:
fail-fast: false
matrix:
v:
- os: ubuntu-latest
# use an older ubuntu version to test the library working with
# previous glibc version
- os: ubuntu-22.04
bin: tdlib-linux-x86_64-glibc
- os: ubuntu-24.04-arm
bin: tdlib-linux-arm64-glibc
- os: macos-13
bin: tdlib-macos-x86_64
- os: macos-14
- os: macos-latest
bin: tdlib-macos-arm64
- os: windows-latest
bin: tdlib-windows-x86_64
Expand All @@ -163,35 +168,6 @@ 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 <<EOF
set -ex
cd /usr/src/app
ldd libtdjson.so # Info
npm install
npm uninstall -D prebuilt-tdlib
LIBDIR_PATH=. npm run test:integration
EOF
docker run -v $(pwd):/usr/src/app --platform linux/arm64 node:20 \
bash /usr/src/app/test-linux-aarch64.sh
publish:
name: 'Publish to npm'
needs: [test, test-linux-arm64]
Expand Down
28 changes: 23 additions & 5 deletions packages/prebuilt-tdlib/ci/build-linux.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
#!/usr/bin/env bash

_tdlib=$1
_target="${2:-x86_64-linux-gnu.2.22}"
set -eo pipefail

if [ -z "$_tdlib" ]; then
tdlib=$1
arch=$2
abi="${3:-gnu}"

if [ -z "$tdlib" ]; then
echo "Not enough arguments: expected TDLib rev"
exit 1
fi

set -ex
if [ -z "$arch" ]; then
echo "Not enough arguments: expected arch"
exit 1
fi

if [ "$abi" = "gnu" ]; then
libc_version="2.22"
else
libc_version=""
fi

set -x

nix-build tdlib-linux.nix -v --argstr rev "$_tdlib" --argstr target "$_target"
nix-build tdlib-zig-wrapper.nix -v \
--argstr rev "$tdlib" \
--argstr arch "$arch" \
--argstr abi "$abi" \
--argstr libcVersion "$libc_version"

mkdir to-upload
cp -L ./result/lib/libtdjson.so to-upload/libtdjson.so
Expand Down
10 changes: 6 additions & 4 deletions packages/prebuilt-tdlib/ci/build-macos.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/usr/bin/env bash

_tdlib=$1
set -eo pipefail

if [ -z "$_tdlib" ]; then
tdlib=$1

if [ -z "$tdlib" ]; then
echo "Not enough arguments: expected TDLib rev"
exit 1
fi

set -ex
set -x

nix-build tdlib-macos.nix -v --argstr rev "$_tdlib"
nix-build -v -E "(import <nixpkgs> { }).callPackage ./tdlib.nix { rev = \"$tdlib\" }"

mkdir to-upload
cp -L ./result/lib/libtdjson.dylib to-upload/libtdjson.dylib
Expand Down
5 changes: 0 additions & 5 deletions packages/prebuilt-tdlib/ci/openssl-zig.nix

This file was deleted.

64 changes: 0 additions & 64 deletions packages/prebuilt-tdlib/ci/tdlib-linux.nix

This file was deleted.

46 changes: 0 additions & 46 deletions packages/prebuilt-tdlib/ci/tdlib-macos.nix

This file was deleted.

23 changes: 23 additions & 0 deletions packages/prebuilt-tdlib/ci/tdlib-zig-wrapper.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ pkgs ? import <nixpkgs> {}, rev, arch, abi, libcVersion ? "" }:
# Linux-only
let
target = "${arch}-linux-${abi}" +
(if builtins.stringLength libcVersion > 0 then ".${libcVersion}" else "");
pkgs' = import pkgs.path { crossSystem.config = "${arch}-unknown-linux-${abi}"; };
zig-toolchain = import ./zig-toolchain.nix {
inherit target;
pkgs = pkgs'.buildPackages.buildPackages;
};
openssl = pkgs'.openssl.overrideAttrs (final: prev: {
preConfigure = (prev.preConfigure or "") + zig-toolchain.env;
doCheck = false;
});
zlib = pkgs'.zlib.overrideAttrs (final: prev: {
preConfigure = (prev.preConfigure or "") + zig-toolchain.env;
doCheck = false;
});
in
(pkgs'.callPackage ./tdlib.nix { inherit rev openssl zlib; }).overrideAttrs (final: prev: {
preConfigure = (prev.preConfigure or "") + zig-toolchain.env;
patches = [ ./tdlib-zig.patch ];
})
Loading

0 comments on commit ad0dea2

Please sign in to comment.