From f7855380c7556f62acfd0a3550671cf1f60abc6f Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 17 Feb 2024 14:38:22 +0000 Subject: [PATCH] ci: build deltachat-rpc-server with nix --- .github/workflows/deltachat-rpc-server.yml | 106 ++++++++++++--------- scripts/README.md | 2 - scripts/wheel-rpc-server.py | 8 +- scripts/zig-cc | 57 ----------- scripts/zig-rpc-server.sh | 50 ---------- 5 files changed, 69 insertions(+), 154 deletions(-) delete mode 100755 scripts/zig-cc delete mode 100755 scripts/zig-rpc-server.sh diff --git a/.github/workflows/deltachat-rpc-server.yml b/.github/workflows/deltachat-rpc-server.yml index bc0cf75553..d62901a2de 100644 --- a/.github/workflows/deltachat-rpc-server.yml +++ b/.github/workflows/deltachat-rpc-server.yml @@ -21,24 +21,27 @@ jobs: # Build a version statically linked against musl libc # to avoid problems with glibc version incompatibility. build_linux: - name: Cross-compile deltachat-rpc-server for x86_64, i686, aarch64 and armv7 Linux - runs-on: ubuntu-22.04 + name: Build deltachat-rpc-server for Linux + strategy: + fail-fast: false + matrix: + arch: [aarch64, armv7l, armv6l, i686, x86_64] + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: show-progress: false - - - name: Install ziglang - run: pip install wheel ziglang==0.11.0 + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main - name: Build deltachat-rpc-server binaries - run: sh scripts/zig-rpc-server.sh + run: nix build .#deltachat-rpc-server-${{ matrix.arch }}-linux - - name: Upload dist directory with Linux binaries + - name: Upload binary uses: actions/upload-artifact@v4 with: - name: linux - path: dist/ + name: deltachat-rpc-server-${{ matrix.arch }}-linux + path: result/bin/deltachat-rpc-server if-no-files-found: error build_windows: @@ -46,34 +49,23 @@ jobs: strategy: fail-fast: false matrix: - include: - - os: windows-latest - artifact: win32.exe - path: deltachat-rpc-server.exe - target: i686-pc-windows-msvc - - - os: windows-latest - artifact: win64.exe - path: deltachat-rpc-server.exe - target: x86_64-pc-windows-msvc - - runs-on: ${{ matrix.os }} + arch: [win32, win64] + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: show-progress: false + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main - - name: Setup rust target - run: rustup target add ${{ matrix.target }} - - - name: Build - run: cargo build --release --package deltachat-rpc-server --target ${{ matrix.target }} --features vendored + - name: Build deltachat-rpc-server binaries + run: nix build .#deltachat-rpc-server-${{ matrix.arch }} - name: Upload binary uses: actions/upload-artifact@v4 with: - name: deltachat-rpc-server-${{ matrix.artifact }} - path: target/${{ matrix.target}}/release/${{ matrix.path }} + name: deltachat-rpc-server-${{ matrix.arch }} + path: result/bin/deltachat-rpc-server.exe if-no-files-found: error build_macos: @@ -81,9 +73,7 @@ jobs: strategy: fail-fast: false matrix: - include: - - arch: x86_64 - - arch: aarch64 + arch: [x86_64, aarch64] runs-on: macos-latest steps: @@ -106,7 +96,7 @@ jobs: publish: name: Build wheels and upload binaries to the release - needs: ["build_linux", "build_windows", "build_macos"] + needs: ["build_linux", "build_macos"] permissions: contents: write runs-on: "ubuntu-latest" @@ -115,23 +105,47 @@ jobs: with: show-progress: false - - name: Download Linux binaries + - name: Download Linux aarch64 binary + uses: actions/download-artifact@v4 + with: + name: deltachat-rpc-server-aarch64-linux + path: deltachat-rpc-server-aarch64-linux.d + + - name: Download Linux armv7l binary + uses: actions/download-artifact@v4 + with: + name: deltachat-rpc-server-armv7l-linux + path: deltachat-rpc-server-armv7l-linux.d + + - name: Download Linux armv6l binary + uses: actions/download-artifact@v4 + with: + name: deltachat-rpc-server-armv6l-linux + path: deltachat-rpc-server-armv6l-linux.d + + - name: Download Linux i686 binary + uses: actions/download-artifact@v4 + with: + name: deltachat-rpc-server-i686-linux + path: deltachat-rpc-server-i686-linux.d + + - name: Download Linux x86_64 binary uses: actions/download-artifact@v4 with: - name: linux - path: dist/ + name: deltachat-rpc-server-x86_64-linux + path: deltachat-rpc-server-x86_64-linux.d - - name: Download win32 binary + - name: Download Win32 binary uses: actions/download-artifact@v4 with: - name: deltachat-rpc-server-win32.exe - path: deltachat-rpc-server-win32.exe.d + name: deltachat-rpc-server-win32 + path: deltachat-rpc-server-win32.d - - name: Download win64 binary + - name: Download Win64 binary uses: actions/download-artifact@v4 with: - name: deltachat-rpc-server-win64.exe - path: deltachat-rpc-server-win64.exe.d + name: deltachat-rpc-server-win64 + path: deltachat-rpc-server-win64.d - name: Download macOS binary for x86_64 uses: actions/download-artifact@v4 @@ -147,8 +161,14 @@ jobs: - name: Flatten dist/ directory run: | - mv deltachat-rpc-server-win32.exe.d/deltachat-rpc-server.exe dist/deltachat-rpc-server-win32.exe - mv deltachat-rpc-server-win64.exe.d/deltachat-rpc-server.exe dist/deltachat-rpc-server-win64.exe + mkdir -p dist + mv deltachat-rpc-server-aarch64-linux.d/deltachat-rpc-server dist/deltachat-rpc-server-aarch64-linux + mv deltachat-rpc-server-armv7l-linux.d/deltachat-rpc-server dist/deltachat-rpc-server-armv7l-linux + mv deltachat-rpc-server-armv6l-linux.d/deltachat-rpc-server dist/deltachat-rpc-server-armv6l-linux + mv deltachat-rpc-server-i686-linux.d/deltachat-rpc-server dist/deltachat-rpc-server-i686-linux + mv deltachat-rpc-server-x86_64-linux.d/deltachat-rpc-server dist/deltachat-rpc-server-x86_64-linux + mv deltachat-rpc-server-win32.d/deltachat-rpc-server.exe dist/deltachat-rpc-server-win32.exe + mv deltachat-rpc-server-win64.d/deltachat-rpc-server.exe dist/deltachat-rpc-server-win64.exe mv deltachat-rpc-server-x86_64-macos.d/deltachat-rpc-server dist/deltachat-rpc-server-x86_64-macos mv deltachat-rpc-server-aarch64-macos.d/deltachat-rpc-server dist/deltachat-rpc-server-aarch64-macos diff --git a/scripts/README.md b/scripts/README.md index 160e633cff..2c8a06721e 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -35,8 +35,6 @@ and an own build machine. - `run_all.sh` builds Python wheels -- `zig-rpc-server.sh` compiles binaries of `deltachat-rpc-server` using Zig toolchain statically linked against musl libc. - - `android-rpc-server.sh` compiles binaries of `deltachat-rpc-server` using Android NDK. - `build-python-docs.sh` builds Python documentation into `dist/html/`. diff --git a/scripts/wheel-rpc-server.py b/scripts/wheel-rpc-server.py index 41f97af951..019dfb347d 100755 --- a/scripts/wheel-rpc-server.py +++ b/scripts/wheel-rpc-server.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 -"""Build Python wheels for deltachat-rpc-server. -Run scripts/zig-rpc-server.sh first.""" +"""Build Python wheels for deltachat-rpc-server.""" from pathlib import Path from wheel.wheelfile import WheelFile import tomllib @@ -160,6 +159,11 @@ def main(): "dist/deltachat-rpc-server-armv7-linux", "py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.musllinux_1_1_armv7l", ) + build_wheel( + version, + "dist/deltachat-rpc-server-armv6-linux", + "py3-none-manylinux_2_17_armv6l.manylinux2014_armv6l.musllinux_1_1_armv6l", + ) build_wheel( version, "dist/deltachat-rpc-server-aarch64-linux", diff --git a/scripts/zig-cc b/scripts/zig-cc deleted file mode 100755 index ffa3278b42..0000000000 --- a/scripts/zig-cc +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python -# /// pyproject -# [run] -# dependencies = [ -# "ziglang==0.11.0" -# ] -# /// -import os -import subprocess -import sys - - -def flag_filter(flag: str) -> bool: - # Workaround for . - if flag == "-latomic": - return False - - if flag == "-lc": - return False - if flag == "-Wl,-melf_i386": - return False - if "self-contained" in flag and "crt" in flag: - return False - return True - - -def main(): - args = [flag for flag in sys.argv[1:] if flag_filter(flag)] - zig_target = os.environ["ZIG_TARGET"] - zig_cpu = os.environ.get("ZIG_CPU") - if zig_cpu: - zig_cpu_args = ["-mcpu=" + zig_cpu] - args = [x for x in args if not x.startswith("-march")] - else: - zig_cpu_args = [] - - # Disable atomics and use locks instead in OpenSSL. - # Zig toolchains do not provide atomics. - # This is a workaround for - args += ["-DBROKEN_CLANG_ATOMICS"] - - subprocess.run( - [ - sys.executable, - "-m", - "ziglang", - "cc", - "-target", - zig_target, - *zig_cpu_args, - *args, - ], - check=True, - ) - - -main() diff --git a/scripts/zig-rpc-server.sh b/scripts/zig-rpc-server.sh deleted file mode 100755 index 455c0f150d..0000000000 --- a/scripts/zig-rpc-server.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/sh -# -# Build statically linked deltachat-rpc-server using zig. - -set -x -set -e - -unset RUSTFLAGS - -# Pin Rust version to avoid uncontrolled changes in the compiler and linker flags. -export RUSTUP_TOOLCHAIN=1.72.0 - -rustup target add i686-unknown-linux-musl -CC="$PWD/scripts/zig-cc" \ -TARGET_CC="$PWD/scripts/zig-cc" \ -CARGO_TARGET_I686_UNKNOWN_LINUX_MUSL_LINKER="$PWD/scripts/zig-cc" \ -LD="$PWD/scripts/zig-cc" \ -ZIG_TARGET="x86-linux-musl" \ -cargo build --release --target i686-unknown-linux-musl -p deltachat-rpc-server --features vendored - -rustup target add armv7-unknown-linux-musleabihf -CC="$PWD/scripts/zig-cc" \ -TARGET_CC="$PWD/scripts/zig-cc" \ -CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER="$PWD/scripts/zig-cc" \ -LD="$PWD/scripts/zig-cc" \ -ZIG_TARGET="arm-linux-musleabihf" \ -ZIG_CPU="generic+v7a+vfp3-d32+thumb2-neon" \ -cargo build --release --target armv7-unknown-linux-musleabihf -p deltachat-rpc-server --features vendored - -rustup target add x86_64-unknown-linux-musl -CC="$PWD/scripts/zig-cc" \ -TARGET_CC="$PWD/scripts/zig-cc" \ -CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER="$PWD/scripts/zig-cc" \ -LD="$PWD/scripts/zig-cc" \ -ZIG_TARGET="x86_64-linux-musl" \ -cargo build --release --target x86_64-unknown-linux-musl -p deltachat-rpc-server --features vendored - -rustup target add aarch64-unknown-linux-musl -CC="$PWD/scripts/zig-cc" \ -TARGET_CC="$PWD/scripts/zig-cc" \ -CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER="$PWD/scripts/zig-cc" \ -LD="$PWD/scripts/zig-cc" \ -ZIG_TARGET="aarch64-linux-musl" \ -cargo build --release --target aarch64-unknown-linux-musl -p deltachat-rpc-server --features vendored - -mkdir -p dist -cp target/x86_64-unknown-linux-musl/release/deltachat-rpc-server dist/deltachat-rpc-server-x86_64-linux -cp target/i686-unknown-linux-musl/release/deltachat-rpc-server dist/deltachat-rpc-server-i686-linux -cp target/aarch64-unknown-linux-musl/release/deltachat-rpc-server dist/deltachat-rpc-server-aarch64-linux -cp target/armv7-unknown-linux-musleabihf/release/deltachat-rpc-server dist/deltachat-rpc-server-armv7-linux