Skip to content

Commit e7990d2

Browse files
authored
Update create_frameworks.sh
1 parent 279cd3e commit e7990d2

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

scripts/create_frameworks.sh

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ function usage() {
1313
echo ""
1414
echo "Usage: $0 --directory=<dir> --framework=<lib> [--output=<output>]"
1515
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'"
1717
echo " 'target' is the name of the target library."
1818
echo " 'lib1,lib2' is a comma-separated list of input libraries."
1919
echo " 'headers' is an optional path to a directory with headers."
20+
echo " ':swiftmodule' is an optional module name to embed its .swiftmodule folder"
2021
echo " --output: Optional output directory. Defaults to the current directory."
2122
echo ""
2223
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"
2425
exit 1
2526
}
2627

@@ -58,6 +59,8 @@ create_xcframework() {
5859
libraries_list=$(echo "$1" | cut -d: -f2 | tr ',' '\n')
5960
local headers_directory
6061
headers_directory=$(echo "$1" | cut -d: -f3)
62+
local swift_module
63+
swift_module=$(echo "$1" | cut -d: -f4)
6164
local dir
6265
local libraries=()
6366
local merged_libs=()
@@ -117,8 +120,36 @@ create_xcframework() {
117120

118121
echo -e "\nCreating XCFramework ${xcframework}"
119122

123+
# Create the new .xcframework.
120124
xcodebuild -create-xcframework "${libraries[@]}" -output "${xcframework}"
121125

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+
122153
echo -e "\nDeleting intermediate libraries:"
123154
for merged_lib in "${merged_libs[@]}"; do
124155
if [[ -f "${merged_lib}" ]]; then

0 commit comments

Comments
 (0)