Trying out the new package trait support in Xcode 26.4 and it seems like the default traits for the package are being enabled even when explicitly set to disabled. At first I thought it was something wonky in the Xcode UI around the new support for traits. I've been able to replicate the issue with just two Swift packages, so no Xcode UI for setting the traits.
Feature package
// swift-tools-version: 6.3
import PackageDescription
let package = Package(
name: "MyAwesomeFeature",
platforms: [
.macOS(.v26)
],
products: [
.library(
name: "MyAwesomeFeature",
targets: ["MyAwesomeFeature"]
)
],
traits: [
.trait(name: "SomeBetaFeature"),
.default(enabledTraits: ["SomeBetaFeature"]),
],
targets: [
.target(
name: "MyAwesomeFeature"
),
],
swiftLanguageModes: [.v6]
)
For the sake of testing I've given it a simple object that just prints if the trait is enabled
Inside MyAwesomeFeature
public struct SomeObject {
func printTraitStatus() {
#if SomeBetaFeature
print("Beta feature enabled")
#else
print("Beta feature disabled")
#endif
}
}
I then have a second package that depends on the feature and produces an executable
// swift-tools-version: 6.3
import PackageDescription
let package = Package(
name: "SwiftPackageBasedProgram",
platforms: [
.macOS(.v26),
],
products: [],
dependencies: [
.package(name: "MyAwesomeFeature", path: "../MyAwesomeFeature", traits: [])
],
targets: [
.executableTarget(
name: "MyAwesomeProgram",
dependencies: [
.product(name: "MyAwesomeFeature", package: "MyAwesomeFeature")
]
),
],
swiftLanguageModes: [.v6]
)
If I run MyAwesomeProgram from the command line with swift run I get the output I would expect
Build of product 'MyAwesomeProgram' complete! (6.10s)
Inside SwiftPM program
Beta feature disabled
If I run the same program from within Xcode though
Inside SwiftPM program
Beta feature enabled
Program ended with exit code: 0
I've got the sample project available here if anyone wants to try it out.
Has anyone else come across anything like this? Very possible I'm just missing something.