Last active
May 27, 2024 06:50
-
-
Save sunnyyoung/f1a35454edf2cd5efdba53057179cacd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# shellcheck disable=SC2016,SC2046,SC2086 | |
VERSION="3.6.0" | |
SRC=$(pwd)/mbedtls | |
DST=$(pwd)/mbedtls.builds | |
PLATFORMS="macosx iphoneos iphonesimulator appletvos appletvsimulator xros xrsimulator" | |
set -e | |
echo "Checking out mbedtls..." | |
if [ -d "$SRC" ] || [ -d "$DST" ]; then | |
echo "Source or Destination folder not empty." && exit 1 | |
else | |
git clone https://github.com/Mbed-TLS/mbedtls --depth 1 --branch v$VERSION | |
git -C "$SRC" submodule update --init | |
fi | |
for PLATFORM in $PLATFORMS; do | |
case $PLATFORM in | |
macosx) | |
DEPLOYMENT_TARGET=10.11 | |
ARCHS="x86_64;arm64" | |
;; | |
iphoneos) | |
DEPLOYMENT_TARGET=9.0 | |
ARCHS="arm64" | |
;; | |
iphonesimulator) | |
DEPLOYMENT_TARGET=9.0 | |
ARCHS="x86_64;arm64" | |
;; | |
appletvos) | |
DEPLOYMENT_TARGET=9.0 | |
ARCHS="arm64" | |
;; | |
appletvsimulator) | |
DEPLOYMENT_TARGET=9.0 | |
ARCHS="x86_64;arm64" | |
;; | |
xros) | |
DEPLOYMENT_TARGET=1.0 | |
ARCHS="arm64" | |
;; | |
xrsimulator) | |
DEPLOYMENT_TARGET=1.0 | |
ARCHS="x86_64;arm64" | |
;; | |
esac | |
echo "Building for $PLATFORM..." | |
cmake \ | |
-DMBEDTLS_FATAL_WARNINGS=OFF \ | |
-DENABLE_PROGRAMS=OFF \ | |
-DENABLE_TESTING=OFF \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DCMAKE_OSX_SYSROOT="$PLATFORM" \ | |
-DCMAKE_OSX_DEPLOYMENT_TARGET="$DEPLOYMENT_TARGET" \ | |
-DCMAKE_OSX_ARCHITECTURES="$ARCHS" \ | |
-GXcode \ | |
-S "$SRC" \ | |
-B "$DST/$PLATFORM" | |
pushd "$DST/$PLATFORM" | |
xcodebuild \ | |
-project "mbed TLS.xcodeproj" \ | |
-target ALL_BUILD \ | |
-configuration Release \ | |
CODE_SIGNING_ALLOWED=NO \ | |
GCC_WARN_INHIBIT_ALL_WARNINGS=YES \ | |
clean \ | |
build | |
cmake --install . --prefix . | |
popd | |
mkdir -p "$DST/libs/$PLATFORM" | |
libtool -static $(find $DST/$PLATFORM/lib/*.a) -o "$DST/libs/$PLATFORM/libmbedtls.a" | |
done | |
echo "Copying headers..." | |
rsync -a \ | |
--include="*/" \ | |
--include="*.h" \ | |
--exclude='*' \ | |
"$SRC/include" \ | |
"$DST" | |
echo "Creating xcframework..." | |
pushd "$DST" | |
XCFRAMEWORK_ARGS="" | |
for PLATFORM in $PLATFORMS; do | |
XCFRAMEWORK_ARGS="$XCFRAMEWORK_ARGS -library $DST/libs/$PLATFORM/libmbedtls.a -headers include" | |
done | |
xcodebuild -create-xcframework $XCFRAMEWORK_ARGS -output libmbedtls.xcframework | |
zip -ry9 libmbedtls.xcframework.zip libmbedtls.xcframework | |
popd | |
echo "Creating framework..." | |
echo " | |
name: mbedtls | |
options: | |
deploymentTarget: | |
macOS: 10.11 | |
iOS: 9.0 | |
tvOS: 9.0 | |
visionOS: 1.0 | |
targets: | |
mbedtls: | |
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.mbedtls | |
sources: | |
- path: include | |
buildPhase: headers | |
headerVisibility: public | |
excludes: | |
- '**/build_info.h' | |
dependencies: | |
- framework: libmbedtls.xcframework | |
aggregateTargets: | |
aggregate: | |
buildScripts: | |
- name: Create xcframework | |
script: | | |
xcodebuild archive \ | |
-scheme mbedtls \ | |
-destination 'generic/platform=macOS' \ | |
-archivePath Archives/mbedtls_macOS.xcarchive | |
xcodebuild archive \ | |
-scheme mbedtls \ | |
-destination 'generic/platform=iOS' \ | |
-archivePath Archives/mbedtls_iOS.xcarchive | |
xcodebuild archive \ | |
-scheme mbedtls \ | |
-destination 'generic/platform=iOS Simulator' \ | |
-archivePath Archives/mbedtls_iOS_Simulator.xcarchive | |
xcodebuild archive \ | |
-scheme mbedtls \ | |
-destination 'generic/platform=tvOS' \ | |
-archivePath Archives/mbedtls_tvOS.xcarchive | |
xcodebuild archive \ | |
-scheme mbedtls \ | |
-destination 'generic/platform=tvOS Simulator' \ | |
-archivePath Archives/mbedtls_tvOS_Simulator.xcarchive | |
xcodebuild archive \ | |
-scheme mbedtls \ | |
-destination 'generic/platform=visionOS' \ | |
-archivePath Archives/mbedtls_visionOS.xcarchive | |
xcodebuild archive \ | |
-scheme mbedtls \ | |
-destination 'generic/platform=visionOS Simulator' \ | |
-archivePath Archives/mbedtls_visionOS_Simulator.xcarchive | |
xcodebuild -create-xcframework \ | |
-archive 'Archives/mbedtls_macOS.xcarchive' -framework mbedtls.framework \ | |
-archive 'Archives/mbedtls_iOS.xcarchive' -framework mbedtls.framework \ | |
-archive 'Archives/mbedtls_iOS_Simulator.xcarchive' -framework mbedtls.framework \ | |
-archive 'Archives/mbedtls_tvOS.xcarchive' -framework mbedtls.framework \ | |
-archive 'Archives/mbedtls_tvOS_Simulator.xcarchive' -framework mbedtls.framework \ | |
-archive 'Archives/mbedtls_visionOS.xcarchive' -framework mbedtls.framework \ | |
-archive 'Archives/mbedtls_visionOS_Simulator.xcarchive' -framework mbedtls.framework \ | |
-output mbedtls.xcframework | |
" > "$DST/project.yml" | |
pushd "$DST" | |
xcodegen && xcodebuild build -scheme aggregate | |
zip -ry9 mbedtls.xcframework.zip mbedtls.xcframework | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment