Skip to content

Fix Objective-C stub APIs on Linux - #36

Merged
p-x9 merged 1 commit into
mainfrom
feature/fix-linux-objc-stub-linking
Aug 1, 2026
Merged

Fix Objective-C stub APIs on Linux#36
p-x9 merged 1 commit into
mainfrom
feature/fix-linux-objc-stub-linking

Conversation

@p-x9

@p-x9 p-x9 commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Restrict the Objective-C stub metadata initializer API to platforms with Objective-C interoperability.
  • Prevent Linux consumers from emitting an unresolved swift_getObjCClassMetadata reference during final executable linking.

Root cause

The library target could compile and archive successfully on Linux, but the public @convention(c) function type returned AnyClass?. 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 build
  • Confirmed the PR contains only the canImport(ObjectiveC) guard around ObjCSwiftMetadataInitializer and initialize(in:_:).

@p-x9
p-x9 marked this pull request as ready for review August 1, 2026 08:35
@p-x9
p-x9 requested a review from Copilot August 1, 2026 08:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ObjCSwiftMetadataInitializer in #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.

@p-x9
p-x9 merged commit 52bba0e into main Aug 1, 2026
3 checks passed
@p-x9
p-x9 deleted the feature/fix-linux-objc-stub-linking branch August 1, 2026 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants