rules_swift
rules_swift copied to clipboard
CC_Library without a tag does not generate a ModuleMap
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) https://github.com/bazelbuild/rules_swift/blob/da4eafef6401442b8c1b481d43dfa65907e8bf23/test/fixtures/private_deps/BUILD#L55
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 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)
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