bazel-contrib / bazel-contrib/rules_foreign_cc

How to pass the include path of a bazel library target to CMake commands

Open
#1,077 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
737
Forks
270
PR merge metrics
No merged PRs in 30d

Description

E.g., I have wrapped `acl library with the following rule:
```bazel
# external/acl/BUILD.bazel file
cc_library(
name = "acl",
hdrs = [
"include/sys/acl.h",
"include/acl/libacl.h",
],
srcs = [
"lib/x86_64-linux-gnu/libacl.so",
"lib/x86_64-linux-gnu/libacl.so.1",
"lib/x86_64-linux-gnu/libacl.so.1.1.0",
],
includes = ["include"],
strip_include_prefix = "include",
visibility = ["//visibility:public"],
)
```

And her's the way how I compile Iceoryx:
```cmake
cmake(
name = "iceoryx",
build_args = [
"--target install",
"-j12",
],
build_data = ["//external/acl:acl"],
cache_entries = {
"CMAKE_BUILD_TYPE": "Release",
"BUILD_SHARED_LIBS": "ON",
"ROUDI_ENVIRONMENT": "ON",
},
out_binaries = ["iox-roudi"],
lib_source = ":iceoryx-srcs",
out_shared_libs = [
"libiceoryx_posh.so.0.11.0",
"libiceoryx_posh.so.0",
"libiceoryx_posh.so",
"libiceoryx_utils.so.0.11.0",
"libiceoryx_utils.so.0",
"libiceoryx_utils.so",
],
deps = ["//external/acl:acl"],
out_data_dirs = ["lib/cmake", "lib/pkgconfig"],
working_directory = "iceoryx_meta",
visibility = ["//visibility:public"],
env = {
"VERBOSE": "1"
}
)
```

However, the compilation failed because one of the file in Iceoryx cannot find `sys/acl.h`. Upon reviewing the compilation command, the folder `external/acl/include` is not in the compiler options.

May I ask what's the correct Bazel way here to pass a Bazel library target as dependencies for a CMake target?

Contributor guide

Open the contributing guide

Research direction

Start with external/acl/BUILD.bazel and the cmake rule invocation shown in the issue, then inspect the verbose compiler command for how build_data and deps are propagated. Compare the generated include paths with the acl target's includes and strip_include_prefix settings; done means the Iceoryx compilation command contains the path needed to resolve sys/acl.h.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.