The Tuist CLI 4.124.0 supports integrating Swift packages with Traits

Hi!

You might have noticed that Apple introduced the concept of traits into Swift Packages as a way to declare another compile-time dimension to include/exclude code. In practice they map to Swift compiler directives.

Those worked fine in Tuist generated projects if you integrated them using Xcode’s default integration of packages, but if you used .external, they failed to integrate because we didn’t have support for them.

Luckily, that has changed with 4.124.0. Now you should be able to declare a .external dependency with packages like swift-configuration that use traits, and Tuist should be able to integrate them. You’ll notice in the build settings of the generated targets for the package products that it includes the compiler directives.

The source of truth of the traits you want to use for your dependencies is the Package.swift:

let package = Package(
    name: "App",
    dependencies: [
        .package(path: "../Package", traits: [.trait(name: "Tuist")]),
        // Add your own dependencies here:
        // .package(url: "https://github.com/Alamofire/Alamofire", from: "5.0.0"),
        // You can read more about dependencies here: https://docs.tuist.io/documentation/tuist/dependencies
    ]
)

Notice the .package API includes a traits: attribute where you declare the traits. At generation time Tuist will read those and set the right build settings in the Xcode project targets generated for your packages.

Please, let me know if you encounter any issue