stackb / bazel-stack-vscode-cc

C/C++ Support For Bazel Stack VSCode Extension
Apache License 2.0
31 stars 7 forks source link

Generation fails for "target_compatible_with" targets #9

Open camearle20 opened 3 years ago

camearle20 commented 3 years ago

When attempting to build a compilation database for a target with "target_compatible_with" set to something other than the host platform, the plugin fails to generate a compilation database. Example output:

Example cc_binary:

cc_binary(
    name = "native",
    srcs = ["test.c"],
    linkshared = True,
    deps = ["//third_party/wpilib:hal-athena", ":example-jni-athena"],
    target_compatible_with = ["@platforms//cpu:arm"]
)

Error output:

ERROR: /home/cameronearle/frc6328/AdvantageKit/example_java_project/BUILD:33:10: in @bazel_vscode_compdb//:aspects.bzl%compilation_database_aspect aspect on cc_binary rule //example_java_project:native: 
Traceback (most recent call last):
        File "/home/cameronearle/.cache/bazel/_bazel_cameronearle/df2869d739dc2caa4da3626bfdc238b8/external/bazel_vscode_compdb/aspects.bzl", line 312, column 48, in _compilation_database_aspect_impl
                compile_commands = _cc_compile_commands(ctx, target, feature_configuration, cc_toolchain)
        File "/home/cameronearle/.cache/bazel/_bazel_cameronearle/df2869d739dc2caa4da3626bfdc238b8/external/bazel_vscode_compdb/aspects.bzl", line 138, column 39, in _cc_compile_commands
                compile_flags = _get_compile_flags(target)
        File "/home/cameronearle/.cache/bazel/_bazel_cameronearle/df2869d739dc2caa4da3626bfdc238b8/external/bazel_vscode_compdb/aspects.bzl", line 87, column 30, in _get_compile_flags
                compilation_context = dep[CcInfo].compilation_context
Error: <target //example_java_project:native> (rule 'cc_binary') doesn't contain declared provider 'CcInfo'
ERROR: Analysis of aspect '@bazel_vscode_compdb//:aspects.bzl%compilation_database_aspect of //example_java_project:native' failed; build aborted: Analysis of target '//example_java_project:native' failed
INFO: Elapsed time: 0.133s
INFO: 0 processes.
INFO: Build Event Protocol files produced successfully.
The terminal process "bash '-c', 'bazel build --override_repository=bazel_vscode_compdb=/home/cameronearle/.vscode-server/extensions/stackbuild.bazel-stack-vscode-cc-1.1.2/compdb/ --aspects=@bazel_vscode_compdb//:aspects.bzl%compilation_database_aspect --color=no --noshow_progress --noshow_loading_progress --output_groups=compdb_files,header_files --build_event_json_file=/tmp/tmp-197-FEInLrkbeQyu //example_java_project:native && /home/cameronearle/.vscode-server/extensions/stackbuild.bazel-stack-vscode-cc-1.1.2/compdb/postprocess.py -b /tmp/tmp-197-FEInLrkbeQyu && rm /tmp/tmp-197-FEInLrkbeQyu'" failed to launch (exit code: 1).

In my example the host is a 64 bit Ubuntu system, but I've been able to reproduce this on macOS as well. In both cases an appropriate toolchain was registered in the WORKSPACE file to build for the platform.

This was also a problem with the older bazel-compdb project that this plugin is based on, so I don't know how involved the fix would be.