Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CC_Library without a tag does not generate a ModuleMap #1166

Open
RStanbouly opened this issue Feb 8, 2024 · 6 comments
Open

CC_Library without a tag does not generate a ModuleMap #1166

RStanbouly opened this issue Feb 8, 2024 · 6 comments

Comments

@RStanbouly
Copy link

RStanbouly commented Feb 8, 2024

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.

@keith
Copy link
Member

keith commented Feb 8, 2024

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

tags = FIXTURE_TAGS + ["swift_module"],

@RStanbouly
Copy link
Author

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.

@keith
Copy link
Member

keith commented Feb 8, 2024

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)

@RStanbouly
Copy link
Author

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

@keith
Copy link
Member

keith commented Feb 8, 2024

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)

@RStanbouly
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants