bazelbuild / rules_swift

Bazel rules to build Swift on Apple and Linux platforms

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CC_Library without a tag does not generate a ModuleMap

RStanbouly opened this issue · comments

In Swift_C_Module.bzl, the documentation mentions that

**Use an auto-generated module map.** In this case, the `swift_c_module`
    rule is not needed. If a `cc_library` is a direct dependency of a
    `swift_{binary,library,test}` target, a module map will be automatically
    generated for it and the module's name will be derived from the Bazel target
    label (in the same fashion that module names for Swift targets are derived).
    The module name can be overridden by setting the `swift_module` tag on the
    `cc_library`; e.g., `tags = ["swift_module=MyModule"]`.

However, despite the documentation, not setting a tag leads to no modulemap being generated.

Is doing tags = ["swift_module"], what you're looking for (without a modulemap)

tags = FIXTURE_TAGS + ["swift_module"],

Woops, apologies, I accidentally did not have my followup comment outside of the code portion.

I'm looking to not have to set the tag at all, and instead have the module name be derived from the bazel target as per the documentation.

based on this code

# TODO: Remove once we cherry-pick the `swift_interop_hint` rule
if not module_name and aspect_ctx.rule.kind == "cc_library":
I do think we're supposed to still be doing that for direct cc_library dependencies. Can you add a repro case here (or better yet a failing test)

The CC Library looked like

cc_library(
    name = "testLibrary",
    srcs = ["CxxTest.cpp"],
    hdrs = ["CxxTest.hpp"],
    visibility = ["//visibility:public"],
)

Which upon adding to a swift_library as a dependency, no swiftmodule was created

note that the behavior might differ for C vs C++, since until very recently Swift doesn't support C++ interop (and it's still disabled by default)

I've successfully been able to have the modulemap generated when doing

cc_library(
    name = "testLibrary",
    srcs = ["CxxTest.cpp"],
    hdrs = ["CxxTest.hpp"],
    tags = ["swift_module=testLibrary"],
    visibility = ["//visibility:public"],
    deps = ["@com_google_protobuf//:protobuf"],
)

instead