Skip to content

fix(nrf52): compile the framework libraries a sketch reaches - #2077

Merged
zackees merged 1 commit into
mainfrom
agent/nrf52-framework-libs
Nov 18, 2026
Merged

zackees merged 1 commit into
mainfrom
agent/nrf52-framework-libs

Conversation

@zackees

@zackees zackees commented Nov 18, 2026

Copy link
Copy Markdown
Member

What

The nRF52 orchestrator put only Wire/ and SPI/ on the include path and never compiled either library. A sketch that calls Wire.begin() therefore compiled and then failed to link:

undefined reference to `TwoWire::begin()'
undefined reference to `TwoWire::beginTransmission(unsigned char)'
undefined reference to `TwoWire::endTransmission()'
undefined reference to `Wire'

That is #2072, reproduced on main with the installed CLI (2.5.50) against tests/platform/nrf52840_dk plus a five-line Wire sketch.

PlatformIO compiles the framework's built-in libraries through LDF when they are included; the Teensy, STM32, RP2040, ESP8266 and Renesas orchestrators here already do the same. nRF52 was the gap.

How

nrf52/framework_libs.rs resolves the core's libraries/ tree with the shared finder (resolve_framework_library_selection_active_declared_with_extra), seeded from the project's translation units, honoring lib_deps and active #if branches, with the include path built so far so SDK headers resolve as they will at compile time. The orchestrator then adds the reached libraries' include dirs and sources before the compiler is created (step 6b), so lib_deps builds see the same path.

Rails:

  • Only reached libraries contribute. Bluefruit52Lib, Adafruit_LittleFS, Adafruit_nRFCrypto, ... stay out when the sketch does not include them, so they cannot shadow a core header or bloat the build.
  • Adafruit_TinyUSB_Arduino is never a candidate. The orchestrator's TinyUSB block already compiles the stack (with its USB-CDC config) on every nRF52840 build.
  • No duplicate translation units. Sources already in the core set — including the SPI.cpp the TinyUSB host adapter needs — are filtered out by normalized path before being added.
  • The Adafruit BSP uses the flat 1.0 layout (libraries/Wire/Wire_nRF52.cpp, libraries/SPI/SPI.cpp + SPI_nrf52832.cpp). The shared discovery helper already implements the Arduino spec for both layouts; the new test fixture mirrors the flat one, and both SPI sources are compiled (the nRF52832 one is #ifdef NRF52832_XXAA-guarded, exactly as Arduino builds it).

Tests

crates/fbuild-build-arm/src/nrf52/framework_libs_tests.rs (7 tests, new):

  • sketch_include_compiles_the_bundled_library — #include <Wire.h> ⇒ Wire_nRF52.cpp in the compile set and the Wire dir on the include path; SPI.cpp not selected.
  • unreached_library_contributes_nothing — Bluefruit52Lib / Adafruit_LittleFS absent.
  • flat_layout_library_contributes_every_source — both SPI.cpp and SPI_nrf52832.cpp.
  • orchestrator_compiled_library_is_never_selected — TinyUSB excluded even when the sketch includes it.
  • already_compiled_sources_are_not_duplicated — the manually added SPI.cpp is not handed back.
  • declared_lib_deps_selects_a_library — lib_deps names a library the scan cannot infer.
  • missing_libraries_dir_is_empty — a core without libraries/ is not an error.

Receipts:

  • Before (installed CLI 2.5.50 on main, real build of tests/platform/nrf52840_dk + Wire.begin()): link failed with the four undefined reference errors quoted above.
  • After: soldr cargo test -p fbuild-build-arm --lib ⇒ 307 passed, 0 failed, 2 ignored.
  • soldr cargo fmt --all -- --check clean.

#2072 stays open until the end-to-end fbuild build receipt is attached (host is at load ~90-120/16 this tick, so the CLI rebuild needed for it is still running).

Part of #2035.

The nRF52 orchestrator put only `Wire/` and `SPI/` on the include path and
never compiled either library, so a sketch calling `Wire.begin()` compiled
and then failed to link with `undefined reference to TwoWire::begin()`
(#2072, on main as well).

Resolve the bundled `libraries/` tree the way the Teensy/STM32/RP2040/
ESP8266/Renesas orchestrators already do: seed the shared library-dependency
finder from the project's translation units, honor `lib_deps`, and add only
the reached libraries' include dirs and sources. Unreached libraries
(`Bluefruit52Lib`, `Adafruit_LittleFS`, ...) stay out, so they cannot shadow a
core header or bloat the build. `Adafruit_TinyUSB_Arduino` is excluded from
the candidates because the orchestrator's TinyUSB block already compiles it,
and any source already in the core set (the `SPI.cpp` the TinyUSB host
adapter needs) is filtered out so no translation unit is built twice.

The Adafruit BSP uses the flat 1.0 layout (`libraries/Wire/Wire_nRF52.cpp`),
which the shared discovery helper already handles; the fixture mirrors it.
@coderabbitai

coderabbitai Bot commented Nov 18, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@zackees

zackees commented Nov 18, 2026

Copy link
Copy Markdown
Member Author

End-to-end receipt on the branch (worktree binary fbuild 2.5.52, dev cache root, nrf52840_dk + the five-line Wire sketch that failed on main):

$ fbuild build -e nrf52840_dk
build succeeded in 59.0s (flash: 48208 bytes, ram: 8776 bytes)

compile_commands.json (102 translation units) now contains the library source that was missing before:

.../1.10601.0/libraries/Wire/Wire_nRF52.cpp
.../1.10601.0/libraries/SPI/SPI.cpp
.../1.10601.0/libraries/Adafruit_TinyUSB_Arduino/src/tusb.c

and libraries/SPI/SPI.cpp appears exactly once — the de-duplication against the SPI.cpp the TinyUSB host adapter already compiles works. No other library (Bluefruit52Lib, Adafruit_LittleFS, Servo, PDM, ...) was pulled in, so the finder really is reaching only what the sketch includes.

Same project on main's installed CLI (2.5.50) still fails at link with undefined reference to TwoWire::begin(), so the delta is this change.

@zackees
zackees added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 0aad680 Nov 18, 2026
33 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 19, 2026
@zackees
zackees deleted the agent/nrf52-framework-libs branch November 24, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant