rules_foreign_cc icon indicating copy to clipboard operation
rules_foreign_cc copied to clipboard

Configure directory structure of $EXT_BUILD_DEPS

Open dylanrush opened this issue 4 years ago • 12 comments

When I pass a few other Bazel dependencies into cmake_external(.. deps = [...]), all of the headers seem to be copied into $EXT_BUILD_DEPS/include and libraries to $EXT_BUILD_DEPS/lib. However, the directory structure is destroyed. If the dependency creates external/org_dependency/include/core/platform/utils/foo.h, then this is just symlinked as $EXT_BUILD_DEPS/include/foo.h. This creates a problem because my source code that I'm trying to compile wants to #include "core/platform/utils/foo.h". And I really can't use $EXT_BUILD_DEPS at all because another dependency decided to create their own time.h which is creating all sorts of linker errors, as you could imagine.

Wondering if there is a way to preserve dependency structure.

Right now my workaround, which isn't quite working, is to use flags like:

        "CMAKE_CXX_FLAGS": "-I $EXT_BUILD_ROOT/bazel-out/k8-opt/bin/external/org_tensorflow/ \
            -I $EXT_BUILD_ROOT/external/org_tensorflow/ \

dylanrush avatar Jun 26 '20 19:06 dylanrush

I have run across this issue too. The way that these rules place all the headers in a single flat include dir made it unusable for my use case. It requires that all headers have unique names across your project and dependency hierarchy.

edbaunton avatar Jun 30 '20 13:06 edbaunton

I've also run into this with Python and the ctype.h header.

jsharpe avatar Jul 14 '20 09:07 jsharpe

Looking at the source, there are actually two things that get put in $EXT_BUILD_DEPS/include: headers and include_dirs: https://github.com/bazelbuild/rules_foreign_cc/blob/83a0c2a9b1e83b98c3d9546a64518e8bd480ad50/tools/build_defs/framework.bzl#L580

While the headers are passed as a list of files that gets squashed here: https://github.com/bazelbuild/rules_foreign_cc/blob/83a0c2a9b1e83b98c3d9546a64518e8bd480ad50/tools/build_defs/framework.bzl#L606-L607 the same logic applied to include_dirs actually symlinks them directly as entire directory trees.

So I've found that adding cc_library(..., includes=["."]) directives into my bazel targets makes two copies: the flattened pile of files and a directory symlink to the base of the include_dir inside $EXT_BUILD_DEPS/include. I've been able to use this as a workaround to get a full include directory structure inserted into $EXT_BUILD_DEPS/include.

I'm as confused as you are about the utility of the flattened headers in the first place -- not sure what use-case that's expected to cover. :shrug:

psigen avatar Mar 04 '21 08:03 psigen

I also run into this issue. glog has a demangle.h that gets linked to $EXT_BUILD_DEPS/include/demangle.h. This conflicts with the demangle.h shipped with gcc 10.

chengji77 avatar Apr 20 '21 07:04 chengji77

+1 to this issue, the handling of (non-foreign, i.e. without a ForeignCcDepsInfo provider) dependencies is no good here. My desired behavior is to symlink such dependencies each into its own sub-directory, just like foreign ones (the /copy_/ => DEPS/), and should take strip_include_prefix and include_prefix into consideration.

I personally tried to make a customized rule to provide a fake ForeignCcDepsInfo with generated contents, that didn't work because once ForeignCcDepsInfo is provided, the build of the cc_library is not triggered.

wudisheng avatar Aug 27 '21 11:08 wudisheng

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_foreign_cc!

github-actions[bot] avatar Feb 23 '22 22:02 github-actions[bot]

As far as I can tell, the desired behavior would always be to replicate the directory structure of the source with include_prefix and strip_include_prefix. I can see no use case where a flattened set of files is the expected result.

psigen avatar Feb 25 '22 01:02 psigen

This issue has been automatically marked as stale because it has not had any activity for 180 days. It will be closed if no further activity occurs in 30 days. Collaborators can add an assignee to keep this open indefinitely. Thanks for your contributions to rules_foreign_cc!

github-actions[bot] avatar Aug 24 '22 22:08 github-actions[bot]

bump, still affected by this issue

psigen avatar Aug 25 '22 04:08 psigen

I ran into this when adding abesil as a dependency - still happening

sulmone avatar Apr 12 '23 11:04 sulmone

This is also an issue building folly, specifically during the boost discovery step

soro avatar Jan 04 '24 22:01 soro

Ran into this issue when building opencv with foreign-rules-cmake and adding oneapi tbb built using bazel. It adds a private tbb semaphore.h at EXT_BUILD_DEPS/include which conflicts with system semaphore.h

alokpr avatar Feb 01 '24 06:02 alokpr