Skip to content

Instantly share code, notes, and snippets.

@sunnyyoung
Last active March 22, 2024 10:34
Show Gist options
  • Save sunnyyoung/75241cc8a071031e8534fad329ca083a to your computer and use it in GitHub Desktop.
Save sunnyyoung/75241cc8a071031e8534fad329ca083a to your computer and use it in GitHub Desktop.
#!/bin/bash
# shellcheck disable=2016,2043,2044,2046,2086
VERSION="4.33"
SRC=$(pwd)/libev
DST=$(pwd)/libev.builds
PLATFORMS="macosx iphoneos iphonesimulator appletvos appletvsimulator xros xrsimulator"
set -e
echo "Checking out libev..."
if [ -d "$SRC" ] || [ -d "$DST" ]; then
echo "Source or Destination folder not empty." && exit 1
else
curl "http://dist.schmorp.de/libev/libev-$VERSION.tar.gz" | tar -xz && mv libev-$VERSION libev
fi
for PLATFORM in $PLATFORMS; do
case $PLATFORM in
macosx)
ARCHS="arm64 x86_64"
EXTRA_CFLAGS="-O3 -mmacosx-version-min=10.11"
;;
iphoneos)
ARCHS="arm64"
EXTRA_CFLAGS="-O3 -mios-version-min=9.0"
;;
iphonesimulator)
ARCHS="arm64 x86_64"
EXTRA_CFLAGS="-O3 -mios-simulator-version-min=9.0"
;;
appletvos)
ARCHS="arm64"
EXTRA_CFLAGS="-O3 -mtvos-version-min=9.0"
;;
appletvsimulator)
ARCHS="arm64 x86_64"
EXTRA_CFLAGS="-O3 -mtvos-simulator-version-min=9.0"
;;
xros)
ARCHS="arm64"
EXTRA_CFLAGS="-O3"
;;
xrsimulator)
ARCHS="arm64 x86_64"
EXTRA_CFLAGS="-O3"
;;
esac
for ARCH in $ARCHS; do
echo "Building for $PLATFORM-$ARCH..."
PREFIX="$DST/$PLATFORM-$ARCH"
mkdir -p "$PREFIX"
pushd "$PREFIX"
CFLAGS="-isysroot $(xcrun --sdk $PLATFORM --show-sdk-path) -arch $ARCH $EXTRA_CFLAGS" \
"$SRC"/configure --srcdir="$SRC" --host="${ARCH/arm64/arm}"-apple-darwin --prefix="$PREFIX" --disable-shared
make install
popd
done
mkdir -p "$DST/libs/$PLATFORM"
lipo -create $(find $DST/$PLATFORM-*/lib -name libev.a) -output "$DST/libs/$PLATFORM/libev.a"
done
echo "Copying headers..."
mkdir -p "$DST/include"
rsync -av --delete "$SRC"/{ev.h,ev++.h,event.h} "$DST/include"
echo "Creating xcframework..."
pushd "$DST"
XCFRAMEWORK_ARGS=""
for PLATFORM in $PLATFORMS; do
XCFRAMEWORK_ARGS="$XCFRAMEWORK_ARGS -library $DST/libs/$PLATFORM/libev.a -headers $DST/include"
done
xcodebuild -create-xcframework $XCFRAMEWORK_ARGS -output libev.xcframework
zip -ry9 libev.xcframework.zip libev.xcframework
popd
echo "Creating framework..."
echo "
name: libev
options:
deploymentTarget:
macOS: 10.11
iOS: 9.0
tvOS: 9.0
visionOS: 1.0
targets:
ev:
type: framework
supportedDestinations: [
macOS,
iOS,
tvOS,
visionOS
]
settings:
DEFINES_MODULE: NO
SKIP_INSTALL: NO
CODE_SIGNING_ALLOWED: NO
GENERATE_INFOPLIST_FILE: YES
BUILD_LIBRARY_FOR_DISTRIBUTION: YES
OTHER_LDFLAGS: -all_load
MARKETING_VERSION: $VERSION
PRODUCT_BUNDLE_IDENTIFIER: framework.ev
sources:
- path: include
buildPhase: headers
headerVisibility: public
dependencies:
- framework: libev.xcframework
aggregateTargets:
aggregate:
buildScripts:
- name: Create xcframework
script: |
xcodebuild archive \
-scheme ev \
-destination 'generic/platform=macOS' \
-archivePath Archives/ev_macOS.xcarchive
xcodebuild archive \
-scheme ev \
-destination 'generic/platform=iOS' \
-archivePath Archives/ev_iOS.xcarchive
xcodebuild archive \
-scheme ev \
-destination 'generic/platform=iOS Simulator' \
-archivePath Archives/ev_iOS_Simulator.xcarchive
xcodebuild archive \
-scheme ev \
-destination 'generic/platform=tvOS' \
-archivePath Archives/ev_tvOS.xcarchive
xcodebuild archive \
-scheme ev \
-destination 'generic/platform=tvOS Simulator' \
-archivePath Archives/ev_tvOS_Simulator.xcarchive
xcodebuild archive \
-scheme ev \
-destination 'generic/platform=visionOS' \
-archivePath Archives/ev_visionOS.xcarchive
xcodebuild archive \
-scheme ev \
-destination 'generic/platform=visionOS Simulator' \
-archivePath Archives/ev_visionOS_Simulator.xcarchive
xcodebuild -create-xcframework \
-archive 'Archives/ev_macOS.xcarchive' -framework ev.framework \
-archive 'Archives/ev_iOS.xcarchive' -framework ev.framework \
-archive 'Archives/ev_iOS_Simulator.xcarchive' -framework ev.framework \
-archive 'Archives/ev_tvOS.xcarchive' -framework ev.framework \
-archive 'Archives/ev_tvOS_Simulator.xcarchive' -framework ev.framework \
-archive 'Archives/ev_visionOS.xcarchive' -framework ev.framework \
-archive 'Archives/ev_visionOS_Simulator.xcarchive' -framework ev.framework \
-output ev.xcframework
" > "$DST/project.yml"
pushd "$DST"
xcodegen && xcodebuild build -scheme aggregate
zip -ry9 ev.xcframework.zip ev.xcframework
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment