Exclude directories per platform not working?

I'm trying to exclude directories based on a macro condition. The simple example below does not work. It completely ignores the macros and includes all the files:

let package = Package(
    name: "MyLibrary",
    platforms: [
        .iOS(.v11),
        .watchOS(.v4)
    ],
    products: [
        .library(
            name: "MyLibrary",
            targets: ["MyLibrary"]
        )
    ],
    targets: [
        .target(
            name: "MyLibrary",
            dependencies: [],
            exclude: {
                var exclude: [String] = []
                
                #if os(iOS)
                    exclude.append("Platforms/iOS")
                    exclude.append("Platforms/watchOS")
                #endif
                
                #if os(watchOS)
                    exclude.append("Platforms/iOS")
                    exclude.append("Platforms/watchOS")
                #endif
                
                return exclude
            }()
        ),
        .testTarget(
            name: "MyLibraryTests",
            dependencies: ["MyLibrary"]
        )
    ]
)

It should not compile when building for an iOS or watchOS app, but it ignores the excludes and compiles fine. Is there another macro condition I should use in the manifest or is this a known issue?

1 Like

The manifest is compiled for the host platform, not the target platform. This sort of thing works for macOS vs Linux (though it’s not recommended), but it does not work for platforms like iOS that are cross‐compiled.

The only available option right now is to put the compilation conditions in the source files themselves (which is admittedly more repetition than anyone wants...)

1 Like