Skip to content

Conversation

@hzeller
Copy link
Contributor

@hzeller hzeller commented Dec 22, 2025

This uses http://bant.build/ to create a compilation DB.

The change provides two useful scripts:

  • etc/bazel-make-compilation-db.sh creates a compilation db. To avoid a huge compile_commands.json, this generates the compile_flags.txt which is a much shorter file applied to all files. This keeps memory usage low for tools such as clang-tidy
  • etc/run-clang-tidy.sh a convenience script that creates the compilation DB and then calls run-clang-tidy-cached.cc. It uses clang-tidy from the llvm-toolchain configured in the MODULE.bazel

Issues #8586

@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces useful scripts for generating a compilation database and running clang-tidy, which is a great improvement for developer workflow and code quality. The scripts are well-structured. My review includes several suggestions to enhance their robustness and maintainability by following shell scripting best practices. These include adding error handling (set -e), quoting variables and command substitutions to prevent word splitting issues, and using more robust methods like bazel cquery to locate build artifacts instead of relying on fragile path globbing. I've also pointed out a potential bug in a loop that could occur if a glob pattern doesn't match any files.

@hzeller hzeller force-pushed the feature-20251222-add-compdb branch from ead2044 to 930e60b Compare December 22, 2025 13:32
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@hzeller hzeller force-pushed the feature-20251222-add-compdb branch from 930e60b to 5eb9f4a Compare December 23, 2025 09:17
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@hzeller hzeller force-pushed the feature-20251222-add-compdb branch from 5eb9f4a to 3a228ad Compare December 23, 2025 09:21
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

This uses http://bant.build/ to create a compilation DB.

The change provides two useful scripts:

  * `etc/bazel-make-compilation-db.sh` creates a compilation db.
    To avoid a huge compile_commands.json, this generates the
    compile_flags.txt which is a much shorter file applied to all
    files. This keeps memory usage low for tools such as clang-tidy
  * `etc/run-clang-tidy.sh` a convenience script that creates the
    compilation DB and then calls `run-clang-tidy-cached.cc`.
    It uses `clang-tidy` from the llvm-toolchain configured in the MODULE.bazel

Issues The-OpenROAD-Project#8586

Signed-off-by: Henner Zeller <[email protected]>
@hzeller hzeller force-pushed the feature-20251222-add-compdb branch from 3a228ad to 1a2d93e Compare December 23, 2025 12:58
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@hzeller
Copy link
Contributor Author

hzeller commented Dec 23, 2025

(forgot to make it a separate commit, so it is --amend-ed)

# Important to run with --remote_download_outputs=all to make sure generated
# files are actually visible locally in case a remote cache (that includes
# --disk_cache) is used ( https://github.com/hzeller/bazel-gen-file-issue )
BAZEL_OPTS="-c opt --remote_download_outputs=all"
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't seem to hit the cache. I see the CI builds with
bazelisk test --config=ci --show_timestamps --test_output=errors --curses=no --force_pic --profile=build.profile --remote_header=Authorization=Basic **** ...

which I'm guessing isn't a match

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since I can not run the ci configuration as a regular user (no permissions), I've now kept that default, but made it overridable with an environment variable, so that the CI or personal set-ups can set that to desired values.

@maliberty
Copy link
Member

compile_flags.txt seems to try to be a universal set of includes rather than the specific includes used by a given translation unit. I don't see how that will work in general. For example:

find src/ -name graphics.h
src/mpl/src/graphics.h
src/fin/src/graphics.h
src/exa/src/graphics.h

build/compile_commands.json is 3.4M so larger but not terrible. cmake is much faster at this job as it doesn't require a build. I think you only need to generate the swig wrappers and tcl encoding files.

@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

1 similar comment
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@hzeller
Copy link
Contributor Author

hzeller commented Dec 24, 2025

compile_flags.txt seems to try to be a universal set of includes rather than the specific includes used by a given translation unit. I don't see how that will work in general. For example:

find src/ -name graphics.h
src/mpl/src/graphics.h
src/fin/src/graphics.h
src/exa/src/graphics.h

Yeah, that is a general problem of the project layout which I have said many times before. Once we can abandon CMake, we should fix the paths to always use paths relative to project root.

build/compile_commands.json is 3.4M so larger but not terrible.

For bazel, it would be several hundred megabytes, as it needs to encode all the paths. With that, running clang-tidy on 128 cores will require several hundred gigabytes of RAM. So unfortunately, a compile_commands.json is not an option right now.

cmake is much faster at this job as it doesn't require a build.

We do that now also but build the relevant generated files. Ideally, bazel would provide a compilation-db in the analysis phase, alas, it is not a feature they have. Bant is the best we have.

I think you only need to generate the swig wrappers and tcl encoding files.

Yep, changed that now, so only the fetch of the dependencies is done plus the handful of generated things (much faster)

@hzeller hzeller force-pushed the feature-20251222-add-compdb branch from 080d3a9 to 2ad0129 Compare December 24, 2025 13:45
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

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.

2 participants