Skip to content

Commit

Permalink
chore: Support arm64 iphone simulator.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Jan 28, 2025
1 parent aa0e2a8 commit 1068501
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 41 deletions.
28 changes: 11 additions & 17 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ 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:
Expand Down Expand Up @@ -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: 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')
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -232,8 +228,6 @@ 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:
Expand Down
4 changes: 4 additions & 0 deletions other/deploy/android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 13 additions & 12 deletions other/deploy/deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 --branch=simulator --depth=1 https://github.com/iphydf/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"
Expand Down
35 changes: 25 additions & 10 deletions other/deploy/ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 26 in other/deploy/ios.sh

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

other/deploy/ios.sh#L26

TARGET_IPHONE_SIMULATOR appears unused. Verify use (or export if used externally).
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 \
Expand All @@ -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"
1 change: 1 addition & 0 deletions other/deploy/ios/LICENSE
71 changes: 71 additions & 0 deletions other/deploy/ios/make_framework
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdocumentation-deprecated-sync"
#include <tox/tox.h>
#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
24 changes: 24 additions & 0 deletions other/deploy/ios/toxcore.podspec
Original file line number Diff line number Diff line change
@@ -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" => "[email protected]" }
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
2 changes: 1 addition & 1 deletion other/deploy/linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
6 changes: 5 additions & 1 deletion other/deploy/macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit 1068501

Please sign in to comment.