diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index facc387926..28e9e7c492 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -51,7 +51,7 @@ jobs: - name: Cache dependencies uses: actions/cache@v4 with: - path: prefix + path: deps-prefix-linux-${{ matrix.arch }} key: ${{ github.job }}-${{ matrix.arch }}-deps - name: Run build run: other/deploy/linux.sh "${{ matrix.arch }}" @@ -108,12 +108,10 @@ jobs: - 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 + path: deps-prefix-macos-${{ matrix.arch }} key: ${{ github.job }}-${{ matrix.arch }}-deps - name: Run build run: other/deploy/macos.sh "${{ matrix.arch }}" @@ -164,36 +162,34 @@ jobs: needs: [update-nightly-tag] strategy: matrix: - arch: [arm64, armv7, armv7s, i386, x86_64] + target: [ios-arm64, ios-armv7, ios-armv7s, iphonesimulator-arm64, iphonesimulator-x86_64] runs-on: 'macos-14' 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 + path: deps-prefix-${{ matrix.target }} + key: ${{ github.job }}-${{ matrix.target }}-deps - name: Run build - run: other/deploy/ios.sh "${{ matrix.arch }}" + run: other/deploy/ios.sh "${{ matrix.target }}" - name: Upload artifacts uses: actions/upload-artifact@v4 with: - name: toxcore-ios-${{ matrix.arch }} - path: toxcore-ios-${{ matrix.arch }} + name: toxcore-${{ matrix.target }} + path: toxcore-${{ matrix.target }} - 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-ios-${{ matrix.arch }}.tar.gz" >>$GITHUB_OUTPUT + echo "release_tarball=toxcore-$VERSION-${{ matrix.target }}.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-ios-${{ matrix.arch }} + tar zcf "${{ steps.get_version.outputs.release_tarball }}" toxcore-${{ matrix.target }} 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') @@ -206,8 +202,8 @@ jobs: - name: Create tarball for nightly upload if: github.event_name == 'push' && github.ref == 'refs/heads/master' run: | - tar zcf toxcore-nightly-ios-${{ matrix.arch }}.tar.gz toxcore-ios-${{ matrix.arch }} - sha256sum toxcore-nightly-ios-${{ matrix.arch }}.tar.gz > toxcore-nightly-ios-${{ matrix.arch }}.tar.gz.sha256 + tar zcf toxcore-nightly-${{ matrix.target }}.tar.gz toxcore-${{ matrix.target }} + sha256sum toxcore-nightly-${{ matrix.target }}.tar.gz > toxcore-nightly-${{ matrix.target }}.tar.gz.sha256 - name: Upload to nightly release uses: ncipollo/release-action@v1 if: github.event_name == 'push' && github.ref == 'refs/heads/master' @@ -219,7 +215,7 @@ jobs: prerelease: true replacesArtifacts: true token: ${{ secrets.GITHUB_TOKEN }} - artifacts: "toxcore-nightly-ios-${{ matrix.arch }}.tar.gz,toxcore-nightly-ios-${{ matrix.arch }}.tar.gz.sha256" + artifacts: "toxcore-nightly-${{ matrix.target }}.tar.gz,toxcore-nightly-${{ matrix.target }}.tar.gz.sha256" build-android: name: Android @@ -232,12 +228,10 @@ jobs: - 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 + path: deps-prefix-android-${{ matrix.arch }} key: ${{ github.job }}-${{ matrix.arch }}-deps - name: Run build run: other/deploy/android.sh "${{ matrix.arch }}" diff --git a/other/deploy/android.sh b/other/deploy/android.sh index bffb5f80bb..95914a0fe8 100755 --- a/other/deploy/android.sh +++ b/other/deploy/android.sh @@ -2,6 +2,10 @@ set -eu +if [ -n "${CI-}" ]; then + sudo apt-get install -y --no-install-recommends ninja-build yasm +fi + # Set up environment NDK=$ANDROID_NDK_HOME @@ -33,7 +37,7 @@ case $ABI in ;; esac -PREFIX="$PWD/prefix" +PREFIX="$PWD/deps-prefix-android-$ABI" TOOLCHAIN="$NDK/toolchains/llvm/prebuilt/linux-x86_64" SYSROOT="$TOOLCHAIN/sysroot" diff --git a/other/deploy/deps.sh b/other/deploy/deps.sh index 4dbb8e90d9..3c3d1fc546 100755 --- a/other/deploy/deps.sh +++ b/other/deploy/deps.sh @@ -2,27 +2,28 @@ set -eux -o pipefail -if [ -d "prefix" ]; then - exit 0 -fi +SYSTEM="$1" +ARCH="$2" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -git clone --depth=1 https://github.com/TokTok/dockerfiles "$SCRIPT_DIR/dockerfiles" +DEP_PREFIX="$PWD/deps-prefix-$SYSTEM-$ARCH" -SYSTEM="$1" -ARCH="$2" +if [ -d "$DEP_PREFIX" ]; then + exit 0 +fi -DEP_PREFIX="$PWD/prefix" +if [ -d ../dockerfiles ]; then + DOCKERFILES="$(realpath ../dockerfiles)" +else + git clone --depth=1 https://github.com/TokTok/dockerfiles "$SCRIPT_DIR/dockerfiles" + DOCKERFILES="$SCRIPT_DIR/dockerfiles" +fi 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="$DOCKERFILES/qtox/build_$dep.sh" "$SCRIPT" --arch "$SYSTEM-$ARCH" --libtype "static" --buildtype "release" --prefix "$DEP_PREFIX" --macos "10.15" popd rm -rf "external/$dep" diff --git a/other/deploy/ios.sh b/other/deploy/ios.sh index 40fdefbd21..6ff826afc4 100755 --- a/other/deploy/ios.sh +++ b/other/deploy/ios.sh @@ -4,24 +4,39 @@ set -eux -o pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -ARCH="$1" -"$SCRIPT_DIR/deps.sh" ios "$ARCH" +TARGET="$1" -export PKG_CONFIG_PATH="$PWD/prefix/lib/pkgconfig" +SYSTEM="${TARGET%%-*}" +ARCH="${TARGET#*-}" -IOS_FLAGS="-miphoneos-version-min=10.0 -arch $ARCH" +if [ -n "${CI-}" ]; then + brew install coreutils ninja yasm +fi + +"$SCRIPT_DIR/deps.sh" "$SYSTEM" "$ARCH" + +export PKG_CONFIG_PATH="$PWD/deps-prefix-$SYSTEM-$ARCH/lib/pkgconfig" -if [ "$ARCH" = "i386" ] || [ "$ARCH" = "x86_64" ]; then +if [ "$SYSTEM" = "ios" ]; then + XC_SDK="iphoneos" + TARGET_IPHONE_SIMULATOR=OFF + IOS_FLAGS="-miphoneos-version-min=10.0 -arch $ARCH" +elif [ "$SYSTEM" = "iphonesimulator" ]; then XC_SDK="iphonesimulator" + TARGET_IPHONE_SIMULATOR=ON + IOS_FLAGS="-arch $ARCH" else - XC_SDK="iphoneos" + echo "Unexpected system $SYSTEM" + exit 1 fi +BUILD_DIR="_build-$SYSTEM-$ARCH" + # Build for iOS 10 cmake \ - -B _build \ + -B "$BUILD_DIR" \ -G Ninja \ - -DCMAKE_INSTALL_PREFIX="$PWD/toxcore-ios-$ARCH" \ + -DCMAKE_INSTALL_PREFIX="$PWD/toxcore-$SYSTEM-$ARCH" \ -DCMAKE_BUILD_TYPE=Release \ -DENABLE_STATIC=OFF \ -DENABLE_SHARED=ON \ @@ -38,5 +53,5 @@ cmake \ -DCMAKE_OSX_SYSROOT="$(xcrun --sdk "$XC_SDK" --show-sdk-path)" \ -DCMAKE_OSX_ARCHITECTURES="$ARCH" -cmake --build _build -cmake --install _build +cmake --build "$BUILD_DIR" +cmake --install "$BUILD_DIR" diff --git a/other/deploy/ios/LICENSE b/other/deploy/ios/LICENSE new file mode 120000 index 0000000000..5853aaea53 --- /dev/null +++ b/other/deploy/ios/LICENSE @@ -0,0 +1 @@ +../../../LICENSE \ No newline at end of file diff --git a/other/deploy/ios/make_framework b/other/deploy/ios/make_framework new file mode 100755 index 0000000000..ae959f1077 --- /dev/null +++ b/other/deploy/ios/make_framework @@ -0,0 +1,71 @@ +#!/bin/bash + +set -eux -o pipefail + +# Make a Tox.xcframework for iOS, iPhone simulator, and macOS from the nightly builds. +for arch in arm64 armv7 armv7s; do + rm -rf "ios/$arch" + mkdir -p "ios/$arch" + tar -C "ios/$arch" --strip-components=1 -zxf \ + <(curl -L "https://github.com/TokTok/c-toxcore/releases/download/nightly/toxcore-nightly-ios-$arch.tar.gz") +done + +for arch in arm64 x86_64; do + rm -rf "iphonesimulator/$arch" + mkdir -p "iphonesimulator/$arch" + tar -C "iphonesimulator/$arch" --strip-components=1 -zxf \ + <(curl -L "https://github.com/TokTok/c-toxcore/releases/download/nightly/toxcore-nightly-iphonesimulator-$arch.tar.gz") +done + +for arch in arm64 x86_64; do + rm -rf "macos/$arch" + mkdir -p "macos/$arch" + tar -C "macos/$arch" --strip-components=1 -zxf \ + <(curl -L "https://github.com/TokTok/c-toxcore/releases/download/nightly/toxcore-nightly-macos-$arch.tar.gz") +done + +# Make a Tox.framework for iOS. +rm -rf ios/Tox.framework +mkdir -p ios/Tox.framework +cp -r ios/arm64/include/tox ios/Tox.framework/Headers +lipo -create -output ios/Tox.framework/Tox ios/arm64/lib/libtoxcore.dylib ios/armv7/lib/libtoxcore.dylib ios/armv7s/lib/libtoxcore.dylib +install_name_tool -id @rpath/Tox.framework/Tox ios/Tox.framework/Tox + +# Make a Tox.framework for iPhone simulator. +rm -rf iphonesimulator/Tox.framework +mkdir -p iphonesimulator/Tox.framework +cp -r iphonesimulator/arm64/include/tox iphonesimulator/Tox.framework/Headers +lipo -create -output iphonesimulator/Tox.framework/Tox iphonesimulator/arm64/lib/libtoxcore.dylib iphonesimulator/x86_64/lib/libtoxcore.dylib +install_name_tool -id @rpath/Tox.framework/Tox iphonesimulator/Tox.framework/Tox + +# Make a Tox.framework for macOS. +rm -rf macos/Tox.framework +mkdir -p macos/Tox.framework +cp -r macos/arm64/include/tox macos/Tox.framework/Headers +lipo -create -output macos/Tox.framework/Tox macos/arm64/lib/libtoxcore.dylib macos/x86_64/lib/libtoxcore.dylib +install_name_tool -id @rpath/Tox.framework/Tox macos/Tox.framework/Tox + +# Make a Tox.xcframework for iOS, iPhone simulator, and macOS. +rm -rf Tox.xcframework +xcodebuild -create-xcframework -framework ios/Tox.framework -framework iphonesimulator/Tox.framework -framework macos/Tox.framework -output Tox.xcframework + +# Test the Tox.xcframework. +cat >smoke-test.c <<'EOF' +#include + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdocumentation-deprecated-sync" +#include +#pragma GCC diagnostic pop + +int main(void) { + Tox *tox = tox_new(NULL, NULL); + if (tox == NULL) { + fprintf(stderr, "tox_new failed\n"); + return 1; + } + tox_kill(tox); + return 0; +} +EOF +pod lib lint toxcore.podspec diff --git a/other/deploy/ios/toxcore.podspec b/other/deploy/ios/toxcore.podspec new file mode 100644 index 0000000000..c46735056a --- /dev/null +++ b/other/deploy/ios/toxcore.podspec @@ -0,0 +1,24 @@ +Pod::Spec.new do |s| + s.name = "toxcore" + s.version = "0.2.20" + s.summary = "Cocoapods wrapper for toxcore" + s.homepage = "https://github.com/TokTok/c-toxcore" + s.license = 'GPLv3' + s.author = { "Iphigenia Df" => "iphydf@gmail.com" } + s.source = { + :git => "https://github.com/TokTok/c-toxcore.git", + :tag => s.version.to_s, + :submodules => true + } + + s.requires_arc = false + + s.ios.deployment_target = '12.0' + s.osx.deployment_target = '10.15' + + s.vendored_frameworks = 'Tox.xcframework' + s.xcconfig = { 'FRAMEWORK_SEARCH_PATHS' => '"${PODS_ROOT}"' } + s.test_spec 'Tests' do |test_spec| + test_spec.source_files = 'smoketest.c' + end +end diff --git a/other/deploy/linux.sh b/other/deploy/linux.sh index 13ea78e24f..16b537e0e6 100755 --- a/other/deploy/linux.sh +++ b/other/deploy/linux.sh @@ -7,7 +7,7 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" ARCH="$1" "$SCRIPT_DIR/deps.sh" linux "$ARCH" -export PKG_CONFIG_PATH="$PWD/prefix/lib/pkgconfig" +export PKG_CONFIG_PATH="$PWD/deps-prefix-linux-$ARCH/lib/pkgconfig" # Build cmake \ diff --git a/other/deploy/macos.sh b/other/deploy/macos.sh index 859866d60d..c00a70707d 100755 --- a/other/deploy/macos.sh +++ b/other/deploy/macos.sh @@ -4,10 +4,14 @@ set -eux -o pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +if [ -n "${CI-}" ]; then + brew install coreutils ninja yasm +fi + ARCH="$1" "$SCRIPT_DIR/deps.sh" macos "$ARCH" -export PKG_CONFIG_PATH="$PWD/prefix/lib/pkgconfig" +export PKG_CONFIG_PATH="$PWD/deps-prefix-macos-$ARCH/lib/pkgconfig" # Build for macOS cmake \