rules_foreign_cc and preserving dir structure of headers

286 views
Skip to first unread message

Fædon Jóhannes Sinis

unread,
Jun 26, 2023, 7:12:59 PM6/26/23
to bazel-discuss
Hi, I'm just starting to figure out how to use Bazel to pull in external dependencies with their own CMake projects, and I ran into a problem with the directory structure of header files.

I'm trying to build a library which calls this external project:

and here is my minimal example:

which I've adapted from the documentation at:

When I run:
bazel build :example

I get the following error:
bazel-out/k8-fastbuild/bin/polyscope/include/polyscope/persistent_value.h:10:10: fatal error: polyscope/render/color_maps.h: No such file or directory
   10 | #include "polyscope/render/color_maps.h"


It appears that the original directory structure of the includes contained a subdirectory called "render", however, something about rules_foreign_cc copied all the headers into a flat directory, so I think now any program using these header files is unable to find the subdirectory referenced in the original structure of the external lib.

Is this a problem with the way the cmake files are configured, or is there an optional flag I need to pass in rules_foreign_cc (something like "preserve_include_directory_structure=1") ?




Filip Filmar

unread,
Jun 26, 2023, 8:09:51 PM6/26/23
to Fædon Jóhannes Sinis, bazel-discuss
Not sure about the `cmake` target type, and I don't have all the external deps to compile your example, but perhaps this helps.
  • For the `make` target I found that one must execute `make install` or equivalent for the output artifacts to be available after compilation. This is because compilation happens in a temporary dir, and `install` will bring the targets you need into the sandbox from which it is then taken over by bazel.  In case it helps I wrote up what I did, but not sure how much `make()` experience translates to `cmake()`.
  • I have found it useful to first compile the dep manually to understand what it is attempting to do when installed, and write the bazel rules off of those findings.  Can you confirm that `cmake install` or some equivalent creates the install directory in the form you expect? If yes, then the issue is with polyscope. If not, then the issue is with rules_foreign_cc. 
  • Are you sure that the dir structure is flattened, vs missing the `render` dir entirely?
HTH,
F


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/39a718df-49da-49ff-a0eb-6c8bf5ba91den%40googlegroups.com.

Fædon Jóhannes Sinis

unread,
Jun 27, 2023, 7:40:39 AM6/27/23
to bazel-discuss
Thank you. After trying your suggestion to verify the output just using cmake (and not through bazel), I saw that the directories were flattened there as well. I reached out to the author, and it looks like there was a problem in the CMake config in Polyscope which has now been fixed:
Reply all
Reply to author
Forward
0 new messages