Based on the [SR-15611] swiftSettings flags aren't being sent to dependencies · Issue #4368 · apple/swift-package-manager · GitHub
I just would like to confirm if this is a bug.
I have been a lot of hours straggling trying to send a specific flag to one of the dependencies that I have in my project.
I have tried the following documentation from here:
[Package — Swift Package Manager]
I see how the flag that is defined in the Package file, it is being sent properly to the source files that belong to my Package.swift, however, it is not being sent to the local and remote dependencies.
Basically, if we have:
A dummy dependency Goodbye
public struct Goodbye {
static public func say() {
#if DUMMY_FLAG
print("Goodbye with DUMMY FLAG! 😊")
#else
print("Sadly Goodbye 😢")
#endif
}
}
With the Package.swift:
let package = Package(
name: "Goodbye",
products: [
.library(
name: "Goodbye",
targets: ["Goodbye"]),
],
dependencies: [],
targets: [
.target(
name: "Goodbye",
dependencies: []),
]
)
As you can see based on whether the DUMMY_FLAG is being sent or not, it will print one message or the other.
Then on the main target, we are using the GoodBye dependency:
import Goodbye
#if DUMMY_FLAG
print("Hello World with DUMMY FLAG! 😊")
#else
print("Sadly Hello World 😢")
#endif
Goodbye.say()
And in the Package.swift we are defining the specific DUMMY_FLAG inside of the swiftSettings section:
let package = Package(
name: "dummy-swiftSettings",
platforms: [
.macOS(.v10_12)
],
products: [
.executable(name: "dummy-swiftSettings", targets: ["dummy-swiftSettings"]),
],
dependencies: [
.package(path: "Goodbye"),
],
targets: [
.executableTarget(
name: "dummy-swiftSettings",
dependencies: ["Goodbye"],
swiftSettings: [.define("DUMMY_FLAG")])
]
)
The expected behavior if I'm right it is:
Hello World with DUMMY FLAG! 😊
Goodbye with DUMMY FLAG! 😊
However, it shows:
Hello World with DUMMY FLAG! 😊
Sadly Goodbye 😢
I have attached a dummy project with this specific example, I have also created a repo in GitHub where I have implemented as well the CI/CD, I have double-checked that it wasn't an issue in my local computer.
Here you have the link:
[GitHub - fjtrujy/dummy-swiftSettings: A dummy project for testing if the Package.swift is passing flag variables to dependencies]
I have tried in:
- Local computer, MacOS 12.0.1 (M1 Max), Xcode 13.2, Swift 5.5.2
- Github CI/CD using MacOS 11.6.1, Xcode 13.1, Swift 5.5.1
- Github CI/CD using Ubuntu 20.04.3 LTS, Swift 5.5.2
Thanks