-
Notifications
You must be signed in to change notification settings - Fork 3
XCFramework experiment #241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mokagio
wants to merge
18
commits into
trunk
Choose a base branch
from
mokagio/experiment-xcframework-2
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
22b48e9
Restore ignoring JS build files from Swift package source
mokagio cfa0dd3
Add unit test target to test Package XCFramework distribution
mokagio bc5cf57
Remove unused GutenbergKit import from demo app
mokagio a8da422
Disable parallelization for integration tests
mokagio ea2f5f0
Add `make` task to run integration tests - Fails as expected
mokagio 38a8b31
Add XCFramework tests to CI
mokagio 2abe2fd
Add script to builds XCFramework
mokagio 80b154d
Embed XCFramework in unit tests and test it works
mokagio 6c3f0ce
Temporarily hardcode lib type as dynamic to build XCFrmwrk
mokagio 279710c
Run on Xcode 26.1.1
mokagio 7eed75c
Use Swift 6 in integration tests (even though we don't use API)
mokagio a673e0c
Track indentation change
mokagio 4de5945
Add implicit test for CSS loading in XCFramework
mokagio c692ece
Bump OS in `Makefile` post Xcode 26.1.1 adoption
mokagio 5d0dd73
Shorter CI title
mokagio 2dfc63e
Use `internal import` for XCFramework dependencies
mokagio 3baad7e
Add test that XCFramework build _would_ crash without bundle
mokagio 32e3bf1
Improve comment
mokagio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
.buildkite/commands/verify-xcframework-test-fails-with-missing-resources.sh
This file contains hidden or 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,28 @@ | ||
| #!/bin/bash -eu | ||
|
|
||
| set -o pipefail | ||
|
|
||
| echo "--- :pencil2: Breaking bundle resource path to verify test catches failures" | ||
| # Replace "Gutenberg" with "folder_that_does_not_exist" in the HTMLPreviewManager | ||
| sed -i.bak 's/forResource: "Gutenberg", withExtension: nil/forResource: "folder_that_does_not_exist", withExtension: nil/g' ios/Sources/GutenbergKit/Sources/Views/HTMLPreview/HTMLPreviewManager.swift | ||
|
Comment on lines
5
to
8
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we can't inject values that would result in a crash and we can't test for crashes anyways when targeting iOS we hack the code to force a crash and test that the tests fail as expected. |
||
|
|
||
| echo "--- :package: Rebuilding XCFramework with broken resource path" | ||
| make build-xcframework-debug | ||
|
|
||
| echo "--- :apple: Running integration tests (expecting failure)" | ||
| set +e # Don't exit on error | ||
| make test-xcframework-integration MAKECMDGOALS=test-xcframework-integration | ||
| TEST_EXIT_CODE=$? | ||
| set -e # Re-enable exit on error | ||
|
|
||
| echo "--- :mag: Restoring original file" | ||
| mv ios/Sources/GutenbergKit/Sources/Views/HTMLPreview/HTMLPreviewManager.swift.bak ios/Sources/GutenbergKit/Sources/Views/HTMLPreview/HTMLPreviewManager.swift | ||
|
|
||
| echo "--- :white_check_mark: Verifying test failed as expected" | ||
| if [ $TEST_EXIT_CODE -eq 0 ]; then | ||
| echo "ERROR: Tests passed when they should have failed! The test does not properly catch missing bundle resources." | ||
| exit 1 | ||
| else | ||
| echo "SUCCESS: Tests failed as expected when bundle resources were missing (exit code: $TEST_EXIT_CODE)" | ||
| exit 0 | ||
| fi | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| 26.0 | ||
| 26.1.1 |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,141 @@ | ||
| #!/bin/bash -eu | ||
|
|
||
| set -o pipefail | ||
|
|
||
| # Originally sourced from: | ||
| # https://github.com/OpenSwiftUIProject/ProtobufKit/blob/937eae5426277bec040c7f99bc8e1498c30ed467/Scripts/build_xcframework.sh | ||
| # | ||
| # Found it via: | ||
| # https://forums.swift.org/t/how-on-earth-can-i-create-a-framework-from-a-swift-package/76797/6 | ||
| # | ||
| # Related: | ||
| # https://forums.swift.org/t/how-to-build-swift-package-as-xcframework/41414/57 | ||
|
|
||
| # Script modified from https://docs.emergetools.com/docs/analyzing-a-spm-framework-ios | ||
|
|
||
| PACKAGE_NAME=${1-} | ||
| if [ -z "$PACKAGE_NAME" ]; then | ||
| echo "No package name provided. Using the first scheme found in the Package.swift." | ||
| PACKAGE_NAME=$(xcodebuild -list | awk 'schemes && NF>0 { print $1; exit } /Schemes:$/ { schemes = 1 }') | ||
| echo "Using: $PACKAGE_NAME" | ||
| fi | ||
|
|
||
| # Swift optimization level: -Onone (no optimization), -O (optimize for speed), -Osize (optimize for size) | ||
| # Default to -O for release builds, can be overridden with SWIFT_OPTIMIZATION_LEVEL environment variable | ||
| SWIFT_OPTIMIZATION_LEVEL="${SWIFT_OPTIMIZATION_LEVEL:--O}" | ||
| echo "Swift optimization level: $SWIFT_OPTIMIZATION_LEVEL" | ||
|
|
||
| # FIXME: Original script was in subfolder, this is in repo root for the time being. | ||
| # | ||
| # SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd -P)" | ||
| # PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" | ||
| PROJECT_ROOT=$(pwd) | ||
|
|
||
| PROJECT_BUILD_DIR="${PROJECT_BUILD_DIR:-"${PROJECT_ROOT}/build"}" | ||
| XCODEBUILD_BUILD_DIR="$PROJECT_BUILD_DIR/xcodebuild" | ||
| XCODEBUILD_DERIVED_DATA_PATH="$XCODEBUILD_BUILD_DIR/DerivedData" | ||
|
|
||
| echo "PROJECT_BUILD_DIR is $PROJECT_BUILD_DIR" | ||
|
|
||
| build_framework() { | ||
| local sdk="$1" | ||
| local destination="$2" | ||
| local scheme="$3" | ||
|
|
||
| local XCODEBUILD_ARCHIVE_PATH="./build/$scheme-$sdk.xcarchive" | ||
|
|
||
| rm -rf "$XCODEBUILD_ARCHIVE_PATH" | ||
|
|
||
| # TODO: Consider using this env var to switch between static (default) | ||
| # and dynamic (required for XCFramework) | ||
| # | ||
| # See: | ||
| # https://github.com/OpenSwiftUIProject/ProtobufKit/blob/937eae5426277bec040c7f99bc8e1498c30ed467/Package.swift#L30 | ||
| # LIBRARY_TYPE=dynamic xcodebuild archive \ | ||
| xcodebuild archive \ | ||
| -scheme "$scheme" \ | ||
| -archivePath "$XCODEBUILD_ARCHIVE_PATH" \ | ||
| -derivedDataPath "$XCODEBUILD_DERIVED_DATA_PATH" \ | ||
| -sdk "$sdk" \ | ||
| -destination "$destination" \ | ||
| BUILD_LIBRARY_FOR_DISTRIBUTION=YES \ | ||
| INSTALL_PATH='Library/Frameworks' \ | ||
| SWIFT_OPTIMIZATION_LEVEL="$SWIFT_OPTIMIZATION_LEVEL" \ | ||
| OTHER_SWIFT_FLAGS=-no-verify-emitted-module-interface \ | ||
| | xcbeautify | ||
|
|
||
| if [ "$sdk" = "macosx" ]; then | ||
| FRAMEWORK_MODULES_PATH="$XCODEBUILD_ARCHIVE_PATH/Products/Library/Frameworks/$scheme.framework/Versions/Current/Modules" | ||
| mkdir -p "$FRAMEWORK_MODULES_PATH" | ||
| cp -r \ | ||
| "$XCODEBUILD_DERIVED_DATA_PATH/Build/Intermediates.noindex/ArchiveIntermediates/$scheme/BuildProductsPath/Release/$scheme.swiftmodule" \ | ||
| "$FRAMEWORK_MODULES_PATH/$scheme.swiftmodule" | ||
| rm -rf "$XCODEBUILD_ARCHIVE_PATH/Products/Library/Frameworks/$scheme.framework/Modules" | ||
| ln -s Versions/Current/Modules "$XCODEBUILD_ARCHIVE_PATH/Products/Library/Frameworks/$scheme.framework/Modules" | ||
| else | ||
| FRAMEWORK_MODULES_PATH="$XCODEBUILD_ARCHIVE_PATH/Products/Library/Frameworks/$scheme.framework/Modules" | ||
| mkdir -p "$FRAMEWORK_MODULES_PATH" | ||
| cp -r \ | ||
| "$XCODEBUILD_DERIVED_DATA_PATH/Build/Intermediates.noindex/ArchiveIntermediates/$scheme/BuildProductsPath/Release-$sdk/$scheme.swiftmodule" \ | ||
| "$FRAMEWORK_MODULES_PATH/$scheme.swiftmodule" | ||
| fi | ||
|
|
||
| # Delete private and package swiftinterface | ||
| rm -f "$FRAMEWORK_MODULES_PATH/$scheme.swiftmodule/*.package.swiftinterface" | ||
| rm -f "$FRAMEWORK_MODULES_PATH/$scheme.swiftmodule/*.private.swiftinterface" | ||
| } | ||
|
|
||
| copy_resource_bundles() { | ||
| local sdk="$1" | ||
| local scheme="$2" | ||
|
|
||
| local XCODEBUILD_ARCHIVE_PATH="./build/$scheme-$sdk.xcarchive" | ||
| local FRAMEWORK_PATH="$XCODEBUILD_ARCHIVE_PATH/Products/Library/Frameworks/$scheme.framework" | ||
|
|
||
| # Find all resource bundles in DerivedData | ||
| local BUNDLE_PATH="$XCODEBUILD_DERIVED_DATA_PATH/Build/Intermediates.noindex/ArchiveIntermediates/$scheme/IntermediateBuildFilesPath/UninstalledProducts/$sdk" | ||
|
|
||
| # Copy all .bundle files found | ||
| if [ -d "$BUNDLE_PATH" ]; then | ||
| find "$BUNDLE_PATH" -name "*.bundle" -maxdepth 1 -type d -print0 | while IFS= read -r -d '' bundle; do | ||
| bundle_name=$(basename "$bundle") | ||
| echo "Copying resource bundle: $bundle_name to $FRAMEWORK_PATH" | ||
| # Remove symlink if it exists and copy the actual bundle | ||
| rm -rf "${FRAMEWORK_PATH:?}/$bundle_name" | ||
| cp -R "$bundle" "$FRAMEWORK_PATH/" | ||
| done | ||
| else | ||
| echo "Warning: Bundle path not found: $BUNDLE_PATH" | ||
| fi | ||
| } | ||
|
|
||
| build_framework "iphonesimulator" "generic/platform=iOS Simulator" "$PACKAGE_NAME" | ||
| copy_resource_bundles "iphonesimulator" "$PACKAGE_NAME" | ||
|
|
||
| build_framework "iphoneos" "generic/platform=iOS" "$PACKAGE_NAME" | ||
| copy_resource_bundles "iphoneos" "$PACKAGE_NAME" | ||
|
|
||
| # No macOS support because of UIKit in the dependencies | ||
| # | ||
| # build_framework "macosx" "generic/platform=macOS" "$PACKAGE_NAME" | ||
| # copy_resource_bundles "macosx" "$PACKAGE_NAME" | ||
|
|
||
| echo "Builds completed successfully." | ||
|
|
||
| pushd "$PROJECT_BUILD_DIR" > /dev/null | ||
|
|
||
| rm -rf "$PACKAGE_NAME.xcframework" | ||
| xcodebuild -create-xcframework \ | ||
| -framework "$PACKAGE_NAME-iphonesimulator.xcarchive/Products/Library/Frameworks/$PACKAGE_NAME.framework" \ | ||
| -framework "$PACKAGE_NAME-iphoneos.xcarchive/Products/Library/Frameworks/$PACKAGE_NAME.framework" \ | ||
| -output "$PACKAGE_NAME.xcframework" | ||
|
|
||
| cp -r "$PACKAGE_NAME-iphonesimulator.xcarchive/dSYMs" "$PACKAGE_NAME.xcframework/ios-arm64_x86_64-simulator" | ||
| cp -r "$PACKAGE_NAME-iphoneos.xcarchive/dSYMs" "$PACKAGE_NAME.xcframework/ios-arm64" | ||
|
|
||
| zip -r "$PACKAGE_NAME.xcframework.zip" "$PACKAGE_NAME.xcframework" > /dev/null | ||
|
|
||
| # TODO: Remove emoji, print all in green | ||
| echo "✅ XCFramework generated at $(pwd)/$PACKAGE_NAME.xcframework" | ||
|
|
||
| popd > /dev/null |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.