Fix Objective-C stub APIs on Linux - #36
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Objective-C stub class API surface so that Objective-C metadata initialization symbols are only exposed/compiled on platforms that support Objective-C interoperability, preventing Linux consumers from linking against unavailable Objective-C runtime metadata support.
Changes:
- Wrap
ObjCSwiftMetadataInitializerin#if canImport(ObjectiveC)so it is not part of the Linux build. - Wrap
ObjCStubClassProtocol.initialize(in:_:)in the same Objective-C availability guard to avoid emitting unresolved Objective-C metadata runtime references on Linux.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
swift_getObjCClassMetadatareference during final executable linking.Root cause
The library target could compile and archive successfully on Linux, but the public
@convention(c)function type returnedAnyClass?. When a consumer linked the affected object code, Swift emitted a reference to Objective-C class metadata support that is unavailable in the Linux runtime.Impact
Linux consumers can link the package without pulling in the unavailable Objective-C metadata runtime symbol. Apple-platform behavior remains unchanged.
Validation
swift buildcanImport(ObjectiveC)guard aroundObjCSwiftMetadataInitializerandinitialize(in:_:).