-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from p-x9/feature/script-for-create-xcframework
Add script for create xcframework
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
set -Ceu | ||
|
||
PACKAGE_DIR=$( | ||
cd "$(dirname "$0")/.." || exit 1 | ||
pwd | ||
) | ||
cd "${PACKAGE_DIR}" || exit 1 | ||
|
||
SCHEME="MachOKit" | ||
DERIVED_DATA_PATH=".build" | ||
|
||
enable_dynamic_type() { | ||
#https://forums.swift.org/t/how-to-build-swift-package-as-xcframework/41414/3 | ||
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 | ||
} | ||
|
||
archive_project() { | ||
local PLATFORM=$1 | ||
local RELEASE=$2 | ||
local ARCHIVE_PATH=".build/archives/$PLATFORM" | ||
|
||
xcodebuild archive -workspace . -scheme "$SCHEME" \ | ||
-destination "generic/platform=$PLATFORM" \ | ||
-archivePath "$ARCHIVE_PATH" \ | ||
-derivedDataPath "$DERIVED_DATA_PATH" \ | ||
SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES | ||
|
||
mkdir -p "$ARCHIVE_PATH.xcarchive/Products/usr/local/lib/$SCHEME.framework/Modules" | ||
cp -r ".build/Build/Intermediates.noindex/ArchiveIntermediates/$SCHEME/BuildProductsPath/$RELEASE/$SCHEME.swiftmodule" \ | ||
"$ARCHIVE_PATH.xcarchive/Products/usr/local/lib/$SCHEME.framework/Modules" | ||
} | ||
|
||
create_xcframework() { | ||
xcodebuild -create-xcframework \ | ||
-framework ".build/archives/iOS.xcarchive/Products/usr/local/lib/$SCHEME.framework" \ | ||
-framework ".build/archives/iOS Simulator.xcarchive/Products/usr/local/lib/$SCHEME.framework" \ | ||
-framework ".build/archives/macOS.xcarchive/Products/usr/local/lib/$SCHEME.framework" \ | ||
-output ".build/archives/$SCHEME.xcframework" | ||
} | ||
|
||
zip_xcframework() { | ||
cd .build/archives | ||
zip -ry - "$SCHEME.xcframework" > "$SCHEME.xcframework.zip" | ||
} | ||
|
||
print_checksum() { | ||
CHECKSUM=$(swift package compute-checksum "$SCHEME.xcframework.zip") | ||
echo "checksum:" | ||
echo ${CHECKSUM} | ||
} | ||
|
||
rm -rf .build/archives | ||
|
||
enable_dynamic_type | ||
|
||
archive_project "iOS" "Release-iphoneos" | ||
archive_project "iOS Simulator" "Release-iphonesimulator" | ||
archive_project "macOS" "Release" | ||
#archive_project "tvOS" | ||
#archive_project "tvOS Simulator" | ||
|
||
create_xcframework | ||
|
||
zip_xcframework | ||
|
||
print_checksum | ||
|