Skip to content

Add clang-format to c++ backend#262

Open
AaronWebster wants to merge 2 commits into
google:masterfrom
AaronWebster:update-cpp-backend
Open

Add clang-format to c++ backend#262
AaronWebster wants to merge 2 commits into
google:masterfrom
AaronWebster:update-cpp-backend

Conversation

@AaronWebster
Copy link
Copy Markdown
Collaborator

@AaronWebster AaronWebster commented May 20, 2026

Generated C++ headers are now run through clang-format --style=google before
being written out, so the output is consistent and readable instead of relying
on whitespace baked into the templates.

The clang-format binary is located via a small clang_format_path.py shim
(with its own py_library target). The seam exists so downstream forks that
can't use the upstream clang-format PyPI package can swap in their own
binary by rewriting just that one file and its pip dep — nothing else in the
Emboss tree needs to change. The PyPI package itself is pinned at 22.1.5 in
requirements.txt.

Most of the diff is regenerated goldens under testdata/golden_cpp/. Those
changes are purely formatting; no semantics moved.

@AaronWebster AaronWebster force-pushed the update-cpp-backend branch 2 times, most recently from c9f6a24 to 5efef50 Compare May 20, 2026 19:56
Apply Google-style clang-format to all generated .emb.h output, in
both the bazel codegen path (emboss_codegen_cpp.main) and the
standalone embossc driver.

The clang-format binary path is resolved through the new
compiler/back_end/cpp/clang_format_path module, which is the single
seam to the underlying binary. The upstream version uses the
clang-format PyPI package; downstream forks that cannot use the PyPI
package can replace just clang_format_path.py and its BUILD entry
with a shim returning an alternative path.
@AaronWebster AaronWebster changed the title Update C++ backend codegen Add clang-format to c++ backend May 21, 2026
@AaronWebster AaronWebster requested a review from robrussell May 21, 2026 21:26
@AaronWebster AaronWebster marked this pull request as ready for review May 21, 2026 21:26

def get_clang_format_path():
"""Returns the path to the clang-format executable."""
from clang_format import get_executable
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Imports should be at the top.

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