cgrindel / rules_swift_package_manager

Collection of utilities and Bazel rules to aid in the development and maintenance of Swift repositories using Bazel.
Apache License 2.0
74 stars 26 forks source link

Ambiguous `copt` in release mode #1111

Closed luispadron closed 2 weeks ago

luispadron commented 3 months ago

I was updating my dependencies and ran into a build failure in release mode (e.g. --compilation_mode=opt)

ERROR: /private/var/tmp/_bazel_runner/859a0f9921c91b89cc2a6b233b4f521c/external/rules_swift_package_manager~~swift_deps~swiftpkg_swift_system/BUILD.bazel:23:14: Illegal ambiguous match on configurable attribute "copts" in @@rules_swift_package_manager~~swift_deps~swiftpkg_swift_system//:SystemPackage.rspm:
luispadron commented 3 months ago

Using the following lock for swift-system:

    {
      "identity" : "swift-system",
      "kind" : "remoteSourceControl",
      "location" : "https://github.com/apple/swift-system.git",
      "state" : {
        "revision" : "f9266c85189c2751589a50ea5aec72799797e471",
        "version" : "1.3.0"
      }
    },
cgrindel commented 3 months ago

Did you happen to capture the declaration in the BUILD.bazel file that it does not like?

roya1v commented 2 months ago

Hey @cgrindel ! I had the exact same problem. Here is the part of the BUILD.bazel it didn't like:

swift_library(
name = "SystemPackage.rspm",
always_include_developer_search_paths = True,
copts = [
"-DSWIFT_PACKAGE",
"-DSYSTEM_PACKAGE",
] + select({
"@rules_swift_package_manager//config_settings/spm/configuration:debug": ["-DENABLE_MOCKING"], # <- here
"@rules_swift_package_manager//config_settings/spm/platform:ios": ["-DSYSTEM_PACKAGE_DARWIN"],
"@rules_swift_package_manager//config_settings/spm/platform:macos": ["-DSYSTEM_PACKAGE_DARWIN"],
"@rules_swift_package_manager//config_settings/spm/platform:tvos": ["-DSYSTEM_PACKAGE_DARWIN"],
"@rules_swift_package_manager//config_settings/spm/platform:visionos": ["-DSYSTEM_PACKAGE_DARWIN"],
"@rules_swift_package_manager//config_settings/spm/platform:watchos": ["-DSYSTEM_PACKAGE_DARWIN"],
"//conditions:default": [],
}),
# ...

For me the problem was that it would both match the debug configuration and macos platform, which seems like something that should be allowed. I've changed the implementation so it generates something like this:

swift_library(
    name = "SystemPackage.rspm",
    always_include_developer_search_paths = True,
    copts = [
        "-DSWIFT_PACKAGE",
        "-DSYSTEM_PACKAGE",
    ] + select({
        "@rules_swift_package_manager//config_settings/spm/configuration:debug": ["-DENABLE_MOCKING"],
        "//conditions:default": [],
    }) + select({
        "@rules_swift_package_manager//config_settings/spm/platform:ios": ["-DSYSTEM_PACKAGE_DARWIN"],
        "//conditions:default": [],
    }) + select({
        "@rules_swift_package_manager//config_settings/spm/platform:macos": ["-DSYSTEM_PACKAGE_DARWIN"],
        "//conditions:default": [],
    }) + select({
        "@rules_swift_package_manager//config_settings/spm/platform:tvos": ["-DSYSTEM_PACKAGE_DARWIN"],
        "//conditions:default": [],
    }) + select({
        "@rules_swift_package_manager//config_settings/spm/platform:visionos": ["-DSYSTEM_PACKAGE_DARWIN"],
        "//conditions:default": [],
    }) + select({
        "@rules_swift_package_manager//config_settings/spm/platform:watchos": ["-DSYSTEM_PACKAGE_DARWIN"],
        "//conditions:default": [],
    }),
# ...

I just stated out with bazel so maybe there is a slicker way to do this 🧐