Skip to content

[repro] module maps created for or on objc_library do not propagate to transitive objc_library #1532

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aaronsky
Copy link
Contributor

@aaronsky aaronsky commented Jun 4, 2025

this is a repro of an issue i've identified while trying to move to mixed_language_library from our custom macro. Regardless of how module_map is hinted in swift_interop_info, generated, or otherwise attached to an objc_library, out-of-the-box these module maps are not propagated to downstream objc_library in a objc -> swift -> objc arrangement. this is especially problematic in scenarios where PrintAsClang, going by its own uncontrollable heuristics (in this case, the addition of a lightweight generic in a public-facing objc type), inserts an @import line for the upstream objc library in a generated header.

this is something that needs to change in either swift_clang_module_aspect or objc_library to discover or otherwise propagate the upstream module maps, as this simple example does not work without customization of the rules or introducing manual dependencies on modulemaps (which isn't possible if relying on the generated modulemaps from the aspect).

aaronsky added 2 commits June 4, 2025 14:10
…o transitive objc_library

this is a repro of an issue i've identified while trying to move to `mixed_language_library` from our custom macro. Regardless of how `module_map` is hinted in `swift_interop_info`, generated, or otherwise attached to an `objc_library`, out-of-the-box these module maps are not propagated to downstream `objc_library` in a `objc -> swift -> objc` arrangement. this is especially problematic in scenarios where PrintAsClang, going by its own uncontrollable heuristics, inserts an `@import` line for the upstream objc library in a generated header.

this is something that needs to change in either `swift_clang_module_aspect` or `objc_library` to discover or otherwise propagate the upstream module maps, as this simple example does not work without customization of the rules or introducing manual dependencies on modulemaps (which isn't possible if relying on the generated modulemaps from the aspect).
@aaronsky
Copy link
Contributor Author

aaronsky commented Jun 6, 2025

i think this is related to #1174

@jschear
Copy link
Contributor

jschear commented Jun 9, 2025

My understanding is that this is "working as intended" from the point of view of Bazel core -- module maps are only used for importing clang modules into Swift. Even if you had objc_library(a) depending on objc_library(b) (with a module map provided), modular imports wouldn't work: bazelbuild/bazel#9429

I'm trying to use this intermediate rule (which pulls out the aspect-generated module map and kind of misuses CcInfo's headers and includes) as a workaround, though it hasn't been battle-tested yet: https://gist.github.com/jschear/721fda69fc64efb5820855def1615bc0

rules_swift_package_manager has a similar approach, generating its own modulemaps and propagating them through a CcInfo.

I would support fixing this in objc_library, but I'm not sure if that would be accepted. There was an attempt long ago that stalled, pre-starlarkification. bazelbuild/bazel#6243

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