Skip to content

Commit

Permalink
chore: add catalyst
Browse files Browse the repository at this point in the history
  • Loading branch information
jerson committed May 24, 2024
1 parent 82e59fd commit 75f8f85
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
53 changes: 36 additions & 17 deletions Makefile.ios
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,64 @@ binding_ios: binding_ios_arm64 binding_ios_x86_64_sim
cp $(IOS_BINDING_OUTPUT)/arm64/*.h $(IOS_BINDING_OUTPUT)
rm -rf $(IOS_BINDING_OUTPUT)/arm64 $(IOS_BINDING_OUTPUT)/x86_64_sim $(IOS_BINDING_OUTPUT)/armv7

binding_ios_test: binding_ios_arm64 binding_ios_x86_64_sim binding_ios_arm64_sim
mkdir -p $(IOS_BINDING_OUTPUT)/sim
lipo $(IOS_BINDING_OUTPUT)/x86_64_sim/$(IOS_BINDING_NAME) $(IOS_BINDING_OUTPUT)/arm64_sim/$(IOS_BINDING_NAME) -create -output $(IOS_BINDING_OUTPUT)/sim/$(IOS_BINDING_NAME)
lipo $(IOS_BINDING_OUTPUT)/sim/$(IOS_BINDING_NAME) $(IOS_BINDING_OUTPUT)/arm64/$(IOS_BINDING_NAME) -create -output $(IOS_BINDING_OUTPUT)/$(IOS_BINDING_NAME)
cp $(IOS_BINDING_OUTPUT)/arm64/*.h $(IOS_BINDING_OUTPUT)
rm -rf $(IOS_BINDING_OUTPUT)/arm64 $(IOS_BINDING_OUTPUT)/x86_64_sim $(IOS_BINDING_OUTPUT)/arm64_sim

binding_ios_xcframework: binding_ios_arm64 binding_ios_x86_64_sim binding_ios_arm64_sim
mkdir -p $(IOS_BINDING_OUTPUT)/sim
lipo $(IOS_BINDING_OUTPUT)/x86_64_sim/$(IOS_BINDING_NAME) $(IOS_BINDING_OUTPUT)/arm64_sim/$(IOS_BINDING_NAME) -create -output $(IOS_BINDING_OUTPUT)/sim/$(IOS_BINDING_NAME)
binding_ios_xcframework: binding_ios_all_iphone binding_ios_all_sim binding_ios_all_catalyst
mkdir -p $(IOS_BINDING_OUTPUT)/headers
cp $(IOS_BINDING_OUTPUT)/arm64/*.h $(IOS_BINDING_OUTPUT)/headers
rm -rf $(IOS_BINDING_OUTPUT)/Rsa.xcframework
xcodebuild -create-xcframework \
-library $(IOS_BINDING_OUTPUT)/arm64/$(IOS_BINDING_NAME) -headers $(IOS_BINDING_OUTPUT)/headers \
-library $(IOS_BINDING_OUTPUT)/sim/$(IOS_BINDING_NAME) -headers $(IOS_BINDING_OUTPUT)/headers \
-library $(IOS_BINDING_OUTPUT)/catalyst/$(IOS_BINDING_NAME) -headers $(IOS_BINDING_OUTPUT)/headers \
-output $(IOS_BINDING_OUTPUT)/Rsa.xcframework
rm -rf $(IOS_BINDING_OUTPUT)/arm64 $(IOS_BINDING_OUTPUT)/x86_64_sim $(IOS_BINDING_OUTPUT)/arm64_sim $(IOS_BINDING_OUTPUT)/sim $(IOS_BINDING_OUTPUT)/headers
rm -rf $(IOS_BINDING_OUTPUT)/arm64 $(IOS_BINDING_OUTPUT)/sim $(IOS_BINDING_OUTPUT)/catalyst $(IOS_BINDING_OUTPUT)/headers

binding_ios_arm64:
BINDING_FILE=$(IOS_OUTPUT)/arm64/$(IOS_BINDING_NAME) BUILD_MODE="c-archive" \
SDK=iphoneos CC=$(PWD)/clangwrap.sh CGO_CFLAGS="-fembed-bitcode" \
GOOS=ios GOARCH=arm64 CGO_ENABLED=1 \
binding_ios_all_iphone: binding_ios_arm64

binding_ios_all_sim: binding_ios_x86_64_sim binding_ios_arm64_sim
mkdir -p $(IOS_BINDING_OUTPUT)/sim
lipo $(IOS_BINDING_OUTPUT)/x86_64_sim/$(IOS_BINDING_NAME) $(IOS_BINDING_OUTPUT)/arm64_sim/$(IOS_BINDING_NAME) -create -output $(IOS_BINDING_OUTPUT)/sim/$(IOS_BINDING_NAME)
rm -rf $(IOS_BINDING_OUTPUT)/x86_64_sim $(IOS_BINDING_OUTPUT)/arm64_sim

binding_ios_all_catalyst: binding_ios_x86_64_catalyst binding_ios_arm64_catalyst
mkdir -p $(IOS_BINDING_OUTPUT)/catalyst
lipo $(IOS_BINDING_OUTPUT)/x86_64_catalyst/$(IOS_BINDING_NAME) $(IOS_BINDING_OUTPUT)/arm64_catalyst/$(IOS_BINDING_NAME) -create -output $(IOS_BINDING_OUTPUT)/catalyst/$(IOS_BINDING_NAME)
rm -rf $(IOS_BINDING_OUTPUT)/x86_64_catalyst $(IOS_BINDING_OUTPUT)/arm64_catalyst

binding_ios_x86_64_catalyst:
CGO_LDFLAGS="-target x86_64-apple-ios14-macabi" \
BINDING_FILE=$(IOS_OUTPUT)/x86_64_catalyst/$(IOS_BINDING_NAME) BUILD_MODE="c-archive" \
SDK=macosx CC=$(PWD)/clangwrap.sh \
GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 \
make binding

binding_ios_arm64_catalyst:
CGO_LDFLAGS="-target arm64-apple-ios14-macabi -fembed-bitcode" \
BINDING_FILE=$(IOS_OUTPUT)/arm64_catalyst/$(IOS_BINDING_NAME) BUILD_MODE="c-archive" \
SDK=macosx CC=$(PWD)/clangwrap.sh \
GOOS=darwin GOARCH=arm64 CGO_ENABLED=1 \
make binding

binding_ios_x86_64_sim:
CGO_LDFLAGS="-target arm64-apple-ios10-simulator" \
CGO_LDFLAGS="-target x86_64-apple-ios10-simulator -fembed-bitcode" \
BINDING_FILE=$(IOS_OUTPUT)/x86_64_sim/$(IOS_BINDING_NAME) BUILD_MODE="c-archive" \
SDK=iphonesimulator CC=$(PWD)/clangwrap.sh \
GOOS=ios GOARCH=amd64 CGO_ENABLED=1 \
make binding

binding_ios_arm64_sim:
CGO_LDFLAGS="-target arm64-apple-ios10-simulator" \
CGO_LDFLAGS="-target arm64-apple-ios10-simulator -fembed-bitcode" \
BINDING_FILE=$(IOS_OUTPUT)/arm64_sim/$(IOS_BINDING_NAME) BUILD_MODE="c-archive" \
SDK=iphonesimulator CC=$(PWD)/clangwrap.sh \
GOOS=ios GOARCH=arm64 CGO_ENABLED=1 \
make binding

binding_ios_arm64:
CGO_LDFLAGS="-target arm64-apple-ios10 -fembed-bitcode" \
BINDING_FILE=$(IOS_OUTPUT)/arm64/$(IOS_BINDING_NAME) BUILD_MODE="c-archive" \
SDK=iphoneos CC=$(PWD)/clangwrap.sh \
GOOS=ios GOARCH=arm64 CGO_ENABLED=1 \
make binding

binding_ios_armv7:
BINDING_FILE=$(IOS_OUTPUT)/armv7/$(IOS_BINDING_NAME) BUILD_MODE="c-archive" \
SDK=iphoneos CC=$(PWD)/clangwrap.sh CGO_CFLAGS="-fembed-bitcode" \
Expand Down
17 changes: 13 additions & 4 deletions clangwrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

SDK_PATH=`xcrun --sdk $SDK --show-sdk-path`
CLANG=`xcrun --sdk $SDK --find clang`
MIN_VERSION=10
IOS_TARGET=10
EXTRA_ARGS=""

if [ "$GOARCH" == "amd64" ]; then
CARCH="x86_64"
Expand All @@ -17,9 +18,17 @@ elif [ "$GOARCH" == "386" ]; then
fi

if [ "$SDK" = "iphoneos" ]; then
TARGET="$CARCH-apple-ios$MIN_VERSION"
EXTRA_ARGS="-fembed-bitcode -miphoneos-version-min==$IOS_TARGET"
TARGET="$CARCH-apple-ios$IOS_TARGET"
elif [ "$SDK" = "iphonesimulator" ]; then
TARGET="$CARCH-apple-ios$MIN_VERSION-simulator"
EXTRA_ARGS="-fembed-bitcode -mios-simulator-version-min=$IOS_TARGET"
TARGET="$CARCH-apple-ios$IOS_TARGET-simulator"
elif [ "$SDK" = "macosx" ]; then
IOS_TARGET=14
TARGET="$CARCH-apple-ios$IOS_TARGET-macabi"
if [ "$GOARCH" == "arm64" ]; then
EXTRA_ARGS="-fembed-bitcode"
fi
fi

exec $CLANG -arch $CARCH -target $TARGET -isysroot $SDK_PATH "$@"
exec $CLANG -target $TARGET $EXTRA_ARGS -isysroot $SDK_PATH "$@"

0 comments on commit 75f8f85

Please sign in to comment.