bazel-compilation-database icon indicating copy to clipboard operation
bazel-compilation-database copied to clipboard

Support layering_check and module_maps features

Open Hallot opened this issue 3 years ago • 2 comments

Hi,

I have recently upgraded a project using gRPC from 1.31 to 1.48, and now I have the following error: Bazel version is 5.2.0. Running on an ARM64 Mac.

ERROR: /tmp/dev/.cache/bazel/_bazel/45687a9fc51e3180e3ee6f957bfa2b6a/external/com_github_grpc_grpc/BUILD:6593:16: in @com_grail_bazel_compdb//:aspects.bzl%compilation_database_aspect aspect on cc_library rule @com_github_grpc_grpc//:grpc++_config_proto:
Traceback (most recent call last):
	File "/tmp/dev/.cache/bazel/_bazel/45687a9fc51e3180e3ee6f957bfa2b6a/external/com_grail_bazel_compdb/aspects.bzl", line 268, column 42, in _compilation_database_aspect_impl
		compiler_info = _cc_compiler_info(ctx, target, srcs, feature_configuration, cc_toolchain)
	File "/tmp/dev/.cache/bazel/_bazel/45687a9fc51e3180e3ee6f957bfa2b6a/external/com_grail_bazel_compdb/aspects.bzl", line 137, column 73, in _cc_compiler_info
		compiler_options = cc_common.get_memory_inefficient_command_line(
Error in get_memory_inefficient_command_line: Invalid toolchain configuration: Cannot find variable named 'module_name'.

I have tried using various versions of bazel-compilation-database (0.4.2, 0.5.1, latest master), but it's always the same.
I have also tried gPRC versions (1.42: first that works with Bazel 5.2.0, 1.48), but it's the same.

I have attached a small project that reproduces the issue. repro.zip Just run bazel build //hello-world:hello-world_compdb to reproduce.

Any help is appreciated, thanks.

Hallot avatar Aug 04 '22 13:08 Hallot

Should have been resolved by #102.

siddharthab avatar Sep 06 '22 05:09 siddharthab

So I looked into this a little more. It looks like the way we get the compile command in Starlark is not compatible with the layering_check feature, which is only enabled for clang on unix. Currently, this feature is enabled in a package by having something like package(features = ["layering_check"]) in the package BUILD file.

The grpc project does enable this feature and then explicitly disables it when using the compilation database generation Starlark code in this project (currently they use version 0.4.5, but the Starlark code should roughly be the same).

https://github.com/grpc/grpc/blob/a644d8c9b43ece0a2683f4940faad8c6795a0b6d/BUILD#L32 https://github.com/grpc/grpc/blob/a644d8c9b43ece0a2683f4940faad8c6795a0b6d/tools/bazel.rc#L137-L138 https://github.com/grpc/grpc/blob/a644d8c9b43ece0a2683f4940faad8c6795a0b6d/tools/distrib/gen_compilation_database.py#L38

I am going to file an issue with bazel to find out the right Starlark with the layering_check feature.

siddharthab avatar Sep 09 '22 05:09 siddharthab

This project is being archived.

siddharthab avatar Mar 17 '24 06:03 siddharthab