`swiftSettings` are ignored for test targets?

I'm trying to define a custom compilation condition using swiftSettings but it only works when setting it on the main target:

            name: "Helm",
            dependencies: [],
            swiftSettings: [.define("HELM_DISABLE_ASSERTIONS")])

But fails to do so when defined only for the test target:

            name: "HelmTests",
            dependencies: ["Helm"],
            swiftSettings: [.define("HELM_DISABLE_ASSERTIONS")])

Is this a known limitation? And if so, any way around it? I must also mention I use Xcode to run the tests, as the problem might come from that.

Are you expecting a setting on one target to be retroactively applied to its dependencies? If so, that is not how it it is supposed to work. A setting belongs to the target and applies only to that target.

Yes! That is correct! I was hoping the setting would traverse the dependency tree (aka being able to configure a dependency via setting a flag on the main target)

Is there an idiomatic way of achieving this with SPM?

Well the idiomatic way would be with “package flavours”, a feature that still languishes in the land of the hypothetical. You can search for that term on the forums to get an idea of the eventual intent.

In the meantime, most of us are accustomed to working around it by using environment variables like this. Note that you need to import Foundation to use ProcessInfo. The variable can then be set on the command line before swift build and xcodebuild. The Xcode UI will also inherit the environment if launched from the command line, but most of us find it more convenient to just temporarily comment out the if to jump back and forth between modes while we work.

Settings are easy to apply universally like this.


That's the workaround I currently use. Unfortunately, Xcode doesn't properly pass the env var when set in the UI so I'm stuck with running test from the command line. I'll keep an eye on package flavours, thanks!

Terms of Service

Privacy Policy

Cookie Policy