Skip to content

Commit db5fcae

Browse files
committed
Use lipo to combine library built for M1 and x86 targets before creating XCFramework
1 parent 67e4a7c commit db5fcae

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: Build libgit2 XCFrameworks for release
22
on: [push]
3+
# on: workflow_dispatch
34
jobs:
45
build-libgit2-xcframework:
56
runs-on: macos-latest

build-libgit2-framework.sh

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
export REPO_ROOT=`pwd`
22
export PATH=$PATH:$REPO_ROOT/tools/bin
33

4-
# There are limitations in `xcodebuild` command that disallow maccatalyst and maccatalyst-arm64
5-
# to be used simultaneously: Doing that and we will get an error
6-
#
7-
# Both ios-x86_64-maccatalyst and ios-arm64-maccatalyst represent two equivalent library definitions.
8-
#
9-
# To provide binary for both, `lipo` is probably needed.
10-
# Likewise, `maccatalyst` and `macosx` cannot be used together. So unfortunately for now, one will
11-
# needs multiple xcframeworks for x86_64-based and ARM-based Mac development computer.
12-
13-
# maccatalyst-arm64 macosx macosx-arm64
14-
#if [[ $(arch) == 'arm64' ]]; then
15-
AVAILABLE_PLATFORMS=(iphoneos iphonesimulator-arm64 maccatalyst-arm64)
16-
#else
17-
#AVAILABLE_PLATFORMS=(iphoneos iphonesimulator maccatalyst)
18-
#fi
4+
# List of platforms-architecture that we support
5+
# Note that there are limitations in `xcodebuild` command that disallows `maccatalyst` and `macosx` (native macOS lib) in the same xcframework.
6+
AVAILABLE_PLATFORMS=(iphoneos iphonesimulator iphonesimulator-arm64 maccatalyst maccatalyst-arm64) # macosx macosx-arm64
7+
8+
# List of frameworks included in the XCFramework (= AVAILABLE_PLATFORMS without architecture specifications)
9+
XCFRAMEWORK_PLATFORMS=(iphoneos iphonesimulator maccatalyst)
10+
11+
# List of platforms that need to be merged using lipo due to presence of multiple architectures
12+
LIPO_PLATFORMS=(iphonesimulator maccatalyst)
1913

2014
# Download build tools
2115
test -d tools || wget -q https://github.com/light-tech/LLVM-On-iOS/releases/download/llvm12.0.0/tools.tar.xz
@@ -57,10 +51,10 @@ function setup_variables() {
5751
SYSROOT=`xcodebuild -version -sdk iphonesimulator Path`
5852
CMAKE_ARGS+=(-DCMAKE_OSX_ARCHITECTURES=$ARCH -DCMAKE_OSX_SYSROOT=$SYSROOT);;
5953

60-
"iphonesimulator-arm64")
61-
ARCH=arm64
62-
SYSROOT=`xcodebuild -version -sdk iphonesimulator Path`
63-
CMAKE_ARGS+=(-DCMAKE_OSX_ARCHITECTURES=$ARCH -DCMAKE_OSX_SYSROOT=$SYSROOT);;
54+
"iphonesimulator-arm64")
55+
ARCH=arm64
56+
SYSROOT=`xcodebuild -version -sdk iphonesimulator Path`
57+
CMAKE_ARGS+=(-DCMAKE_OSX_ARCHITECTURES=$ARCH -DCMAKE_OSX_SYSROOT=$SYSROOT);;
6458

6559
"maccatalyst")
6660
ARCH=x86_64
@@ -123,7 +117,7 @@ function build_openssl() {
123117

124118
"iphonesimulator"|"iphonesimulator-arm64")
125119
TARGET_OS=iossimulator-xcrun
126-
export CFLAGS="-isysroot $SYSROOT";;
120+
export CFLAGS="-isysroot $SYSROOT -arch $ARCH";;
127121

128122
"maccatalyst"|"maccatalyst-arm64")
129123
TARGET_OS=darwin64-$ARCH-cc
@@ -237,8 +231,15 @@ for p in ${AVAILABLE_PLATFORMS[@]}; do
237231
libtool -static -o libgit2.a lib/*.a
238232
done
239233

234+
# Merge the libgit2.a for iphonesimulator & iphonesimulator-arm64 as well as maccatalyst & maccatalyst-arm64 using lipo
235+
for p in ${LIPO_PLATFORMS[@]}; do
236+
cd $REPO_ROOT/install/$p
237+
lipo libgit2.a ../$p-arm64/libgit2.a -output libgit2_all_archs.a -create
238+
test -f libgit2_all_archs.a && rm libgit2.a && mv libgit2_all_archs.a libgit2.a
239+
done
240+
240241
# Build raw libgit2 XCFramework for Objective-C usage
241-
build_xcframework libgit2 ${AVAILABLE_PLATFORMS[@]}
242+
build_xcframework libgit2 ${XCFRAMEWORK_PLATFORMS[@]}
242243
zip -r libgit2.xcframework.zip libgit2.xcframework/
243244

244245
# Build Clibgit2 XCFramework for use with SwiftGit2

0 commit comments

Comments
 (0)