Skip to content

Conversation

matthewseaman
Copy link
Contributor

@matthewseaman matthewseaman commented Jun 19, 2025

Mergeable libraries use a re-exported library in Debug mode and merge into the client in Release builds.
In both cases, we cannot simply rely on the #dsohandle for bundle lookup as #bundle does by default.

Instead, dyld includes special bundle loading hooks that allows BundleForClass to return the current resource bundle at runtime.

In this PR, we have mergeable libraries codegen a simple __BundleLookupHelper class and define the SWIFT_BUNDLE_LOOKUP_HELPER_AVAILABLE compilation condition.
The implementation of #bundle in Foundation will then lookup Bundle(for: __BundleLookupHelper.self) under this condition.
This solution intentional avoids the need for generated code to import Foundation.

This should allow #bundle to work correctly for mergeable libraries.

  • Add Tests

Copy link

Choose a reason for hiding this comment

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

I wonder if this effectively evaluates to true in a debug build when we're not building as mergeable? cc @mhrawdon

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is the difference between MERGEABLE_LIBRARY and MAKE_MERGEABLE.
If MERGEABLE_LIBRARY is true then this is a library that is opting into being mergeable (either automatically or manually), while MAKE_MERGEABLE is only true in optimized builds per the lines above.

So MERGEABLE_LIBRARY should be what we need here.

@matthewseaman
Copy link
Contributor Author

@swift-ci test

@matthewseaman matthewseaman force-pushed the mseaman/mergeable-library-bundle-macro-support branch from c9813f4 to 157001d Compare June 23, 2025 21:50
@matthewseaman
Copy link
Contributor Author

@swift-ci test

@matthewseaman matthewseaman changed the base branch from release/6.2 to main June 24, 2025 18:51
@matthewseaman matthewseaman changed the base branch from main to release/6.2 June 24, 2025 18:54
@matthewseaman matthewseaman merged commit ec83172 into release/6.2 Jun 24, 2025
44 of 45 checks passed
@matthewseaman matthewseaman deleted the mseaman/mergeable-library-bundle-macro-support branch June 24, 2025 22:24
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.

3 participants