Skip to content

Add clang-format to c++ backend#262

Merged
AaronWebster merged 3 commits into
google:masterfrom
AaronWebster:update-cpp-backend
Jun 1, 2026
Merged

Add clang-format to c++ backend#262
AaronWebster merged 3 commits into
google:masterfrom
AaronWebster:update-cpp-backend

Conversation

@AaronWebster

@AaronWebster AaronWebster commented May 20, 2026

Copy link
Copy Markdown
Collaborator

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
Comment thread compiler/back_end/cpp/clang_format_path.py Outdated
@AaronWebster AaronWebster merged commit 893c3f8 into google:master Jun 1, 2026
12 checks passed
AaronWebster added a commit that referenced this pull request Jun 2, 2026
Merge current master, which landed clang-format for the C++ back end
(#262) and the optimized-conditionals work (#241).  Both rewrote
generated_code_templates and every testdata/golden_cpp/*.h.  The
template conflict is resolved by re-applying the JSON text-output logic
on top of master's version, and all goldens are regenerated with
clang-format 22.1.5.

Fixes that turn the failing "Run Bazel tests (clang)" job green:

- Remove internal-ism include paths from emboss_array_view_test.cc
  (testing/base/public/gunit.h, third_party/absl/..., third_party/
  emboss/...).  These do not resolve in the open-source build and broke
  compilation -- the same class of issue already corrected in the
  template.

- Size JsonTestStruct's struct_array to two elements ([+40] -> [+8]) so
  the 87-byte struct becomes 55 bytes and fits the 57-byte test buffer.
  The oversized fixed array made WriteToTextStream read past the buffer
  (the tests assert exactly two elements), causing check failures.

- Update the array JSON test expectation to compact form
  ("[-3,2,...]" rather than "[-3, 2, ...]") to match the compact JSON
  the implementation emits, resolving the test/implementation version
  skew noted in review.

Additionally, emit newlines between fields in multiline JSON output so
multiline JSON is properly formatted; the change is guarded so non-JSON
text output is byte-for-byte unchanged.  Adds a JsonMultilineOutput test.
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