bazelbuild / rules_cc

C++ Rules for Bazel
https://bazel.build
Apache License 2.0
182 stars 90 forks source link

Added `clang-format` rules #125

Closed UebelAndre closed 2 years ago

UebelAndre commented 2 years ago

I get the feeling these changes may not be desirable for rules_cc but thought I'd share them none the less.

This PR introduces rules for running clang-format.

alexeagle commented 1 year ago

Hey @UebelAndre I just got a pointer here from @jsharpe - I'd like to bring your work into our "super formatter" that formats approx. all code in a monorepo with one tool. https://github.com/aspect-build/bazel-super-formatter LMK if you have thoughts or 👍🏻 👎🏻 about me borrowing your code, or if you'd like to do that yourself :)

UebelAndre commented 1 year ago

Hey @UebelAndre I just got a pointer here from @jsharpe - I'd like to bring your work into our "super formatter" that formats approx. all code in a monorepo with one tool. https://github.com/aspect-build/bazel-super-formatter LMK if you have thoughts or 👍🏻 👎🏻 about me borrowing your code, or if you'd like to do that yourself :)

Feel free to use this code, I posted it here to share it with the community and try to save folks time re-implmenting this. Hoping it helps 😄

alexeagle commented 1 year ago

Oh, I see this still doesn't provide the clang-format binary itself. I was somewhat involved with https://www.npmjs.com/package/clang-format - not sure if the pre-built binaries there are a good thing to re-use, or if we can get pre-built binaries from somewhere else? Or do we force users to compile the tool from source?

jsharpe commented 1 year ago

Oh, I see this still doesn't provide the clang-format binary itself. I was somewhat involved with npmjs.com/package/clang-format - not sure if the pre-built binaries there are a good thing to re-use, or if we can get pre-built binaries from somewhere else? Or do we force users to compile the tool from source?

Compiling from source is probably very non-trivial to do as AFAIK this requires the LLVM core? The grailbio/bazel-toolchain has the ability to export clang-format from the binary releases of llvm (this is clang-tidy but clang-format would be trivial to add): https://github.com/grailbio/bazel-toolchain/blob/24720b5021ce9c0e05f606bf9b654ddafbbae783/toolchain/BUILD.llvm_repo#L133 but this is a rather heavyweight way of fetching the binaries for clang-format as it downloads the whole llvm install. https://github.com/DoozyX/clang-format-lint-action/tree/master/clang-format also has some binaries for linux but guess windows and macOS will also be needed. I suspect that the npm solution is probably the easiest and most lightweight approach to this.