Skip to content
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

Fix XCFramework with library evolution #7753

Merged
merged 3 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ x.y.z Release notes (yyyy-MM-dd)
* Replace Xcode 13.3 binaries with 13.3.1 binaries.

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-swift/issues/????), since v?.?.?)
* None.
* Consuming a RealmSwift XCFramework with library evolution enabled would give the error
`'Failed to build module 'RealmSwift'; this SDK is not supported by the compiler'` when the XCFramework was built
with an older XCode version and is then consumed with a later version. ([#7313](https://github.com/realm/realm-swift/issues/7313), since v3.18.0)

<!-- ### Breaking Changes - ONLY INCLUDE FOR NEW MAJOR version -->

Expand Down
17 changes: 17 additions & 0 deletions Jenkinsfile.releasability
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ def installationTest(platform, test, language) {
}
}

def xcframeworkEvolutionTest() {
return {
node('osx') {
deleteDir()
unstash 'source'

sh """
hostname
export REALM_XCODE_OLDEST_VERSION=${xcodeVersions.first()}
export REALM_XCODE_LATEST_VERSION=${xcodeVersions.last()}
./build.sh verify-xcframework-evolution-mode
"""
}
}
}

def spmInstallationTest(platform) {
return {
node('osx') {
Expand Down Expand Up @@ -319,6 +335,7 @@ def doBuild() {
}

parallelBuilds["Installation - Mac Catalyst Swift CocoaPods"] = installationTest('catalyst', 'cocoapods', 'swift')
parallelBuilds["Installation - iOS XCFramework Evolution"] = xcframeworkEvolutionTest()

parallel parallelBuilds
}
Expand Down
39 changes: 37 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
##################################################################################
# Custom build tool for Realm Objective-C binding.
#
# (C) Copyright 2011-2015 by realm.io.
# (C) Copyright 2011-2022 by realm.io.
##################################################################################

# Warning: pipefail is not a POSIX compatible option, but on macOS it works just fine.
Expand Down Expand Up @@ -87,7 +87,9 @@ environment variables:
CONFIGURATION: Debug or Release (default)
REALM_CORE_VERSION: version in x.y.z format or "current" to use local build
REALM_EXTRA_BUILD_ARGUMENTS: additional arguments to pass to the build tool
REALM_XCODE_VERSION: the version number of Xcode to use (e.g.: 8.1)
REALM_XCODE_VERSION: the version number of Xcode to use (e.g.: 13.3.1)
REALM_XCODE_OLDEST_VERSION: the version number of oldest available Xcode to use (e.g.: 12.4)
REALM_XCODE_LATEST_VERSION: the version number of latest available Xcode to use (e.g.: 13.3.1)
EOF
}

Expand Down Expand Up @@ -440,6 +442,39 @@ case "$COMMAND" in
| sed 's/.*/-framework &/' \
| xargs xcodebuild -create-xcframework -allow-internal-distribution -output build/RealmSwift.xcframework

# Because we have a module named Realm and a type named Realm we need to manually resolve the naming
# collisions that are happening. These collisions create a red herring which tells the user the xcframework
# was compiled with an older Swift version and is not compatible with the current compiler.
find build/RealmSwift.xcframework -name "*.swiftinterface" -exec sed -i '' 's/Realm\.//g' {} \; \
-exec sed -i '' 's/import Private/import Realm.Private/g' {} \; \
-exec sed -i '' 's/RealmSwift.Configuration/RealmSwift.Realm.Configuration/g' {} \; \
-exec sed -i '' 's/extension Configuration/extension Realm.Configuration/g' {} \; \
-exec sed -i '' 's/RealmSwift.Error/RealmSwift.Realm.Error/g' {} \; \
-exec sed -i '' 's/extension Error/extension Realm.Error/g' {} \; \
-exec sed -i '' 's/RealmSwift.AsyncOpenTask/RealmSwift.Realm.AsyncOpenTask/g' {} \; \
-exec sed -i '' 's/RealmSwift.UpdatePolicy/RealmSwift.Realm.UpdatePolicy/g' {} \; \
-exec sed -i '' 's/RealmSwift.Notification /RealmSwift.Realm.Notification /g' {} \; \
-exec sed -i '' 's/RealmSwift.Notification,/RealmSwift.Realm.Notification,/g' {} \; \
-exec sed -i '' 's/τ_1_0/V/g' {} \; # Generics will use τ_1_0 which needs to be changed to the correct type name.

exit 0
;;

"verify-xcframework-evolution-mode")
export REALM_EXTRA_BUILD_ARGUMENTS="$REALM_EXTRA_BUILD_ARGUMENTS REALM_BUILD_LIBRARY_FOR_DISTRIBUTION=YES"
# set the Xcode version to the oldest
export REALM_XCODE_VERSION=$REALM_XCODE_OLDEST_VERSION
unset REALM_SWIFT_VERSION
sh build.sh xcframework ios
# copy the xcframework to the testing target
rm -rf examples/installation/xcframework-evolution
mkdir examples/installation/xcframework-evolution
cp -r build/*.xcframework examples/installation/xcframework-evolution
export REALM_XCODE_VERSION=$REALM_XCODE_LATEST_VERSION
unset REALM_SWIFT_VERSION
cd examples/installation
sh build.sh "test-ios-swift-xcframework"

exit 0
;;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
3FDA0A3D2319AD940099B474 /* RealmSwift.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3FDA0A3B2319AD940099B474 /* RealmSwift.xcframework */; };
3FDA0A3E2319AD940099B474 /* RealmObjc.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3FDA0A3C2319AD940099B474 /* RealmObjc.xcframework */; };
CF5971C528117BCE00094EA3 /* RealmSwift.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = CF5971C328117BCE00094EA3 /* RealmSwift.xcframework */; };
CF5971C628117BCE00094EA3 /* Realm.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = CF5971C428117BCE00094EA3 /* Realm.xcframework */; };
E8E060C11AFAB5EB00484DEE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8E060C01AFAB5EB00484DEE /* AppDelegate.swift */; };
E8E060C31AFAB5EB00484DEE /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8E060C21AFAB5EB00484DEE /* ViewController.swift */; };
E8E060C61AFAB5EB00484DEE /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E8E060C41AFAB5EB00484DEE /* Main.storyboard */; };
Expand Down Expand Up @@ -41,8 +41,8 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
3FDA0A3B2319AD940099B474 /* RealmSwift.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = RealmSwift.xcframework; path = "../../../realm-swift-latest/RealmSwift.xcframework"; sourceTree = "<group>"; };
3FDA0A3C2319AD940099B474 /* RealmObjc.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = RealmObjc.xcframework; path = "../../../realm-swift-latest/RealmObjc.xcframework"; sourceTree = "<group>"; };
CF5971C328117BCE00094EA3 /* RealmSwift.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = RealmSwift.xcframework; path = "../../../xcframework-evolution/RealmSwift.xcframework"; sourceTree = "<group>"; };
CF5971C428117BCE00094EA3 /* Realm.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Realm.xcframework; path = "../../../xcframework-evolution/Realm.xcframework"; sourceTree = "<group>"; };
E8E060BB1AFAB5EB00484DEE /* XCFrameworkExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = XCFrameworkExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
E8E060BF1AFAB5EB00484DEE /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E8E060C01AFAB5EB00484DEE /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -60,8 +60,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
3FDA0A3E2319AD940099B474 /* RealmObjc.xcframework in Frameworks */,
3FDA0A3D2319AD940099B474 /* RealmSwift.xcframework in Frameworks */,
CF5971C528117BCE00094EA3 /* RealmSwift.xcframework in Frameworks */,
CF5971C628117BCE00094EA3 /* Realm.xcframework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -78,11 +78,11 @@
E8E060B21AFAB5EB00484DEE = {
isa = PBXGroup;
children = (
CF5971C428117BCE00094EA3 /* Realm.xcframework */,
CF5971C328117BCE00094EA3 /* RealmSwift.xcframework */,
E8E060BC1AFAB5EB00484DEE /* Products */,
E8E060BD1AFAB5EB00484DEE /* XCFrameworkExample */,
E8E060D31AFAB5EB00484DEE /* XCFrameworkExampleTests */,
3FDA0A3C2319AD940099B474 /* RealmObjc.xcframework */,
3FDA0A3B2319AD940099B474 /* RealmSwift.xcframework */,
);
sourceTree = "<group>";
};
Expand Down Expand Up @@ -303,7 +303,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down Expand Up @@ -361,7 +361,7 @@
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import UIKit
import RealmSwift

public class MyModel: RealmSwift.Object {}
public class MyModel: RealmSwift.Object {
@Persisted var name: String
}

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import UIKit
import XCTest
import XCFrameworkExample
import Realm
import RealmSwift

class XCFrameworkExampleTests: XCTestCase {
func testExample() {
// This is an example of a functional test case.
XCTAssertNotNil(MyModel() as AnyObject is Object)
_ = try! Realm()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,5 @@ func randomTitle() -> String {
}

func randomSectionTitle() -> String {
return sectionTitles[Int.random(0..<sectionTitles.count)]
return sectionTitles[Int.random(in: 0..<sectionTitles.count)]
}