Description
If a Swift package contains an asset catalog, in iOS 17+/macOS 14+, Xcode will generate Swift extensions for ColorResource and ImageResource for each color and image asset in the catalog. For example, if a color is named "primaryBackground" in the catalog, Xcode will generate a file with these contents:
@available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *)
extension DeveloperToolsSupport.ColorResource {
/// The "primaryBackground" asset catalog color resource.
static let primaryBackground = DeveloperToolsSupport.ColorResource(name: "primaryBackground", bundle: resourceBundle)
}
The color can then be instantiated with Color(.primaryBackground)
.
When using rules_swift_package_manager, if you depend on a package that uses these accessors, the build fails with the following error:
external/rules_swift_package_manager++swift_deps+swiftpkg_dependency/Sources/Dependency/Dependency.swift:7:50: error: reference to member 'primaryBackground' cannot be resolved without a contextual type
5 | public static let primaryAccent = Color(.primaryAccent)
6 | public static let secondaryAccent = Color(.secondaryAccent)
7 | public static let primaryBackground = Color(.primaryBackground)
| `- error: reference to member 'primaryBackground' cannot be resolved without a contextual type
I've created a sample project to demonstrate this issue. Clone the repo, then run:
bazel build //Example
Of course, this problem is not specific to Swift packages, so I'd imagine we could benefit from a new rule in rules_apple like "apple_xcassets_accessors" or something. Because of this, let me know if you think this issue is misplaced here.