From d6f0bef2cdaec385a0d2079312634041beb8c5bf Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 27 Jan 2025 00:32:09 +0000 Subject: [PATCH] chore: Add binary deploy workflows. --- .github/scripts/cmake-android | 65 ---------- .github/workflows/ci.yml | 11 -- .github/workflows/deploy.yml | 222 ++++++++++++++++++++++++++++++++++ other/deploy/android.sh | 96 +++++++++++++++ other/deploy/deps.sh | 29 +++++ other/deploy/linux.sh | 26 ++++ other/deploy/macos.sh | 26 ++++ 7 files changed, 399 insertions(+), 76 deletions(-) delete mode 100755 .github/scripts/cmake-android create mode 100644 .github/workflows/deploy.yml create mode 100755 other/deploy/android.sh create mode 100755 other/deploy/deps.sh create mode 100755 other/deploy/linux.sh create mode 100755 other/deploy/macos.sh diff --git a/.github/scripts/cmake-android b/.github/scripts/cmake-android deleted file mode 100755 index 95ec6600a8a..00000000000 --- a/.github/scripts/cmake-android +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash - -set -eu - -# Set up environment -NDK=$ANDROID_NDK_HOME - -ABI=${1:-"armeabi-v7a"} - -case $ABI in - armeabi-v7a) - TARGET=armv7a-linux-androideabi - NDK_API=21 - ;; - arm64-v8a) - TARGET=aarch64-linux-android - NDK_API=21 - ;; - x86) - TARGET=i686-linux-android - NDK_API=21 - ;; - x86_64) - TARGET=x86_64-linux-android - NDK_API=21 - ;; - *) - exit 1 - ;; -esac - -rm -rf _android_prefix -mkdir -p _android_prefix -PREFIX=$PWD/_android_prefix - -TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64 -SYSROOT=$TOOLCHAIN/sysroot - -export CC="$TOOLCHAIN/bin/$TARGET$NDK_API"-clang -export LDFLAGS=-static-libstdc++ -export PKG_CONFIG_PATH="$PREFIX"/lib/pkgconfig - -# Build libsodium -if [ ! -d libsodium ]; then - git clone --branch=1.0.18 https://github.com/jedisct1/libsodium.git -fi -cd libsodium -git clean -ffdx -autoreconf -fi -./configure --prefix="$PREFIX" --host="$TARGET" --with-sysroot="$SYSROOT" --disable-shared --disable-pie -make -j"$(nproc)" install -cd .. - -# Build c-toxcore -rm -rf _build -mkdir -p _build -cd _build -cmake .. \ - -DBUILD_TOXAV=OFF \ - -DBOOTSTRAP_DAEMON=OFF \ - -DCMAKE_TOOLCHAIN_FILE="$NDK/build/cmake/android.toolchain.cmake" \ - -DANDROID_ABI="$ABI" \ - -DCMAKE_INSTALL_PREFIX="$PREFIX" \ - -DCMAKE_PREFIX_PATH="$PREFIX" -cmake --build . diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b832d3778a..4a71bf5230c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,17 +60,6 @@ jobs: - name: Build, test, and upload coverage run: other/docker/coverage/run - build-android: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v4 - with: - submodules: recursive - - run: .github/scripts/cmake-android armeabi-v7a - - run: .github/scripts/cmake-android arm64-v8a - - run: .github/scripts/cmake-android x86 - - run: .github/scripts/cmake-android x86_64 - build-macos: runs-on: macos-latest steps: diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000000..d61849dac2a --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,222 @@ +name: deploy + +on: + # Allow manual trigger. + workflow_dispatch: + pull_request: + branches: ["master"] + push: + branches: ["master"] + tags: ["v*"] + +# Cancel old PR builds when pushing new commits. +concurrency: + group: deploy-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + + ################################################################################################ + # Preparation jobs + ################################################################################################ + + update-nightly-tag: + name: Update nightly release tag + runs-on: ubuntu-24.04 + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - name: Move nightly tag to head for nightly release + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + run: git tag -f nightly && git push origin nightly -f + + ################################################################################################ + # Build and deploy jobs (PR and push) + ################################################################################################ + + build-linux: + name: Linux + needs: [update-nightly-tag] + strategy: + matrix: + arch: [aarch64, x86_64] + runs-on: ${{ matrix.arch == 'aarch64' && 'ubuntu-24.04-arm' || 'ubuntu-24.04' }} + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: Install build tools + run: sudo apt-get install -y --no-install-recommends ninja-build yasm + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: prefix + key: ${{ github.job }}-${{ matrix.arch }}-deps + - name: Run build + run: other/deploy/linux.sh + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: toxcore-linux-${{ matrix.arch }} + path: toxcore-linux-${{ matrix.arch }} + - name: Get tag name for release file name + if: contains(github.ref, 'refs/tags/v') + id: get_version + run: | + VERSION="$(echo "$GITHUB_REF" | cut -d / -f 3)" + echo "release_tarball=toxcore-$VERSION-linux-${{ matrix.arch }}.tar.gz" >>$GITHUB_OUTPUT + - name: Create tarball for release upload + if: contains(github.ref, 'refs/tags/v') + run: | + tar zcf "${{ steps.get_version.outputs.release_tarball }}" toxcore-linux-${{ matrix.arch }} + sha256sum "${{ steps.get_version.outputs.release_tarball }}" > "${{ steps.get_version.outputs.release_tarball }}.sha256" + - name: Upload to versioned release + if: contains(github.ref, 'refs/tags/v') + uses: ncipollo/release-action@v1 + with: + allowUpdates: true + draft: true + token: ${{ secrets.GITHUB_TOKEN }} + artifacts: "${{ steps.get_version.outputs.release_tarball }},${{ steps.get_version.outputs.release_tarball }}.sha256" + - name: Create tarball for nightly upload + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + run: | + tar zcf toxcore-nightly-linux-${{ matrix.arch }}.tar.gz toxcore-linux-${{ matrix.arch }} + sha256sum toxcore-nightly-linux-${{ matrix.arch }}.tar.gz > toxcore-nightly-linux-${{ matrix.arch }}.tar.gz.sha256 + - name: Upload to nightly release + uses: ncipollo/release-action@v1 + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + with: + allowUpdates: true + tag: nightly + omitBodyDuringUpdate: true + omitNameDuringUpdate: true + prerelease: true + replacesArtifacts: true + token: ${{ secrets.GITHUB_TOKEN }} + artifacts: "toxcore-nightly-linux-${{ matrix.arch }}.tar.gz,toxcore-nightly-linux-${{ matrix.arch }}.tar.gz.sha256" + + build-macos: + name: macOS + needs: [update-nightly-tag] + strategy: + matrix: + arch: [arm64, x86_64] + runs-on: ${{ matrix.arch == 'arm64' && 'macos-14' || 'macos-13' }} + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: Install build tools + run: brew install coreutils ninja yasm + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: prefix + key: ${{ github.job }}-${{ matrix.arch }}-deps + - name: Run build + run: other/deploy/macos.sh + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: toxcore-macos-${{ matrix.arch }} + path: toxcore-macos-${{ matrix.arch }} + - name: Get tag name for release file name + if: contains(github.ref, 'refs/tags/v') + id: get_version + run: | + VERSION="$(echo "$GITHUB_REF" | cut -d / -f 3)" + echo "release_tarball=toxcore-$VERSION-macos-${{ matrix.arch }}.tar.gz" >>$GITHUB_OUTPUT + - name: Create tarball for release upload + if: contains(github.ref, 'refs/tags/v') + run: | + tar zcf "${{ steps.get_version.outputs.release_tarball }}" toxcore-macos-${{ matrix.arch }} + sha256sum "${{ steps.get_version.outputs.release_tarball }}" > "${{ steps.get_version.outputs.release_tarball }}.sha256" + - name: Upload to versioned release + if: contains(github.ref, 'refs/tags/v') + uses: ncipollo/release-action@v1 + with: + allowUpdates: true + draft: true + token: ${{ secrets.GITHUB_TOKEN }} + artifacts: "${{ steps.get_version.outputs.release_tarball }},${{ steps.get_version.outputs.release_tarball }}.sha256" + - name: Create tarball for nightly upload + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + run: | + tar zcf toxcore-nightly-macos-${{ matrix.arch }}.tar.gz toxcore-macos-${{ matrix.arch }} + sha256sum toxcore-nightly-macos-${{ matrix.arch }}.tar.gz > toxcore-nightly-macos-${{ matrix.arch }}.tar.gz.sha256 + - name: Upload to nightly release + uses: ncipollo/release-action@v1 + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + with: + allowUpdates: true + tag: nightly + omitBodyDuringUpdate: true + omitNameDuringUpdate: true + prerelease: true + replacesArtifacts: true + token: ${{ secrets.GITHUB_TOKEN }} + artifacts: "toxcore-nightly-macos-${{ matrix.arch }}.tar.gz,toxcore-nightly-macos-${{ matrix.arch }}.tar.gz.sha256" + + build-android: + name: Android + needs: [update-nightly-tag] + strategy: + matrix: + arch: [armeabi-v7a, arm64-v8a, x86, x86_64] + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: Install build tools + run: sudo apt-get install -y --no-install-recommends ninja-build yasm + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: prefix + key: ${{ github.job }}-${{ matrix.arch }}-deps + - name: Run build + run: other/deploy/android.sh "${{ matrix.arch }}" + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: toxcore-android-${{ matrix.arch }} + path: toxcore-android-${{ matrix.arch }} + - name: Get tag name for release file name + if: contains(github.ref, 'refs/tags/v') + id: get_version + run: | + VERSION="$(echo "$GITHUB_REF" | cut -d / -f 3)" + echo "release_tarball=toxcore-$VERSION-android-${{ matrix.arch }}.tar.gz" >>$GITHUB_OUTPUT + - name: Create tarball for release upload + if: contains(github.ref, 'refs/tags/v') + run: | + tar zcf "${{ steps.get_version.outputs.release_tarball }}" toxcore-android-${{ matrix.arch }} + sha256sum "${{ steps.get_version.outputs.release_tarball }}" > "${{ steps.get_version.outputs.release_tarball }}.sha256" + - name: Upload to versioned release + if: contains(github.ref, 'refs/tags/v') + uses: ncipollo/release-action@v1 + with: + allowUpdates: true + draft: true + token: ${{ secrets.GITHUB_TOKEN }} + artifacts: "${{ steps.get_version.outputs.release_tarball }},${{ steps.get_version.outputs.release_tarball }}.sha256" + - name: Create tarball for nightly upload + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + run: | + tar zcf toxcore-nightly-android-${{ matrix.arch }}.tar.gz toxcore-android-${{ matrix.arch }} + sha256sum toxcore-nightly-android-${{ matrix.arch }}.tar.gz > toxcore-nightly-android-${{ matrix.arch }}.tar.gz.sha256 + - name: Upload to nightly release + uses: ncipollo/release-action@v1 + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + with: + allowUpdates: true + tag: nightly + omitBodyDuringUpdate: true + omitNameDuringUpdate: true + prerelease: true + replacesArtifacts: true + token: ${{ secrets.GITHUB_TOKEN }} + artifacts: "toxcore-nightly-android-${{ matrix.arch }}.tar.gz,toxcore-nightly-android-${{ matrix.arch }}.tar.gz.sha256" diff --git a/other/deploy/android.sh b/other/deploy/android.sh new file mode 100755 index 00000000000..cd7bbc21e8a --- /dev/null +++ b/other/deploy/android.sh @@ -0,0 +1,96 @@ +#!/bin/bash + +set -eu + +# Set up environment +NDK=$ANDROID_NDK_HOME + +ABI=${1:-"armeabi-v7a"} + +case $ABI in + armeabi-v7a) + TARGET=armv7a-linux-androideabi + NDK_API=21 + ANDROID_VPX_ABI=armv7-android-gcc + ;; + arm64-v8a) + TARGET=aarch64-linux-android + NDK_API=21 + ANDROID_VPX_ABI=arm64-android-gcc + ;; + x86) + TARGET=i686-linux-android + NDK_API=21 + ANDROID_VPX_ABI=x86-android-gcc + ;; + x86_64) + TARGET=x86_64-linux-android + NDK_API=21 + ANDROID_VPX_ABI=x86_64-android-gcc + ;; + *) + exit 1 + ;; +esac + +PREFIX="$PWD/prefix" + +TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/linux-x86_64" +SYSROOT="$TOOLCHAIN/sysroot" + +export CC="$TOOLCHAIN/bin/$TARGET$NDK_API-clang" +export CXX="$TOOLCHAIN/bin/$TARGET$NDK_API-clang++" +export LDFLAGS=-static-libstdc++ +export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig" + +# Build libsodium +if [ ! -f "$PREFIX/lib/libsodium.a" ]; then + tar zxf <(wget -O- https://github.com/jedisct1/libsodium/releases/download/1.0.20-RELEASE/libsodium-1.0.20.tar.gz) + pushd libsodium-1.0.20 + ./configure --prefix="$PREFIX" --host="$TARGET" --with-sysroot="$SYSROOT" --disable-shared --disable-pie + make -j"$(nproc)" install + popd + rm -rf libsodium-1.0.20 +fi + +# Build opus +if [ ! -f "$PREFIX/lib/libopus.a" ]; then + tar zxf <(wget -O- https://github.com/xiph/opus/releases/download/v1.5.2/opus-1.5.2.tar.gz) + pushd opus-1.5.2 + CFLAGS="-fPIC" ./configure --prefix="$PREFIX" --host="$TARGET" --with-sysroot="$SYSROOT" --disable-shared + make "-j$(nproc)" + make install + popd + rm -rf opus-1.5.2 +fi + +# Build libvpx +if [ ! -f "$PREFIX/lib/libvpx.a" ]; then + tar zxf <(wget -O- https://github.com/webmproject/libvpx/archive/refs/tags/v1.15.0.tar.gz) + pushd libvpx-1.15.0 + ./configure --prefix="$PREFIX" --libc="$SYSROOT" --target="$ANDROID_VPX_ABI" --disable-examples --disable-unit-tests --enable-pic \ + || (cat config.log && exit 1) + sed -i -e "s!^AS=as!AS=$CC -c!" *.mk + sed -i -e "s!^STRIP=strip!STRIP=$TOOLCHAIN/bin/llvm-strip!" *.mk + make "-j$(nproc)" + make install + popd + rm -rf libvpx-1.15.0 +fi + +# Build c-toxcore +rm -rf _build +cmake -B _build -G Ninja \ + -DANDROID_ABI="$ABI" \ + -DCMAKE_TOOLCHAIN_FILE="$NDK/build/cmake/android.toolchain.cmake" \ + -DCMAKE_INSTALL_PREFIX="$PWD/toxcore-android-$ABI" \ + -DCMAKE_PREFIX_PATH="$PREFIX" \ + -DENABLE_STATIC=OFF \ + -DENABLE_SHARED=ON \ + -DMUST_BUILD_TOXAV=ON \ + -DDHT_BOOTSTRAP=OFF \ + -DBOOTSTRAP_DAEMON=OFF \ + -DUNITTEST=OFF \ + -DMIN_LOGGER_LEVEL=TRACE +cmake --build _build +cmake --install _build diff --git a/other/deploy/deps.sh b/other/deploy/deps.sh new file mode 100755 index 00000000000..159a48279b6 --- /dev/null +++ b/other/deploy/deps.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -eux -o pipefail + +if [ -d "prefix" ]; then + exit 0 +fi + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" + +git clone --branch=pic --depth=1 https://github.com/iphydf/dockerfiles "$SCRIPT_DIR/dockerfiles" + +SYSTEM="$1" +ARCH="$(uname -m)" + +DEP_PREFIX="$PWD/prefix" + +for dep in sodium opus vpx; do + mkdir -p "external/$dep" + pushd "external/$dep" + if [ -f "$SCRIPT_DIR/dockerfiles/qtox/build_${dep}_$SYSTEM.sh" ]; then + SCRIPT="$SCRIPT_DIR/dockerfiles/qtox/build_${dep}_$SYSTEM.sh" + else + SCRIPT="$SCRIPT_DIR/dockerfiles/qtox/build_$dep.sh" + fi + "$SCRIPT" --arch "$SYSTEM-$ARCH" --libtype "static" --buildtype "release" --prefix "$DEP_PREFIX" --macos "10.15" + popd + rm -rf "external/$dep" +done diff --git a/other/deploy/linux.sh b/other/deploy/linux.sh new file mode 100755 index 00000000000..f355b3d3ee7 --- /dev/null +++ b/other/deploy/linux.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -eux -o pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" + +"$SCRIPT_DIR/deps.sh" linux + +export PKG_CONFIG_PATH="$PWD/prefix/lib/pkgconfig" + +# Build +cmake \ + -B _build \ + -G Ninja \ + -DCMAKE_INSTALL_PREFIX="$PWD/toxcore-linux-$(uname -m)" \ + -DCMAKE_BUILD_TYPE=Release \ + -DENABLE_STATIC=OFF \ + -DENABLE_SHARED=ON \ + -DMUST_BUILD_TOXAV=ON \ + -DDHT_BOOTSTRAP=OFF \ + -DBOOTSTRAP_DAEMON=OFF \ + -DUNITTEST=OFF \ + -DMIN_LOGGER_LEVEL=TRACE + +cmake --build _build +cmake --install _build diff --git a/other/deploy/macos.sh b/other/deploy/macos.sh new file mode 100755 index 00000000000..53393304a8a --- /dev/null +++ b/other/deploy/macos.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +set -eux -o pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" + +"$SCRIPT_DIR/deps.sh" macos + +export PKG_CONFIG_PATH="$PWD/prefix/lib/pkgconfig" + +# Build +cmake \ + -B _build \ + -G Ninja \ + -DCMAKE_INSTALL_PREFIX="$PWD/toxcore-macos-$(uname -m)" \ + -DCMAKE_BUILD_TYPE=Release \ + -DENABLE_STATIC=OFF \ + -DENABLE_SHARED=ON \ + -DMUST_BUILD_TOXAV=ON \ + -DDHT_BOOTSTRAP=OFF \ + -DBOOTSTRAP_DAEMON=OFF \ + -DUNITTEST=OFF \ + -DMIN_LOGGER_LEVEL=TRACE + +cmake --build _build +cmake --install _build