[iOS] Improved XCFramework generation script (#1018)

This commit is contained in:
Mauro 2024-07-16 15:32:29 +02:00 committed by GitHub
parent 1e975b11c3
commit 6a1960dc20
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 62 additions and 87 deletions

View file

@ -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
@ -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

View file

@ -37,7 +37,6 @@
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 */; };
@ -45,6 +44,7 @@
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 */
@ -106,7 +106,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
A6E6B26F2886D9AA009596F2 /* WysiwygComposer in Frameworks */,
A74D33FE2C468E1500A40BB5 /* WysiwygComposer in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -273,7 +273,7 @@
);
name = Wysiwyg;
packageProductDependencies = (
A6E6B26E2886D9AA009596F2 /* WysiwygComposer */,
A74D33FD2C468E1500A40BB5 /* WysiwygComposer */,
);
productName = Wysiwyg;
productReference = A6472CA72886CF830021A0E8 /* Wysiwyg.app */;
@ -721,7 +721,7 @@
/* End XCConfigurationList section */
/* Begin XCSwiftPackageProductDependency section */
A6E6B26E2886D9AA009596F2 /* WysiwygComposer */ = {
A74D33FD2C468E1500A40BB5 /* WysiwygComposer */ = {
isa = XCSwiftPackageProductDependency;
productName = WysiwygComposer;
};

View file

@ -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"
}
}
],

View file

@ -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
}

View file

@ -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",

View file

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AvailableLibraries</key>
<array>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>WysiwygComposerFFI.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
</dict>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>WysiwygComposerFFI.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
<string>XFWK</string>
<key>XCFrameworkFormatVersion</key>
<string>1.0</string>
</dict>
</plist>

View file

@ -1,4 +0,0 @@
framework module WysiwygComposerFFI {
umbrella header "WysiwygComposerFFI.h"
export *
}