Skip to content

Introduce new defines to enable #bundle in Swift Packages #8556

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

matthewseaman
Copy link
Contributor

@matthewseaman matthewseaman commented Apr 24, 2025

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.

if bundlePath != nil {
compilationConditions += ["-DSWIFT_MODULE_RESOURCE_BUNDLE_AVAILABLE=1"]
} else {
compilationConditions += ["-DSWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE=1"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this trigger

warning: conditional compilation flags do not have values in Swift; they are either present or absent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh good catch! I was copying the wrong pattern from the Clang version.

@matthewseaman
Copy link
Contributor Author

@swift-ci please test

Copy link
Contributor

@jakepetroules jakepetroules left a comment

Choose a reason for hiding this comment

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

Looks like a bunch of tests need updating.

@matthewseaman
Copy link
Contributor Author

@swift-ci please test

@matthewseaman matthewseaman force-pushed the mseaman/149806691-pound-bundle-support branch from 96c5bae to c052c54 Compare April 25, 2025 01:33
@matthewseaman
Copy link
Contributor Author

@swift-ci please test

@MaxDesiatov
Copy link
Contributor

@swift-ci test windows

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