cc_common Starlark examples don't work with layering_check feature
#16.243 aperta il 9 set 2022
Metriche repository
- Star
- (25.384 star)
- Metriche merge PR
- (Merge medio 22g 20h) (77 PR mergiate in 30 g)
Descrizione
Description of the bug:
It looks like the common flow of using cc_common.configure_features, cc_common.create_compile_variables and cc_common.get_memory_inefficient_command_line does not work when layering_check feature is enabled for the package.
An indication that this is a known but undocumented issue is the line in the example in the rules_cc repo: https://github.com/bazelbuild/rules_cc/blob/807a87190a117d5798f9f2c69427e9037e9891d3/examples/my_c_compile/my_c_compile.bzl#L23
Because layering_check feature is enabled only for clang on unix, this is only observed when compiling with clang on unix systems (not osx, which is a special case).
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
touch hello.cc
touch WORKSPACE
cat >BUILD <<EOF
package(features = ["layering_check"])
cc_library(
name = "hello",
srcs = ["hello.cc"],
)
EOF
cat >aspects.bzl <<EOF
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
load(
"@bazel_tools//tools/build_defs/cc:action_names.bzl",
"CPP_COMPILE_ACTION_NAME",
)
def _my_aspect_impl(target, ctx):
cc_toolchain = find_cpp_toolchain(ctx)
feature_configuration = cc_common.configure_features(
ctx = ctx,
cc_toolchain = cc_toolchain,
requested_features = ctx.features,
unsupported_features = ctx.disabled_features,
)
compile_variables = cc_common.create_compile_variables(
feature_configuration = feature_configuration,
cc_toolchain = cc_toolchain,
user_compile_flags = ctx.fragments.cpp.cxxopts +
ctx.fragments.cpp.copts,
)
compiler_options = cc_common.get_memory_inefficient_command_line(
feature_configuration = feature_configuration,
action_name = CPP_COMPILE_ACTION_NAME,
variables = compile_variables,
)
return []
my_aspect = aspect(
attr_aspects = ["srcs"],
attrs = {
"_cc_toolchain": attr.label(
default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
),
},
fragments = ["cpp"],
toolchains = ["@bazel_tools//tools/cpp:toolchain_type"],
implementation = _my_aspect_impl,
)
EOF
export CC=clang
bazel build --aspects=aspects.bzl%my_aspect "//:hello"
Which operating system are you running Bazel on?
Ubuntu 20.04
What is the output of bazel info release?
release 5.3.0
If bazel info release returns development version or (@non-git), tell us how you built Bazel.
NA
What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?
NA
Have you found anything relevant by searching the web?
Another issue that discusses this in a specific context is https://github.com/grailbio/bazel-compilation-database/issues/101, where an aspect does not work when used with the grpc package. grpc package has the layering_check feature enabled.
Any other information, logs, or outputs that you want to share?
No response