cgrindel/rules_spm

Bazel mode regression in `0.11.1`

Opened this issue · 5 comments

In 0.11.0 the below WORKSPACE file builds correctly for both build modes, however, in 0.11.1 this is broken when building with Bazel.

WORKSPACE:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "cgrindel_rules_spm",
    sha256 = "d36697e83720e4dc29a97c7a8f1a02858b3c6ce51fa645be3faa03f51dbc1151",
    strip_prefix = "rules_spm-0.11.1",
    urls = [
        "http://github.com/cgrindel/rules_spm/archive/v0.11.1.tar.gz",
    ],
)

http_archive(
    name = "build_bazel_rules_swift",
    sha256 = "51efdaf85e04e51174de76ef563f255451d5a5cd24c61ad902feeadafc7046d9",
    url = "https://github.com/bazelbuild/rules_swift/releases/download/1.2.0/rules_swift.1.2.0.tar.gz",
)

load(
    "@build_bazel_rules_swift//swift:repositories.bzl",
    "swift_rules_dependencies",
)

swift_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:extras.bzl",
    "swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()


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

spm_rules_dependencies()

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

spm_repositories(
    name = "packages",
    build_mode = "bazel",
    dependencies = [
        spm_pkg(
            "https://github.com/apple/swift-argument-parser",
            exact_version = "1.1.4",
            products = ["ArgumentParser"],
        ),
    ],
    platforms = [".macOS(.v10_15)"],
    swift_version = "5.5",
)

Command:

bazel build @packages//swift-argument-parser:ArgumentParser                   

Error:

INFO: Repository packages instantiated at:
  /Users/lpadron/Development/rules_spm_tests/swift-argument-parser/WORKSPACE:42:17: in <toplevel>
Repository rule spm_repositories defined at:
  /private/var/tmp/_bazel_lpadron/c6bc6d4775904d1b0ef5909dd250fe57/external/cgrindel_rules_spm/spm/private/spm_repositories.bzl:595:35: in <toplevel>
ERROR: An error occurred during the fetch of repository 'packages':
   Traceback (most recent call last):
        File "/private/var/tmp/_bazel_lpadron/c6bc6d4775904d1b0ef5909dd250fe57/external/cgrindel_rules_spm/spm/private/spm_repositories.bzl", line 593, column 30, in _spm_repositories_impl
                _configure_spm_repository(repository_ctx, pkgs, env)
        File "/private/var/tmp/_bazel_lpadron/c6bc6d4775904d1b0ef5909dd250fe57/external/cgrindel_rules_spm/spm/private/spm_repositories.bzl", line 483, column 31, in _configure_spm_repository
                dep_pkg_desc = pds.get(
        File "/private/var/tmp/_bazel_lpadron/c6bc6d4775904d1b0ef5909dd250fe57/external/cgrindel_rules_spm/spm/private/package_descriptions.bzl", line 142, column 50, in _get_package_description
                pkg_manifest = _retrieve_package_manifest(
        File "/private/var/tmp/_bazel_lpadron/c6bc6d4775904d1b0ef5909dd250fe57/external/cgrindel_rules_spm/spm/private/package_descriptions.bzl", line 104, column 58, in _retrieve_package_manifest
                manifest_json_str = repository_utils.exec_spm_command(
        File "/private/var/tmp/_bazel_lpadron/c6bc6d4775904d1b0ef5909dd250fe57/external/cgrindel_rules_spm/spm/private/repository_utils.bzl", line 52, column 13, in _execute_spm_command
                fail(err_msg_tpl.format(
Error in fail: Failed to execute SPM command. name: packages, args: ["xcrun", "swift", "run", "spm_parser", "/private/var/tmp/_bazel_lpadron/c6bc6d4775904d1b0ef5909dd250fe57/external/packages/spm_build/checkouts/swift-argument-parser"]
Updating https://github.com/apple/swift-package-manager
Updated https://github.com/apple/swift-package-manager (0.80s)
Updating https://github.com/apple/swift-llbuild.git
Updated https://github.com/apple/swift-llbuild.git (0.58s)
Updating https://github.com/apple/swift-tools-support-core.git
Updated https://github.com/apple/swift-tools-support-core.git (0.50s)
Updating https://github.com/apple/swift-driver.git
Updated https://github.com/apple/swift-driver.git (0.37s)
Updating https://github.com/jpsim/Yams.git
Updating https://github.com/apple/swift-collections.git
Fetching https://github.com/apple/swift-argument-parser from cache
error: Dependencies could not be resolved because root depends on 'swift-argument-parser' 1.0.1..<1.1.0 and root depends on 'swift-argument-parser' 1.2.0..<2.0.0.
Updated https://github.com/apple/swift-collections.git (0.42s)
Updating https://github.com/apple/swift-system.git
Updated https://github.com/jpsim/Yams.git (0.45s)
Fetching https://github.com/apple/swift-crypto.git from cache
.
ERROR: /Users/lpadron/Development/rules_spm_tests/swift-argument-parser/WORKSPACE:42:17: fetching spm_repositories rule //external:packages: Traceback (most recent call last):
        File "/private/var/tmp/_bazel_lpadron/c6bc6d4775904d1b0ef5909dd250fe57/external/cgrindel_rules_spm/spm/private/spm_repositories.bzl", line 593, column 30, in _spm_repositories_impl
                _configure_spm_repository(repository_ctx, pkgs, env)
        File "/private/var/tmp/_bazel_lpadron/c6bc6d4775904d1b0ef5909dd250fe57/external/cgrindel_rules_spm/spm/private/spm_repositories.bzl", line 483, column 31, in _configure_spm_repository
                dep_pkg_desc = pds.get(
        File "/private/var/tmp/_bazel_lpadron/c6bc6d4775904d1b0ef5909dd250fe57/external/cgrindel_rules_spm/spm/private/package_descriptions.bzl", line 142, column 50, in _get_package_description
                pkg_manifest = _retrieve_package_manifest(
        File "/private/var/tmp/_bazel_lpadron/c6bc6d4775904d1b0ef5909dd250fe57/external/cgrindel_rules_spm/spm/private/package_descriptions.bzl", line 104, column 58, in _retrieve_package_manifest
                manifest_json_str = repository_utils.exec_spm_command(
        File "/private/var/tmp/_bazel_lpadron/c6bc6d4775904d1b0ef5909dd250fe57/external/cgrindel_rules_spm/spm/private/repository_utils.bzl", line 52, column 13, in _execute_spm_command
                fail(err_msg_tpl.format(
Error in fail: Failed to execute SPM command. name: packages, args: ["xcrun", "swift", "run", "spm_parser", "/private/var/tmp/_bazel_lpadron/c6bc6d4775904d1b0ef5909dd250fe57/external/packages/spm_build/checkouts/swift-argument-parser"]
Updating https://github.com/apple/swift-package-manager
Updated https://github.com/apple/swift-package-manager (0.80s)
Updating https://github.com/apple/swift-llbuild.git
Updated https://github.com/apple/swift-llbuild.git (0.58s)
Updating https://github.com/apple/swift-tools-support-core.git
Updated https://github.com/apple/swift-tools-support-core.git (0.50s)
Updating https://github.com/apple/swift-driver.git
Updated https://github.com/apple/swift-driver.git (0.37s)
Updating https://github.com/jpsim/Yams.git
Updating https://github.com/apple/swift-collections.git
Fetching https://github.com/apple/swift-argument-parser from cache
error: Dependencies could not be resolved because root depends on 'swift-argument-parser' 1.0.1..<1.1.0 and root depends on 'swift-argument-parser' 1.2.0..<2.0.0.
Updated https://github.com/apple/swift-collections.git (0.42s)
Updating https://github.com/apple/swift-system.git
Updated https://github.com/jpsim/Yams.git (0.45s)
Fetching https://github.com/apple/swift-crypto.git from cache
.
ERROR: Failed to execute SPM command. name: packages, args: ["xcrun", "swift", "run", "spm_parser", "/private/var/tmp/_bazel_lpadron/c6bc6d4775904d1b0ef5909dd250fe57/external/packages/spm_build/checkouts/swift-argument-parser"]
Updating https://github.com/apple/swift-package-manager
Updated https://github.com/apple/swift-package-manager (0.80s)
Updating https://github.com/apple/swift-llbuild.git
Updated https://github.com/apple/swift-llbuild.git (0.58s)
Updating https://github.com/apple/swift-tools-support-core.git
Updated https://github.com/apple/swift-tools-support-core.git (0.50s)
Updating https://github.com/apple/swift-driver.git
Updated https://github.com/apple/swift-driver.git (0.37s)
Updating https://github.com/jpsim/Yams.git
Updating https://github.com/apple/swift-collections.git
Fetching https://github.com/apple/swift-argument-parser from cache
error: Dependencies could not be resolved because root depends on 'swift-argument-parser' 1.0.1..<1.1.0 and root depends on 'swift-argument-parser' 1.2.0..<2.0.0.
Updated https://github.com/apple/swift-collections.git (0.42s)
Updating https://github.com/apple/swift-system.git
Updated https://github.com/jpsim/Yams.git (0.45s)
Fetching https://github.com/apple/swift-crypto.git from cache
.
INFO: Elapsed time: 4.989s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)

This is probably related to the fact that spm_parser uses 1.2.0 version of swift-argument-parser (here) and the parser gets run via swift run which fetches and rebuilds as needed.

However, its confusing that these versions would collide since they should be in separate packages?

Looking at it a bit more, it seems like maybe caused by this change in Package.swift of swift-argument-parser: https://github.com/apple/swift-argument-parser/blob/main/Package%40swift-5.6.swift#L94-L108

@luispadron I just reverted the incompatible version upgrade in #193. I will push a release in a few minutes.

Thanks! Wonder though what a solution here is that doesn't care about what version the internal tool is on?

Release: v0.11.2

It stems from the fact that swift-package-manager is pinned to 1.0.x releases for swift-argument-parser. I updated the spm_parser package to have the same dependency definition. Right now, I don't have a better solution.