Skip to content

Track both outputs of each Protobuf schema in Make - #402

Open
cjyhjy wants to merge 1 commit into
google:masterfrom
cjyhjy:codex/protobuf-generated-outputs
Open

cjyhjy wants to merge 1 commit into
google:masterfrom
cjyhjy:codex/protobuf-generated-outputs

Conversation

@cjyhjy

@cjyhjy cjyhjy commented Nov 25, 2026

Copy link
Copy Markdown

Each schema produces a .pb.cc and a .pb.h. Make currently declares the header as a side effect of the source recipe. If a header disappears while the source is current, Make can report success for the header target without creating it. Building tests/nstun_policy_test directly then fails when it includes the missing header. Editing one schema also regenerates both schemas.

Use one grouped pattern rule per schema so Make tracks both outputs and runs one generator job per schema during a parallel build. Declare the generated headers as prerequisites of the standalone policy test.

Verification

  • On Debian 12 ARM64 with GNU Make 4.3 and protoc 3.21.12, a clean parallel build produced the binary and four nstun test programs. All four programs and all seven make test-cmdline cases passed.
  • After a clean generation, remove either generated header and request it with make -j4 config.pb.h or make -j4 unotify/unotify.pb.h, respectively. Before the patch the requested header remained missing. With the patch it is recreated by one protoc invocation.
  • After building the policy test, remove config.pb.h and tests/nstun_policy_test and rerun make -j4 tests/nstun_policy_test. The baseline failed to compile, and the patched build succeeded.
  • Requesting all four generated files in a clean tree runs protoc twice, a repeat runs it zero times, and touching only config.proto runs it once. Regenerating a missing unotify/unotify.pb.cc also passed.

AI-assisted implementation and testing.

Use a grouped pattern rule so a missing generated header triggers protoc while parallel builds generate each schema only once. Declare generated headers as prerequisites of the standalone nstun policy test as well.
@cjyhjy

cjyhjy commented Nov 26, 2026

Copy link
Copy Markdown
Author

One additional validation result for this PR: I ran the actual Protobuf generation targets on Debian 13 x86_64 with GNU Make 4.4.1 and libprotoc 3.13.0. With the baseline, Make returned success when either generated header was deleted but did not regenerate it. With this patch, deleting any one of the four generated outputs regenerated the missing file with one protoc invocation. A no-op rebuild invoked protoc zero times. This covered code generation only, not full compilation or runtime. This additional verification was Codex-assisted.

This branch has not been deployed

No deployments
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.

1 participant