swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.7k stars 1.33k forks source link

[SR-13962] Interface builder ignores SupportedPlatforms value for Swift packages with IBDesignables #4459

Open swift-ci opened 3 years ago

swift-ci commented 3 years ago
Previous ID SR-13962
Radar rdar://problem/72302322
Original Reporter nico.elayda (JIRA User)
Type Bug

Attachment: Download

Environment Xcode 12.2 (12B45b) / Xcode 12.3 RC (12C33) macOS 11.0.1 (20B50)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Package Manager | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 89ea42b3e6423f999fc0b2088b90c040

Issue Description:

When using an IBDesignable component from an SPM package as a custom class in an interface builder document, it is being built for platforms other than the ones specified in the package description to render the designables. This only occurs when the IBDesignable is inside an SPM package.

To reproduce the issue:

1. Create a new swift package with the following package description (note the value for platforms).

// swift-tools-version:5.3

import PackageDescription

let package = Package(
 name: "SPMDesignablePackage",
 platforms: [
 .iOS(.v12)
 ],
 products: [
 .library(
 name: "SPMDesignablePackage",
 targets: ["SPMDesignablePackage"]),
 ],
 targets: [
 .target(name: "SPMDesignablePackage"),
 ]
)

2. Create a single source file SPMDesignableControl.swift in the Sources directory of this package.

import UIKit

@IBDesignable
public class SPMDesignableControl: UIView {

 @IBInspectable public var designableColorProperty: UIColor = .blue

 public override func prepareForInterfaceBuilder() {
 super.prepareForInterfaceBuilder()
 backgroundColor = designableColorProperty
 }
}

3. Create a new Xcode project and drag this new package to the Project Navigator.

  1. Add this package as a dependency in the Frameworks, Libraries, and Embedded Content section of the build target.
  2. In Main.storyboard, add a UIView and set this view's Custom Class to SPMDesignableControl in the Identity Inspector.
  3. Click on Editor > Refresh All Views to force the designables to render.
  4. The Identity Inspector for SPMDesignableControl will show a build error, with a message expecting the existence of a tvOS product/target.

My expectation is since iOS is the only explicitly specified platform in the package description, it should not attempt to build the package sources for tvOS (or other platforms).

I've also seen multiple threads describing a similar issue with no solution:
https://developer.apple.com/forums/thread/652552
https://developer.apple.com/forums/thread/652558
https://developer.apple.com/forums/thread/661391
https://stackoverflow.com/questions/64881772/

A zip archive is attached below containing the SPM package (SPMDesignablePackage) and sample project setup (SPMDesignablePackageUser).

typesanitizer commented 3 years ago

@swift-ci create