cgrindel / rules_spm

Provide a means for integrating external Swift packages built by Swift Package Manager into Bazel build using rules_swift.
Apache License 2.0
58 stars 13 forks source link

attribute 'srcs' in 'filegroup' rule: invalid target name '_:).json': #213

Closed AttilaTheFun closed 1 year ago

AttilaTheFun commented 1 year ago

Hi! I'm trying to use rules_spm to get one of my apps building with Bazel.

I tried to follow your Quickstart guide and I'm getting this error from one of my swift package dependencies:

logan@Logans-MBP Stetho % bazel build //Stetho
ERROR: /private/var/tmp/_bazel_logan/fb85e7e43f35393064b64827ed702e79/external/swift_packages/BUILD.bazel:12:10: @swift_packages//:all_srcs: invalid label 'spm_build/checkouts/SpotifyAPI/docs/data/documentation/spotifywebapi/album/!=(_:_:).json' in element 1013 of attribute 'srcs' in 'filegroup' rule: invalid target name '_:).json': target names may not contain ':'
ERROR: /private/var/tmp/_bazel_logan/fb85e7e43f35393064b64827ed702e79/external/swift_packages/SpotifyAPI/BUILD.bazel:14:18: Target '@swift_packages//:build' contains an error and its package is in error and referenced by '@swift_packages//SpotifyAPI:SpotifyWebAPI_swiftmodule'
ERROR: Analysis of target '//Stetho:Stetho' failed; build aborted: 
INFO: Elapsed time: 0.071s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)

This is the Swift Package it appears to be failing on: https://github.com/Peter-Schorn/SpotifyAPI/blob/master/Package.swift

My WORKSPACE.bzl has:

# Rules SPM

http_archive(
    name = "cgrindel_rules_spm",
    sha256 = "777e687245faa7340488e61f5abb23b95b4c0e27e05f7cea7318c03e4cc38289",
    strip_prefix = "rules_spm-0.11.2",
    urls = [
        "http://github.com/cgrindel/rules_spm/archive/v0.11.2.tar.gz",
    ],
)

load(
    "@cgrindel_rules_spm//spm:deps.bzl",
    "spm_rules_dependencies",
)

spm_rules_dependencies()

# SPM Packages

load("@cgrindel_rules_spm//spm:defs.bzl", "spm_pkg", "spm_repositories")

spm_repositories(
    name = "swift_packages",
    dependencies = [
        spm_pkg(
            "https://github.com/Peter-Schorn/SpotifyAPI.git",
            exact_version = "2.2.2",
            products = ["SpotifyAPI"],
        ),
        spm_pkg(
            "https://github.com/onevcat/Kingfisher.git",
            exact_version = "7.5.0",
            products = ["Kingfisher"],
        ),
    ],
)

And my BUILD file has:

swift_library(
    name = "StethoLibrary",
    module_name = "Stetho",
    srcs = glob([
        "Sources/*.swift",
    ]),
    deps = [
        "@swift_packages//SpotifyAPI:SpotifyWebAPI",
        "@swift_packages//Kingfisher:Kingfisher",
    ],
)
cgrindel commented 1 year ago

I see the issue. One of the filenames in this directory is !=(_:_:).json. Bazel is choking on that combination of characters as a valid target name.

The rules_spm project is lightly deprecated. There are some limitations with its design. However, I am actively working on swift_bazel. It is designed to replace rules_spm and provide other niceties like a Swift Gazelle extension. I would recommend trying swift_bazel to bring in those external Swift packages.

(The file should not be a problem if you use swift_bazel. The Swift package manifest does not reference the file. So, it should not appear in any of the Bazel build files that are generated.)

AttilaTheFun commented 1 year ago

Ah okay! I made it further with swift_bazel, but I encountered this new error when trying to archive the app for the App Store: https://github.com/cgrindel/swift_bazel/issues/182 I went into more detail here: https://github.com/bazelbuild/rules_apple/issues/1814 Because I wasn't sure which side this issue was on (rules_apple or swift_bazel)