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

Issue enabling `layering_check` #1221

Open dotnwat opened 5 days ago

dotnwat commented 5 days ago

I'm using openssl via configure_make:

configure_make(
    name = "openssl",
    configure_command = "Configure",
    configure_options = [
        "--libdir=lib",
        "--release",
    ],
    lib_source = ":all_srcs",
    out_shared_libs = [
        "libssl.so",
        "libcrypto.so",
    ],
    visibility = [
        "//visibility:public",
    ],
)

And then enable the layering_check feature on a cc_library that depends on "@openssl":

cc_library(
    name = "crypto",
    srcs = [
        "ssl_utils.cc",
        "ssl_utils.h",
    ],
    hdrs = [
        "include/crypto/crypto.h",
    ],
    strip_include_prefix = "include",
    visibility = ["//visibility:public"],
    deps = [
        "@openssl",
    ],
    features = [
        "layering_check",
    ],
)

But layering_check does not seem to think that openssl is exporting certain header files:

src/crypto/ssl_utils.h:20:10: error: module //src/crypto:crypto does not depend on a module exporting 'openssl/evp.h'
#include <openssl/evp.h>

I can see these header files in the build cache include directories, so I'm just guessing that the rule for openssl doesn't have these headers declared?

Is this expected behavior, or how can I go about debugging this?

EDIT:

It does seem as though rules_foreign_cc disables layering checks. But I'm still a bit lost on how to deal with adding layering checks to libraries that depend on a library built with rules_foreign_cc as it doesn't appear to declare the output headers explicitly.

jsharpe commented 1 day ago

rules_foreign_cc disables layering checks because the flags that this feature set are not safe to pass to a third party build system. @fmeum you've previously worked with getting layering checks working in the toolchain - is there something I can add to the generated CcInfo that would make this case work where one layer comes from a third party build system?

fmeum commented 1 day ago

The API for creating and adding module maps is private, so the only thing you could try now is to split up the CcInfo: Populate the linking context from your custom starlark rule, but wrap it in a cc_library with the exported headers to provide the compilation context. The cc_library target should have features = ["-layering_check"] set to disable checks for it, but it will still generate a module map.