bazelbuild / rules_foreign_cc

Build rules for interfacing with "foreign" (non-Bazel) build systems (CMake, configure-make, GNU Make, boost, ninja, Meson)
https://bazelbuild.github.io/rules_foreign_cc
Apache License 2.0
650 stars 232 forks source link

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

Open t0ny-peng opened 11 months ago

t0ny-peng commented 11 months ago

E.g., I have wrapped `acl library with the following rule:

# 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(
    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?

t0ny-peng commented 11 months ago

Attempt 1: Add copts = ["-isystem external/acl/include"],. I found this in the compiler command

-isystem /home/<name>/git/iceoryx-build-infra/.bazel/383bf083faa830bb13ec7c86d4b4286b/sandbox/processwrapper-sandbox/10/execroot/__main__/external/acl/include.

And that folder does have a sys/acl.h. But it symlinks to a non-existing file /home/<name>/git/iceoryx-build-infra/.bazel/383bf083faa830bb13ec7c86d4b4286b/execroot/__main__/external/acl/include/sys/acl.h