Conversation
|
@swift-ci test please |
|
@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") |
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Agreed. Removed the declaration and now only the implementation in FoundationMacros remains.
|
FYI here is the SwiftPM implementation of the compile-time conditions: swiftlang/swift-package-manager#8556 |
|
@swift-ci please test |
* Implementation of #bundle macro * separate macro declaration from implementation of bundle expansion * Remove CurrentBundle.swift --------- Co-authored-by: Andreas Neusuess <andreas_n@apple.com>
Introduce Swift compilation conditions to support `#bundle` in Foundation. ### Motivation: This is the SwiftPM companion to `#bundle`. Pitch: https://forums.swift.org/t/pitch-introduce-bundle-macro/79288 Proposal: swiftlang/swift-foundation#1251 Implementation: swiftlang/swift-foundation#1274 ### Modifications: Define `SWIFT_MODULE_RESOURCE_BUNDLE_AVAILABLE` when we'd like `#bundle` to call our generated `Bundle.module`. Define `SWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE` when there are no resources and `#bundle` should complain about that. Leave them both undefined when we'd like `#bundle` to keep its default behavior of using the same bundle where the source code lives. ### Result: `#bundle` will point to the correct resource bundle when called from Swift Packages.
This PR implements
#bundle, as pitched here and proposed here