Add clang-format to c++ backend#262
Merged
Merged
Conversation
c9f6a24 to
5efef50
Compare
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.
5efef50 to
50b28a6
Compare
robrussell
approved these changes
May 21, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Generated C++ headers are now run through
clang-format --style=googlebeforebeing 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.pyshim(with its own
py_librarytarget). The seam exists so downstream forks thatcan't use the upstream
clang-formatPyPI package can swap in their ownbinary 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/. Thosechanges are purely formatting; no semantics moved.