build: generate nanopb message code at build time#38
Merged
Conversation
The committed blerpc.pb.c/.h could drift from proto/blerpc.proto: the
CONTRIBUTING regeneration step only runs the Go generate-handlers tool, which
does not regenerate the nanopb message code. Generate *.pb.c/.h at build time
via nanopb_generate_cpp so they always match the proto/options, and drop the
committed copies.
- peripheral_fw/CMakeLists.txt, central_fw/CMakeLists.txt: nanopb_generate_cpp
from ../proto/blerpc.proto. The proto dir is resolved to an absolute path
(no "..") to avoid protoc's "input is shadowed in --proto_path" error, and
NANOPB_GENERATE_CPP_STANDALONE is OFF so the nanopb runtime is not duplicated
against the one provided by CONFIG_NANOPB.
- remove committed peripheral_fw/src/blerpc.pb.{c,h} and
central_fw/src/blerpc.pb.{c,h}.
- CONTRIBUTING.md: note the nanopb code is now generated automatically at build.
Verified: peripheral_fw and central_fw build for nrf54l15dk/nrf54l15/cpuapp
(NCS 2.9 / Zephyr SDK 0.17.0).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
blerpc.pb.c/.hare committed, but the documented regeneration step(
cd tools/generate-handlers && go run . -root ../..) only runs the Gogenerate-handlerstool — it does not regenerate the nanopb message code.So after changing
proto/blerpc.proto, the committed*.pb.c/.hsilently gostale (and regenerating them manually with
nanopb_generatoris undocumentedand environment-sensitive, e.g.
pkg_resources/setuptools).Change
Generate
*.pb.c/.hat build time fromproto/blerpc.proto(+blerpc.options)via
nanopb_generate_cpp, and remove the committed copies, so the message codealways matches the proto.
peripheral_fw/CMakeLists.txt,central_fw/CMakeLists.txt: callnanopb_generate_cppon../proto/blerpc.proto...) to avoid protoc'sInput is shadowed in --proto_patherror.NANOPB_GENERATE_CPP_STANDALONE OFFso the nanopb runtime is not added asecond time (it already comes from
CONFIG_NANOPB); otherwise the linkfails with duplicate
pb_*symbols.peripheral_fw/src/blerpc.pb.{c,h}andcentral_fw/src/blerpc.pb.{c,h}.CONTRIBUTING.md: note the nanopb code is generated automatically at build.Testing
Built both targets for
nrf54l15dk/nrf54l15/cpuapp(NCS 2.9 / Zephyr SDK0.17.0):
peripheral_fwandcentral_fwconfigure, generate, compile and link.🤖 Generated with Claude Code