Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
[iOS] Improved XCFramework generation script (#1018)
Browse files Browse the repository at this point in the history
  • Loading branch information
Velin92 committed Jul 16, 2024
1 parent 1e975b1 commit 6a1960d
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 87 deletions.
41 changes: 5 additions & 36 deletions build_xcframework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,17 @@

GENERATION_PATH=.generated/ios

UNIFFI_CONFIG_FILE_PATH=bindings/wysiwyg-ffi/uniffi.toml

ARM64_LIB_PATH=target/aarch64-apple-ios/release/libuniffi_wysiwyg_composer.a
ARM64_SIM_LIB_PATH=target/aarch64-apple-ios-sim/release/libuniffi_wysiwyg_composer.a
X86_LIB_PATH=target/x86_64-apple-ios/release/libuniffi_wysiwyg_composer.a
SIM_LIB_PATH=target/ios-simulator/libuniffi_wysiwyg_composer.a

IOS_PATH=platforms/ios
TOOLS_PATH="${IOS_PATH}/tools"

SWIFT_PACKAGE_PATH="${IOS_PATH}/lib/WysiwygComposer"
SWIFT_BINDINGS_FILE_PATH="${SWIFT_PACKAGE_PATH}/Sources/WysiwygComposer/WysiwygComposer.swift"

XCFRAMEWORK_PATH="${SWIFT_PACKAGE_PATH}/WysiwygComposerFFI.xcframework"
XCFRAMEWORK_SIM_PATH="${XCFRAMEWORK_PATH}/ios-arm64_x86_64-simulator/WysiwygComposerFFI.framework"
XCFRAMEWORK_SIM_HEADERS_PATH="${XCFRAMEWORK_SIM_PATH}/Headers"
XCFRAMEWORK_SIM_MODULES_PATH="${XCFRAMEWORK_SIM_PATH}/Modules"
XCFRAMEWORK_SIM_LIBRARY_PATH="${XCFRAMEWORK_SIM_PATH}/WysiwygComposerFFI"
XCFRAMEWORK_ARM64_PATH="${XCFRAMEWORK_PATH}/ios-arm64/WysiwygComposerFFI.framework"
XCFRAMEWORK_ARM64_HEADERS_PATH="${XCFRAMEWORK_ARM64_PATH}/Headers"
XCFRAMEWORK_ARM64_MODULES_PATH="${XCFRAMEWORK_ARM64_PATH}/Modules"
XCFRAMEWORK_ARM64_LIBRARY_PATH="${XCFRAMEWORK_ARM64_PATH}/WysiwygComposerFFI"

# Build libraries for all platforms
cargo build -p uniffi-wysiwyg-composer --release --target aarch64-apple-ios --target aarch64-apple-ios-sim --target x86_64-apple-ios
Expand Down Expand Up @@ -57,28 +46,8 @@ mv "${GENERATION_PATH}/WysiwygComposer.swift" $SWIFT_BINDINGS_FILE_PATH
sed -i "" -e '1h;2,$H;$!d;g' -e 's/) -> ComposerUpdate {\n return try! FfiConverterTypeComposerUpdate.lift(\n try!/) throws -> ComposerUpdate {\n return try FfiConverterTypeComposerUpdate.lift(\n try/g' $SWIFT_BINDINGS_FILE_PATH
sed -i "" -e '1h;2,$H;$!d;g' -e 's/) -> ComposerUpdate/) throws -> ComposerUpdate/g' $SWIFT_BINDINGS_FILE_PATH

# Create xcframework hierarchy
mkdir -p $XCFRAMEWORK_SIM_HEADERS_PATH
mkdir $XCFRAMEWORK_SIM_MODULES_PATH
mkdir -p $XCFRAMEWORK_ARM64_HEADERS_PATH
mkdir $XCFRAMEWORK_ARM64_MODULES_PATH

# Copy/move files to expected locations
#
# Note: this and the hierarchy created above are actually
# replacing the call to xcodebuild's create-xcframework because
# it doesn't build up the hierarchy in a way that would avoid
# conflicts between multiple Rust libraries imported into the same
# hosting application. This does, because .framework objects
# have their own directory in DerivedData, whereas root headers
# directory module.modulemap files tend to conflict with each other
# as Xcode blindly moves them all to the same include folder.
mv $ARM64_LIB_PATH $XCFRAMEWORK_ARM64_LIBRARY_PATH
mv $SIM_LIB_PATH $XCFRAMEWORK_SIM_LIBRARY_PATH
cp ${GENERATION_PATH}/*.h $XCFRAMEWORK_SIM_HEADERS_PATH
mv ${GENERATION_PATH}/*.h $XCFRAMEWORK_ARM64_HEADERS_PATH
cp "${TOOLS_PATH}/Framework-Info.plist" "${XCFRAMEWORK_SIM_PATH}/Info.plist"
cp "${TOOLS_PATH}/Framework-Info.plist" "${XCFRAMEWORK_ARM64_PATH}/Info.plist"
cp "${TOOLS_PATH}/XCFramework-Info.plist" "${XCFRAMEWORK_PATH}/Info.plist"
cp "${TOOLS_PATH}/module.modulemap" $XCFRAMEWORK_SIM_MODULES_PATH
cp "${TOOLS_PATH}/module.modulemap" $XCFRAMEWORK_ARM64_MODULES_PATH
# Making this directory is required to not have conflicts with other FFI generated xcframeworks.
mkdir $GENERATION_PATH/WysiwygComposerFFI
mv ${GENERATION_PATH}/WysiwygComposerFFI.modulemap ${GENERATION_PATH}/WysiwygComposerFFI/module.modulemap
mv ${GENERATION_PATH}/*.h ${GENERATION_PATH}/WysiwygComposerFFI
xcodebuild -create-xcframework -library $ARM64_LIB_PATH -headers $GENERATION_PATH -library $SIM_LIB_PATH -headers $GENERATION_PATH -output $XCFRAMEWORK_PATH
8 changes: 4 additions & 4 deletions platforms/ios/example/Wysiwyg.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
A6E13E5129A8F06E00A85A55 /* SerializationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E13E5029A8F06E00A85A55 /* SerializationService.swift */; };
A6E13E5329A8F0DD00A85A55 /* WysiwygTextAttachmentData.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E13E5229A8F0DD00A85A55 /* WysiwygTextAttachmentData.swift */; };
A6E13E5529A8F1C400A85A55 /* WysiwygAttachmentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E13E5429A8F1C400A85A55 /* WysiwygAttachmentView.swift */; };
A6E6B26F2886D9AA009596F2 /* WysiwygComposer in Frameworks */ = {isa = PBXBuildFile; productRef = A6E6B26E2886D9AA009596F2 /* WysiwygComposer */; };
A6F3FC0128D4658000C170E8 /* AlertHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6F3FC0028D4658000C170E8 /* AlertHelper.swift */; };
A6F3FC0428D465AF00C170E8 /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6F3FC0328D465AF00C170E8 /* View.swift */; };
A6F3FC0628DA123900C170E8 /* UIAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6F3FC0528DA123900C170E8 /* UIAlertController.swift */; };
A6F4D0CC29AE082900087A3E /* WysiwygSuggestionList.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6F4D0CB29AE082900087A3E /* WysiwygSuggestionList.swift */; };
A6F4D0CF29AE0C1500087A3E /* Users.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6F4D0CE29AE0C1500087A3E /* Users.swift */; };
A6F4D0D129AE0C3200087A3E /* Rooms.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6F4D0D029AE0C3200087A3E /* Rooms.swift */; };
A6F4D0D329AE0C5100087A3E /* Commands.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6F4D0D229AE0C5100087A3E /* Commands.swift */; };
A74D33FE2C468E1500A40BB5 /* WysiwygComposer in Frameworks */ = {isa = PBXBuildFile; productRef = A74D33FD2C468E1500A40BB5 /* WysiwygComposer */; };
A75C6AD22C3E989D0096D3A4 /* WysiwygUITests+Keyboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = A75C6AD12C3E989D0096D3A4 /* WysiwygUITests+Keyboard.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -106,7 +106,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
A6E6B26F2886D9AA009596F2 /* WysiwygComposer in Frameworks */,
A74D33FE2C468E1500A40BB5 /* WysiwygComposer in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -273,7 +273,7 @@
);
name = Wysiwyg;
packageProductDependencies = (
A6E6B26E2886D9AA009596F2 /* WysiwygComposer */,
A74D33FD2C468E1500A40BB5 /* WysiwygComposer */,
);
productName = Wysiwyg;
productReference = A6472CA72886CF830021A0E8 /* Wysiwyg.app */;
Expand Down Expand Up @@ -721,7 +721,7 @@
/* End XCConfigurationList section */

/* Begin XCSwiftPackageProductDependency section */
A6E6B26E2886D9AA009596F2 /* WysiwygComposer */ = {
A74D33FD2C468E1500A40BB5 /* WysiwygComposer */ = {
isa = XCSwiftPackageProductDependency;
productName = WysiwygComposer;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "f29e2014f6230cf7d5138fc899da51c7f513d467",
"version" : "1.10.0"
"revision" : "c097f955b4e724690f0fc8ffb7a6d4b881c9c4e3",
"version" : "1.17.2"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax",
"state" : {
"revision" : "4c6cc0a3b9e8f14b3ae2307c5ccae4de6167ac2c",
"version" : "600.0.0-prerelease-2024-06-12"
}
}
],
Expand Down
41 changes: 41 additions & 0 deletions platforms/ios/lib/WysiwygComposer/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"pins" : [
{
"identity" : "dtcoretext",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Cocoanetics/DTCoreText",
"state" : {
"revision" : "b664664825da565b4c2b7a17dbe2369f68ae43d9",
"version" : "1.6.26"
}
},
{
"identity" : "dtfoundation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Cocoanetics/DTFoundation.git",
"state" : {
"revision" : "76062513434421cb6c8a1ae1d4f8368a7ebc2da3",
"version" : "1.7.18"
}
},
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "c097f955b4e724690f0fc8ffb7a6d4b881c9c4e3",
"version" : "1.17.2"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax",
"state" : {
"revision" : "4c6cc0a3b9e8f14b3ae2307c5ccae4de6167ac2c",
"version" : "600.0.0-prerelease-2024-06-12"
}
}
],
"version" : 2
}
2 changes: 1 addition & 1 deletion platforms/ios/lib/WysiwygComposer/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ let package = Package(
dependencies: [
.package(
url: "https://github.com/pointfreeco/swift-snapshot-testing",
from: "1.17.1"
from: "1.17.2"
),
.package(
url: "https://github.com/Cocoanetics/DTCoreText",
Expand Down
Binary file removed platforms/ios/tools/Framework-Info.plist
Binary file not shown.
40 changes: 0 additions & 40 deletions platforms/ios/tools/XCFramework-Info.plist

This file was deleted.

4 changes: 0 additions & 4 deletions platforms/ios/tools/module.modulemap

This file was deleted.

0 comments on commit 6a1960d

Please sign in to comment.