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

When cc rules depend on objc_library, headers of transitive dependencies are dropped #10738

Closed
cpsauer opened this issue Feb 9, 2020 · 2 comments
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: bug

Comments

@cpsauer
Copy link
Contributor

cpsauer commented Feb 9, 2020

Hi wonderful Bazel folk,

I'm pretty sure I've found a bug in the interaction between cc rules and objc_library, which makes them hard to use together in meaningfully sized dependency graphs.

Offhand, my guess is that the fix would need to be on the cc side.

Background:

C-style language rules (cc_library, objc_library, etc.) need to propagate their hrs to all rules that might transitively #include them. In practice, that means that the hrs need to be propagated to all c-style rules that depend on them, transitively or directly. In Bazel, this already works when cc rules depend on each other, when objc rules depend on each other, and when objc rules depend on cc rules.

The Issue

The case that's broken is cc rules depending on objc rules. The hdrs of the objc rules' dependencies get dropped, and the build fails when the cc rule tries to #include on the the headers of an objc rule that #includes its dependencies.

Here's a minimal example of the issue.

Test.zip

  • It contains three targets: A, B, and C.
  • A.c #includes B.h, which #includes C.h
    • Therefore, the include graph looks like A -> B -> C.
    • The deps graph is hooked up the same way, so there should never be missing headers

Now we'll try building //:A: bazel build A:
If A, B, and C are all cc_librarys, this works. Same if they're all objc_libraries.
All the following cases work as expected:

  • cc -> cc -> cc
  • cc -> cc -> objc
  • objc -> objc -> objc
  • objc -> objc -> cc
  • objc -> cc -> objc
  • objc -> cc -> cc

These two cases are broken (project left configured in the first of these cases):

  • cc -> objc -> cc
  • cc -> objc -> objc

In both cases, building fails with the error

 In file included from A.c:1:
./B.h:1:10: fatal error: 'C.h' file not found
#include "C.h"

My conclusion

cc rules seem to fail to pick up the hdrs of the deps of objc rules. (Other cases work as expected.) This happens whether those dependencies are cc rules or objc rules. The expected behavior would be that objc rules would propagate the hdrs of their deps the same way as cc rules do, or objc rules do with each other.

Severity

You can work around this issue, but it's fairly ugly. This issue would come up whenever someone uses an objc_library to bridge from C/C++ into a meaningfully-sized Objective-C or Objective-C++ implementation, as happens with cross-platform code with a backend for Apple platforms.

Thanks,
Chris
(ex-Googler)

@cpsauer
Copy link
Contributor Author

cpsauer commented Feb 10, 2020

It would appear that there's a related issue where archives get dropped when cc_library -> objc_library -> objc_import. Discovered that while working around #10740

@dslomov dslomov added team-Rules-CPP Issues for C++ rules untriaged labels Feb 10, 2020
@oquenchil oquenchil added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels Feb 18, 2020
@oquenchil oquenchil added P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) type: bug and removed P2 We'll consider working on this in future. (Assignee optional) labels Nov 19, 2020
@cpsauer
Copy link
Contributor Author

cpsauer commented Apr 10, 2021

This was fixed, I'm pretty sure by #10674--given what I've learned about Bazel since writing this long ago.

Thanks, @googlewalt! Really appreciate your making C++ -> Obj-C dependencies work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) team-Rules-CPP Issues for C++ rules type: bug
Projects
None yet
Development

No branches or pull requests

3 participants