Skip to content

build: generate nanopb message code at build time#38

Merged
tdaira merged 1 commit into
mainfrom
build-time-nanopb-generation
Jun 30, 2026
Merged

build: generate nanopb message code at build time#38
tdaira merged 1 commit into
mainfrom
build-time-nanopb-generation

Conversation

@tdaira

@tdaira tdaira commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Problem

blerpc.pb.c/.h are committed, but the documented regeneration step
(cd tools/generate-handlers && go run . -root ../..) only runs the Go
generate-handlers tool — it does not regenerate the nanopb message code.
So after changing proto/blerpc.proto, the committed *.pb.c/.h silently go
stale (and regenerating them manually with nanopb_generator is undocumented
and environment-sensitive, e.g. pkg_resources/setuptools).

Change

Generate *.pb.c/.h at build time from proto/blerpc.proto (+ blerpc.options)
via nanopb_generate_cpp, and remove the committed copies, so the message code
always matches the proto.

  • peripheral_fw/CMakeLists.txt, central_fw/CMakeLists.txt: call
    nanopb_generate_cpp on ../proto/blerpc.proto.
    • The proto dir is resolved to an absolute path (no ..) to avoid protoc's
      Input is shadowed in --proto_path error.
    • NANOPB_GENERATE_CPP_STANDALONE OFF so the nanopb runtime is not added a
      second time (it already comes from CONFIG_NANOPB); otherwise the link
      fails with duplicate pb_* symbols.
  • Remove committed peripheral_fw/src/blerpc.pb.{c,h} and
    central_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 SDK
0.17.0): peripheral_fw and central_fw configure, generate, compile and link.

🤖 Generated with Claude Code

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>
@tdaira
tdaira merged commit e86ee59 into main Jun 30, 2026
7 checks passed
@tdaira
tdaira deleted the build-time-nanopb-generation branch June 30, 2026 06:44
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