rules_swift icon indicating copy to clipboard operation
rules_swift copied to clipboard

CC_Library without a tag does not generate a ModuleMap

Open RStanbouly opened this issue 1 year ago • 6 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.

RStanbouly avatar Feb 08 '24 22:02 RStanbouly

Is doing tags = ["swift_module"], what you're looking for (without a modulemap) https://github.com/bazelbuild/rules_swift/blob/da4eafef6401442b8c1b481d43dfa65907e8bf23/test/fixtures/private_deps/BUILD#L55

keith avatar Feb 08 '24 23:02 keith

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.

RStanbouly avatar Feb 08 '24 23:02 RStanbouly

based on this code https://github.com/bazelbuild/rules_swift/blob/da4eafef6401442b8c1b481d43dfa65907e8bf23/swift/internal/swift_clang_module_aspect.bzl#L405-L406 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)

keith avatar Feb 08 '24 23:02 keith

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

RStanbouly avatar Feb 08 '24 23:02 RStanbouly

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)

keith avatar Feb 08 '24 23:02 keith

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

RStanbouly avatar Feb 09 '24 00:02 RStanbouly