Skip to content

Fix clang warnings and cross-platform toolchain failures#276

Open
srikantharun wants to merge 1 commit intohedronvision:mainfrom
srikantharun:fix/clang-warnings-and-cross-platform
Open

Fix clang warnings and cross-platform toolchain failures#276
srikantharun wants to merge 1 commit intohedronvision:mainfrom
srikantharun:fix/clang-warnings-and-cross-platform

Conversation

@srikantharun
Copy link
Copy Markdown

Summary

This PR fixes two issues that affect users of LLVM/Clang toolchains with Bazel.

1. Clang warnings about unused -c flag (fixes #273)

Problem: When generating header dependencies, the -c flag is passed to clang but is unused during -M mode, causing warnings:

clang: error: argument unused during compilation: '-c' [-Werror,-Wunused-command-line-argument]

Solution: Strip -c from the header dependency generation command, similar to how -o and .o are already stripped.

2. Cross-platform toolchain failure (fixes #255)

Problem: When building //... for a target platform different from the host, the refresh_compile_commands target fails:

No matching toolchains found for types:
  @@bazel_tools//tools/cpp:toolchain_type

Solution: Add "manual" tag to refresh_compile_commands targets. This prevents them from being built with bazel build //... while still allowing bazel run to work correctly.

Test plan

  • Verified -c is stripped from header command
  • Verified manual tag is added to py_binary
  • Test with toolchains_llvm and -Werror to confirm no warnings
  • Test cross-platform build with --platforms=... to confirm no failure

This commit fixes two issues:

1. Clang warnings about unused -c flag (fixes hedronvision#273)
   - Strip -c flag from header dependency generation commands
   - The -c flag is unused during -M (dependency generation) mode
     and causes "argument unused" warnings with clang -Werror

2. Cross-platform toolchain failure (fixes hedronvision#255)
   - Add "manual" tag to refresh_compile_commands targets
   - Prevents failure when running `bazel build //...` for a
     different target platform that lacks a matching C++ toolchain
   - These targets are meant for `bazel run`, not regular builds
@vittorioromeo
Copy link
Copy Markdown

@cpsauer: are you still maintaining the repo?

Comment thread refresh.template.py
# Strip -c flag which is unused during dependency generation (-M) and causes
# "argument unused during compilation" warnings with clang -Werror.
# See https://github.com/hedronvision/bazel-compile-commands-extractor/issues/273
header_cmd = (arg for arg in header_cmd if arg != '-c')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: also strip '/c' (similar situation in windows).

Copy link
Copy Markdown

@swgr424 swgr424 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows compatibility suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Any way to suppress Clang warnings? ("argument unused during compilation") avoid toolchain failure for cross-platform builds

3 participants