Skip to content

layering_check for CppCompile doesn't work with generated files in textual_hdrs #27718

@keith

Description

@keith

Description of the bug:

with a toolchain that supports layering_check and this BUILD file:

load("@rules_cc//cc:defs.bzl", "cc_library")

genrule(
    name = "lol",
    outs = ["foo.h"],
    cmd = "echo '// hdr' > $@",
)

cc_library(
    name = "foo",
    srcs = ["foo.cpp"],
    textual_hdrs = [":lol"],
    features = ["layering_check"],
)

the build fails with:

foo.cpp:1:10: error: module //:foo does not depend on a module exporting 'foo.h'
    1 | #include "foo.h"
      |          ^
1 error generated.

and the relevant cppmap file has this contents:

% cat bazel-bin/foo.cppmap
module "//:foo" {
  export *
  textual header "../../../bazel-out/aarch64-fastbuild/bin/foo.h"
  use "crosstool"
}
extern module "crosstool" "../../../external/rules_cc++cc_configure_extension+local_config_cc/module.modulemap"

If you move the file from textual_hdrs to hdrs it works and has the correct contents:

% cat bazel-bin/foo.cppmap
module "//:foo" {
  export *
  textual header "../../../bazel-out/cfg/bin/foo.h"
  use "crosstool"
}
extern module "crosstool" "../../../external/rules_cc++cc_configure_extension+local_config_cc/module.modulemap"

Which category does this issue belong to?

No response

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

bazel build :foo in layering_check.zip

Which operating system are you running Bazel on?

No response

What is the output of bazel info release?

491f252

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?


If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions