Skip to content

Fix cpp_golden_test to support --no-cc-enum-traits flag#107

Draft
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-large-header-generation
Draft

Fix cpp_golden_test to support --no-cc-enum-traits flag#107
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-large-header-generation

Conversation

Copy link

Copilot AI commented Dec 6, 2025

The no_enum_traits_golden_test was generating headers with enum traits enabled, causing the golden file to include EnumTraits, emboss_text_util.h, and text stream methods that should be excluded when --no-cc-enum-traits is passed.

Changes

  • build_defs.bzl: Add enable_enum_traits parameter to cpp_golden_test macro
  • run_one_golden_test.py: Parse --no-cc-enum-traits flag and extract import-dir paths correctly
  • one_golden_test.py: Pass --no-cc-enum-traits to compiler when disabled
  • BUILD: Set enable_enum_traits = False for no_enum_traits_golden_test
  • no_enum_traits.emb.h: Regenerate golden file without enum traits (653 → 492 lines)

Usage

cpp_golden_test(
    name = "no_enum_traits_golden_test",
    emb_file = "//testdata:no_enum_traits.emb",
    enable_enum_traits = False,
    golden_file = "//testdata/golden_cpp:no_enum_traits.emb.h",
)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.googleapis.com
    • Triggering command: /usr/local/lib/node_modules/@bazel/bazelisk/bazelisk-linux_amd64 /usr/local/lib/node_modules/@bazel/bazelisk/bazelisk-linux_amd64 test //compiler/back_end/cpp:header_generator_test --test_output=errors (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>C++ backend generates excessively large headers</issue_title>
<issue_description>This issue was copied from the upstream repository google/emboss.

Original issue: google#128
Original state: open, created at: 2024-04-08T17:08:21Z, updated at: 2024-07-22T14:17:35Z, by @EricRahm


Original description

Issue

For a ~75KB emb file I'm seeing a ~7.5MB header generated. An example for the pw_bluetooth project:

Definition File Size (KB) Header Size (KB)
hci_events.emb 76 7488
hci_commands.emb 108 7376
hci_vendor.emb 32 2328
hci_common.emb 32 824
hci_data.emb 4 204
l2cap_frames.emb 4 60
hci_h4.emb 4 8

The scaling of input size to output size isn't consistent, so the behavior is definitely content driven.

Impact

  • Overhead of the backend generation step: larger headers take longer to generate
  • Slower compilation times: large headers result in long compile times even if a majority of the header is unreferenced
  • Hard to navigate: consumers of the headers have a lot of code to look at
  • Code analysis tools like clangd slow to a crawl when encountering the generated headers

Possible Improvements

  1. C++ fragment templates include comments relevant to the emboss C++ backend, but not the generated code itself. We could trim out the comments when generating the code
  2. Large amount of text conversion code (ostream, enum strings, etc). For many projects this is unnecessary, we should make it optional and/or split out to a separate header.
  3. Large amount of code generated to wrap / validate / extract constant values, we can just use the constants directly.

Discussion (copied comments)

Comment by @EricRahm on 2024-04-18T01:59:00Z:

I have a few patches pending that'll address 1 and 2. Just need to hold off until AaronWebster/emboss#130 lands since it has a significant changes to the code templates. FYI @robrussell


</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 6, 2025 02:58
…raits golden file

Co-authored-by: AaronWebster <3766083+AaronWebster@users.noreply.github.com>
Co-authored-by: AaronWebster <3766083+AaronWebster@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix C++ backend to reduce header size Fix cpp_golden_test to support --no-cc-enum-traits flag Dec 6, 2025
Copilot AI requested a review from AaronWebster December 6, 2025 03:07
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.

C++ backend generates excessively large headers

2 participants