Skip to content

Implementation of #bundle #1274

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

Merged
merged 3 commits into from
Apr 26, 2025
Merged

Conversation

Tantalum73
Copy link
Contributor

This PR implements #bundle, as pitched here and proposed here

@jmschonfeld jmschonfeld self-requested a review April 25, 2025 18:42
@Tantalum73
Copy link
Contributor Author

@swift-ci test please

@jmschonfeld
Copy link
Contributor

@swift-ci please test

/// Code in a Swift Package target will return the resource bundle associated with that target.
@available(macOS 10.0, iOS 2.0, tvOS 9.0, watchOS 2.0, *)
@freestanding(expression)
public macro bundle() -> Bundle = #externalMacro(module: "FoundationMacros", type: "BundleMacro")

Choose a reason for hiding this comment

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

@Tantalum73 @jmschonfeld should this go somewhere other than FoundationInternationalization given that bundles are not just for internationalization? For example someone could easily use this to lookup an asset or some other resource.

Copy link
Contributor

@jmschonfeld jmschonfeld Apr 25, 2025

Choose a reason for hiding this comment

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

Right now, Bundle does not exist in FoundationInternationalization and this is just a FOUNDATION_FRAMEWORK piece that will be picked up by the Foundation.framework build. For this to be fully usable on non-Darwin, this macro would currently need to be declared in the Foundation module in the swift-corelibs-foundation repo as well / separately (which we can do next). Eventually, if we sink Bundle down to swift-foundation this would remove the FOUNDATION_FRAMEWORK ifdef and would go alongside wherever Bundle is defined, but given that Bundle does not currently exist in swift-foundation I'm ok leaving this here for now as just a piece for the Foundation.framework build to pickup and moving it whenever we decide where Bundle will go later

Copy link
Contributor

Choose a reason for hiding this comment

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

I had the same question as @matthewseaman when I read this. IMO Bundle will very likely be in FoundationEssentials if/when we move it, so we'll likely move this there, though like Jeremy said it doesn't really matter now for swift-foundation when building as a package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Removed the declaration and now only the implementation in FoundationMacros remains.

@matthewseaman
Copy link

FYI here is the SwiftPM implementation of the compile-time conditions: swiftlang/swift-package-manager#8556

@jmschonfeld
Copy link
Contributor

@swift-ci please test

@itingliu itingliu merged commit ff0f955 into swiftlang:main Apr 26, 2025
14 checks passed
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.

4 participants