forked from mohamed-3amer/spm-create-xcframework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_xcframework.sh
112 lines (93 loc) · 3.42 KB
/
create_xcframework.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
# Exits on error
set -e
# Constants
ARCHIVE_BASE_PATH="XCFramework_Archives"
# Rewrite Package.swift so that it declaras dynamic libraries, since the approach does not work with static libraries
perl -i -p0e 's/type: .static,//g' Package.swift
perl -i -p0e 's/type: .dynamic,//g' Package.swift
perl -i -p0e 's/(library[^,]*,)/$1 type: .dynamic,/g' Package.swift
# Read the command line arguments target, zip-version, and output-path
while [[ "$#" -gt 0 ]]; do
case $1 in
-target)
TARGET_NAME=$2
shift
;;
-zip-version)
ZIP_VERSION=$2
shift
;;
-output-path)
OUTPUT_PATH=$2
shift
;;
*)
TARGET_NAME=$1
;;
esac
shift
done
if [ -z "$OUTPUT_PATH" ]
then
OUTPUT_PATH="."
fi
XCFRAMEWORK_FILE_NAME="${TARGET_NAME}"
OUTPUT_FILE_NAME="${TARGET_NAME}-${ZIP_VERSION}"
# Archive the target for all platforms that we plan to support
for PLATFORM in "iOS" "iOS Simulator"; do
case $PLATFORM in
"iOS")
RELEASE_FOLDER="Release-iphoneos"
;;
"iOS Simulator")
RELEASE_FOLDER="Release-iphonesimulator"
;;
esac
ARCHIVE_PATH=$ARCHIVE_BASE_PATH/$RELEASE_FOLDER
xcodebuild archive -workspace .swiftpm/xcode/package.xcworkspace -scheme $TARGET_NAME \
-destination "generic/platform=$PLATFORM" \
-archivePath $ARCHIVE_PATH \
-derivedDataPath ".build" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
FRAMEWORK_PATH="$ARCHIVE_PATH.xcarchive/Products/usr/local/lib/$TARGET_NAME.framework"
MODULES_PATH="$FRAMEWORK_PATH/Modules"
mkdir -p $MODULES_PATH
BUILD_PRODUCTS_PATH=".build/Build/Intermediates.noindex/ArchiveIntermediates/$TARGET_NAME/BuildProductsPath"
RELEASE_PATH="$BUILD_PRODUCTS_PATH/$RELEASE_FOLDER"
SWIFT_MODULE_PATH="$RELEASE_PATH/$TARGET_NAME.swiftmodule"
RESOURCES_BUNDLE_PATH="$RELEASE_PATH/${TARGET_NAME}_${TARGET_NAME}.bundle"
# Copy Swift modules
if [ -d $SWIFT_MODULE_PATH ]
then
cp -r $SWIFT_MODULE_PATH $MODULES_PATH
else
# In case there are no modules, assume C/ObjC library and create module map
echo "module $TARGET_NAME { export * }" > $MODULES_PATH/module.modulemap
# TODO: Copy headers
fi
# Copy resources bundle, if exists
if [ -e $RESOURCES_BUNDLE_PATH ]
then
cp -r $RESOURCES_BUNDLE_PATH $FRAMEWORK_PATH
fi
done
# Create and save the XCFramework
xcodebuild -create-xcframework \
-framework $ARCHIVE_BASE_PATH/Release-iphoneos.xcarchive/Products/usr/local/lib/$TARGET_NAME.framework \
-framework $ARCHIVE_BASE_PATH/Release-iphonesimulator.xcarchive/Products/usr/local/lib/$TARGET_NAME.framework \
-output $OUTPUT_PATH/$XCFRAMEWORK_FILE_NAME.xcframework
echo "XCFramework created successuflly at the output path."
# Zip the XCFRamework
echo "Start zipping XCFramework file..."
cd $OUTPUT_PATH; zip -r $OUTPUT_FILE_NAME.zip $XCFRAMEWORK_FILE_NAME.xcframework
rm -r $XCFRAMEWORK_FILE_NAME.xcframework
cd -
echo "XCFramework file zipped successuflly at the output path."
# Compute and save the checksum
echo "Start computing the checksum for the zipped XCFramework..."
CHECKSUM=$(swift package compute-checksum $OUTPUT_PATH/$OUTPUT_FILE_NAME.zip)
echo $CHECKSUM > $OUTPUT_PATH/$OUTPUT_FILE_NAME.sha256
echo "Checksum: ${CHECKSUM}"
echo "Checksum saved successuflly at the output path."