bazel icon indicating copy to clipboard operation
bazel copied to clipboard

Headers not propagated from objc_library to cc_library.

Open chetgnegy opened this issue 9 years ago • 9 comments

Description of the problem / feature request / question:

I have lots of purely C++ libraries that depend on a library that internally uses Objective C (when built on OSX). The Objective C is not exposed through any header in this library.

If possible, provide a minimal example to reproduce the problem:

TestFolder/my_header.h

int k = 0;

TestFolder/test.cc

#include "TestFolder/my_header.h"
#include <stdio.h>
int main(void) { printf("%d\n", k); }  // k is defined in the header.

TestFolder/BUILD

objc_library(
    name = "ObjcLib",
    hdrs = ["my_header.h"],
)

cc_binary(
  name = "Test",
  srcs = ["test.cc"],
  deps = [":ObjcLib"],
)

If I make both libraries cc_* targets this works. If I make both libraries objc_* targets this works. I don't want a single objc_library to infect all of my C++ code. This code needs to compile on both OSX and on Linux, where objc_library presumably doesn't work.

I actually care about this example below, but the above is a simplified version of what is likely the same issue:

TestFolder/BUILD

cc_library(   # I don't really care if this is a cc or objc library.
    name = "TextualHeaderTarget",
    textual_hdrs = ["my_header.h"],
)

objc_library(
    name = "ObjcLib",
    srcs = [":TextualHeaderTarget"],
)

cc_binary(
  name = "Test",
  srcs = ["test.cc"],
  deps = [":ObjcLib"],
)

Environment info

  • Operating System: OSX 10.11.6

  • Bazel version (output of bazel info release): release 0.5.2-homebrew

Related: https://groups.google.com/forum/#!msg/bazel-discuss/IAtDeYJ4Mi8/HWhQ_K9TryMJ I didn't see any issues that were obviously related. This looks like a way to perhaps hack around the issue: https://github.com/bazelbuild/bazel/issues/2420

chetgnegy avatar Jul 11 '17 05:07 chetgnegy

Please let me know if you have any suggestions for workarounds. I am blocked on this at the moment. Thanks!

chetgnegy avatar Jul 12 '17 00:07 chetgnegy

Has there been any progress here? An ETA?

chetgnegy avatar Feb 09 '18 04:02 chetgnegy

https://github.com/bazelbuild/bazel/commit/db61b316458685344d3aa4b6a784f09001a90892 should have addressed this, please let us know if your problem continues.

calpeyser avatar Feb 27 '18 01:02 calpeyser

Thanks, Cal. I'm still finding that I can't build either of the examples above at Bazel version 0.11.0.

chetgnegy avatar Feb 27 '18 02:02 chetgnegy

It doesn't look like db61b31 is in Bazel 0.11.0: https://github.com/bazelbuild/bazel/commits/0.11.0

calpeyser avatar Feb 27 '18 18:02 calpeyser

How does whoever prepares releases decide what commits will make the cut? It looks like it's not in 0.12.0 either, even though newer changes are included and this one is many months old. I'm fumbling around with building Bazel from source now.

chetgnegy avatar Apr 16 '18 00:04 chetgnegy

It builds my most basic test example now, but not the one with the textual headers. I believe if we were to add this test (below) and get it to pass, I'd be in good shape. Looks like it would be a small change. We'd just need to add another cpp compilation context that digs into the textual_hdrs of the cc_library dep.

@Test
public void testTextualHeaderPassedToCcLib() throws Exception {
  ScratchAttributeWriter.fromLabelString(this, "cc_library", "//cc:txt_dep")
      .setList("textual_hdrs", "hdr.h")
      .write();
  createLibraryTargetWriter("//objc:lib")
      .setList("deps", "//cc:txt_dep")
      .write();
  ScratchAttributeWriter.fromLabelString(this, "cc_library", "//cc:lib")
      .setList("srcs", "a.cc")
      .setList("deps", "//objc:lib")
      .write();
  CommandAction compileAction = compileAction("//cc:lib", "a.o");
  assertThat(Artifact.toRootRelativePaths(compileAction.getPossibleInputsForTesting()))
      .contains("cc/hdr.h");
}

chetgnegy avatar Apr 16 '18 00:04 chetgnegy

This test is now added and passes at Head. Thanks!

chetgnegy avatar May 03 '18 00:05 chetgnegy

Glad it works! For posterity, this was 968f87900dce45a7af749a965b72dbac51b176b3.

calpeyser avatar May 03 '18 15:05 calpeyser