SPM Resources only in debug configuration

Very excitied to try out SPM resources support!

I was wondering if there was any way to exclude certain assets from the release configuration of a package? I was hoping to exclude my “Preview Assets.xcassets” catalog.

The exclude option seemed promising, but there doesn’t appear to be a way to condition it. I don’t think you can use #if DEBUG in a Package.swift. Is there anything like BuildSettingCondition, but for resources?

6 Likes

I have the same question !

1 Like

This isn't supported right now, but sounds like an interesting future direction to explore.

2 Likes

Ah, gotcha! Wondering if there’s at least a workaround to suggest for now.

What if these resources were placed in a separate target? Are there any tricks for conditionally linking two targets between dev and release configurations?

If you put them in a separate target and forward them with public accessors, then the main target could put #if DEBUG around the import, and use dependencies: [.target(..., condition: .when(configuration: .debug))] in the manifest to prevent it from being included in the product.

That sounds useful! But I couldn't seem to get it working. It appears that TargetDependencyCondition only supports .when(.platforms), but no .configuration.

Interesting. I hadn’t tried it myself. I copied and pasted from the text of SE‐0273. Maybe its implementation is incomplete? Or it was accepted with revisions that never made it back into the document? @NeoNacho was review manager.

Yep, it is, only the platform part is implemented. It was incorrectly updated to fully implemented, let me fix that.

Updated the status to

Partially implemented (Swift 5.3 supports platform conditionals, but not configuration conditionals)

now.

4 Likes

When you search the evolution proposals, it still shows up as Implemented: Swift Evolution
But maybe that can't be fixed?

What is important is - is this feature still being tracked somewhere, or is it falling through the cracks?

2 Likes

Friendly bump.

2 Likes

@NeoNacho what is the state on this matter? What is currently blocking implementation?

5 Likes

This post outlines a use case that I'm also actively seeking: The ability to share stub-like data between tests in a package and Xcode previews in an app -- without having to include that said data in release builds.

1 Like

Hey everyone. Has there been any progress on supporting configuration conditions?

We would like to link one version of a framework for debug builds and another for release builds, but can't seem to find a way to do that.

4 Likes

Here is another +1 for this functionality. I am working on a project that is divided in many self-contained SPM packages. I’d like to have fully-featured SwiftUI previews in the packages, with some resources as part of the package, that would be included only in a debug build for SwiftUI previews. Couldn’t find a way to do this currently (as of May 2022).

4 Likes

+1 for varying dependencies and resources by configuration.

3 Likes

Another +1 as I have the exact same use case as @JaanusK.

1 Like

I have the exact same requirement. But have no way to achieve it sofar.

The only solution I found is kind of a workaround. I have a demo app that renders the view and injects the resources.

+1 I have the same use case