Skip to content

Conversation

@jschear
Copy link
Contributor

@jschear jschear commented Jun 12, 2025

At Square, we're using a headermap for the Swift generated header, so that the objective-C half of a module is able to import it using #import <Module/Module-Swift.h>.

This headermap target can't be placed in deps, as doing so creates a dependency cycle.

Here is an example of what the use case looks like: master...jschear:rules_swift:js/demo_swift_header_imports_in_clang_half

header_map(
    name = "swift_headermap",
    module_name = "MixedAnswer",
    propagate_include = False,
    # This relies on us knowing the naming scheme used for internal targets in mixed_language_library, which is not ideal.
    deps = ["MixedAnswer_swift"],
)

mixed_language_library(
    name = "MixedAnswer",
    hdrs = ["MixedAnswer.h"],
    clang_copts = [
        "-I$(execpath :swift_headermap)",
        "-I.",
    ],
    clang_deps = [":swift_headermap"],
    clang_srcs = [
        "MixedAnswer.m",
        "MixedAnswerPrivate.m",
        "MixedAnswerPrivate.h",
    ],
    enable_modules = True,
    module_name = "MixedAnswer",
    swift_srcs = [
        "MixedAnswer.swift",
    ],
    target_compatible_with = ["@platforms//os:macos"],
)

At Square, we're using a headermap for the Swift generated header, so
that the objective-C half of a module is able to import it using
`#import <Module/Module-Swift.h>`.

This headermap target can't be placed in `deps`, as doing so creates a
dependency cycle.

Here is an example of what the use case looks like:
bazelbuild/rules_swift@master...jschear:rules_swift:js/demo_swift_header_imports_in_clang_half

```
header_map(
    name = "swift_headermap",
    module_name = "MixedAnswer",
    propagate_include = False,
    # This relies on us knowing the naming scheme used for internal targets in mixed_language_library, which is not ideal.
    deps = ["MixedAnswer_swift"],
)

mixed_language_library(
    name = "MixedAnswer",
    hdrs = ["MixedAnswer.h"],
    clang_copts = [
        "-I$(execpath :swift_headermap)",
        "-I.",
    ],
    clang_deps = [":swift_headermap"],
    clang_srcs = [
        "MixedAnswer.m",
        "MixedAnswerPrivate.m",
        "MixedAnswerPrivate.h",
    ],
    enable_modules = True,
    module_name = "MixedAnswer",
    swift_srcs = [
        "MixedAnswer.swift",
    ],
    target_compatible_with = ["@platforms//os:macos"],
)
```
@jschear jschear changed the title Add clang_deps attr to mixed_language_library (#1540) 2.x cherry-pick: Add clang_deps attr to mixed_language_library (#1540) Jun 12, 2025
@luispadron luispadron merged commit aa175e1 into bazelbuild:2.x Jun 12, 2025
12 checks passed
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

Successfully merging this pull request may close these issues.

2 participants