Merged
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Currently, trying to pass a Bundle from a native Skip Fuse module to a transpiled Skip Lite module as a parameter will fail to compile with the error:
This is because in order to handle how Android stores resources (as assets and accessible through the
AssetManager), we need to subclassFoundation.Bundleas anAndroidBundle. When SwiftPM generates itsBundle.moduleproperty, it spits out aresource_bundle_accessor.swiftfile that will be compiled along with the module like:So in order to intercept this and return our subclass, the SwiftPM plugin spits out a typealias from Bundle to a local
class AndroidModuleBundle : AndroidBundlethat defines its owninit?(path: String)so we can return theAndroidBundlesubclass. It does this in aswift/plugins/outputs/swift/SkipAndroidBridgeSamples/destination/skipstone/SkipBridgeGenerated/Bundle_Support.swiftfile created by theKotlinBundleTransformer.swift.All told, the relevant source and generate file tree looks like this for the
SkipAndroidBridgeSamplesmodule's resources:This has been working fine:
Bundle.module.url(forResource: "foo")will returnasset:/my/kotlin/package/Resources/fooas expected (which is subsequently handled by a custom URL scheme handler, both on the Kotlin and Swift sides). However, because it uses a package-internal subclass ofAndroidBundle, it isn't bridgeable. And even it if was, each module would have their own separateAndroidModuleBundleclass definition that would be incompatible with each other.This PR changes the way we generate the local
Bundle.init(path: String)override by instead making apublic typealias Bundle = AndroidBundleto the baseAndroidBundle, and intercepting the initialization fromresource_bundle_accessor.swiftwithconvenience init?(path: String, unusedp_0: Void? = nil).This makes
Bundlebridgeable and simplifies the internal handling ofAndroidBundleby eliminating the custom per-module subclass and just using the (bridgeable) base class the destination for theBundletypealias.