@@ -13,14 +13,15 @@ function usage() {
13
13
echo " "
14
14
echo " Usage: $0 --directory=<dir> --framework=<lib> [--output=<output>]"
15
15
echo " --directory: Directory containing the libs"
16
- echo " --framework: Framework to create in the format 'target:lib1,lib2:headers'"
16
+ echo " --framework: Framework to create in the format 'target:lib1,lib2:headers:swiftmodule '"
17
17
echo " 'target' is the name of the target library."
18
18
echo " 'lib1,lib2' is a comma-separated list of input libraries."
19
19
echo " 'headers' is an optional path to a directory with headers."
20
+ echo " ':swiftmodule' is an optional module name to embed its .swiftmodule folder"
20
21
echo " --output: Optional output directory. Defaults to the current directory."
21
22
echo " "
22
23
echo " Example:"
23
- echo " $0 --directory=ios-arm64 --directory=ios-arm64-simulator --framework=\" mylib:lib1.a,lib2.a:include\" --output=output/dir"
24
+ echo " $0 --directory=ios-arm64 --directory=ios-arm64-simulator --framework=\" mylib:lib1.a,lib2.a:include:MyModule \" --output=output/dir"
24
25
exit 1
25
26
}
26
27
@@ -58,6 +59,8 @@ create_xcframework() {
58
59
libraries_list=$( echo " $1 " | cut -d: -f2 | tr ' ,' ' \n' )
59
60
local headers_directory
60
61
headers_directory=$( echo " $1 " | cut -d: -f3)
62
+ local swift_module
63
+ swift_module=$( echo " $1 " | cut -d: -f4)
61
64
local dir
62
65
local libraries=()
63
66
local merged_libs=()
@@ -117,8 +120,36 @@ create_xcframework() {
117
120
118
121
echo -e " \nCreating XCFramework ${xcframework} "
119
122
123
+ # Create the new .xcframework.
120
124
xcodebuild -create-xcframework " ${libraries[@]} " -output " ${xcframework} "
121
125
126
+ # Copy the .swiftmodule files into the .xcframework if applicable.
127
+ if [[ -n " $swift_module " ]]; then
128
+ echo -e " \nCopying Swift module ${swift_module} .swiftmodule into ${xcframework} "
129
+ for dir in " ${directories[@]} " ; do
130
+ local module_source_dir=" ${dir} /${swift_module} .swiftmodule"
131
+ if [ ! -d " $module_source_dir " ]; then
132
+ echo " Swiftmodule directory ${module_source_dir} does not exist"
133
+ exit 1
134
+ fi
135
+ local swiftmodule_file
136
+ swiftmodule_file=$( find " $module_source_dir " -maxdepth 1 -type f -name ' *.swiftmodule' | head -n1)
137
+ if [[ -z " $swiftmodule_file " ]]; then
138
+ echo " No .swiftmodule file found in ${module_source_dir} "
139
+ exit 1
140
+ fi
141
+
142
+ local dir_suffix
143
+ dir_suffix=$( echo " $dir " | cut -d' /' -f1 | tr ' [:upper:]' ' [:lower:]' | sed ' s/[\/\.~]/_/g' )
144
+ for slice_path in " ${xcframework} /${dir_suffix} -" * ; do
145
+ if [ -d " ${slice_path} /Headers" ]; then
146
+ echo " - Copying ${swiftmodule_file##*/ } to ${slice_path} /Headers/${swift_module} .swiftmodule"
147
+ cp " ${swiftmodule_file} " " ${slice_path} /Headers/${swift_module} .swiftmodule"
148
+ fi
149
+ done
150
+ done
151
+ fi
152
+
122
153
echo -e " \nDeleting intermediate libraries:"
123
154
for merged_lib in " ${merged_libs[@]} " ; do
124
155
if [[ -f " ${merged_lib} " ]]; then
0 commit comments