Repository navigation
feat(fqbn): discover the libraries a sketch includes (#1298) - #2250
Merged
Merged
Conversation
Arduino's builder resolves a sketch's `#include` lines to libraries before it compiles anything; the FQBN path compiled the core and the sketch but had no library step, so `#include <FastLED.h>` had nowhere to come from. New `fqbn_libraries` module: a header is owned by the library that declares it (`library.properties` `includes=`), else by the folder whose name is its stem, else by the one library holding a file of that name; the earliest search root wins, exactly as Arduino's include order does, and two libraries in the SAME root claiming one header are refused by name. Roots are the package's bundled `libraries/`, then the data directory's, then `--library-root`. A 1.5 library is `src/`-rooted (sources recursively, one include dir); a 1.0 library compiles from its root plus `utility/` and never from `examples/`/`extras/`. Core and variant headers are never library headers, and selection is transitive through library headers. CLI: `fbuild fqbn <FQBN> --sketch <dir>/<name>.ino [--library-root DIR]` reports `library_count`, `library.<i>`, `library_root.<i>`, `library_include.<i>.<j>`, `library_source.<i>.<j>` and `unresolved_header.<i>` (JSON: `libraries`), and a `--compile` of the sketch gains the selected include directories. Real e2e on `arduino:[email protected]` from the published index plus a real FastLED 3.10.10 checkout: 5 libraries (FastLED 36 sources, Wire 2, SPI 1, SoftwareSerial 1, EEPROM header-only), 0 unresolved, and the sketch TU compiled through the package's own `recipe.cpp.o.pattern` -- avr-g++ exit 0, `Blink.ino.o` 160,096 B, with all five library `-I` directories on the command.
`ban_std_pathbuf` denies `std::path::PathBuf` in new code, including a `Vec<PathBuf>` used only to dedup roots and to sort directory entries. Carry `NormalizedPath` through both instead; no behaviour change.
This was referenced Dec 4, 2026
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.
What
fbuild fqbncould compile a package's core and a sketch, but nothing resolved the sketch's own#includelines to libraries — the step Arduino's builder does before it compiles anything.#include <FastLED.h>therefore had no source.New
crates/fbuild-build-engine/src/fqbn_libraries.rs:library.propertiesincludes=), else to the library whose folder name is its stem (Wire/Wire.h), else to the one library holding a file of that name. The earliest search root wins, as Arduino's include order does; two libraries inside the same root claiming one header are refused by name (compiling the wrongutility/twi.honly shows up at link).libraries/, then the data directory'slibraries/, then each--library-root.src/-rooted (sources recursive,src/the only include dir); a 1.0 library compiles from its root plusutility/, and never fromexamples//extras/.stdint.his the toolchain's). A library's own guarded platform includes (FastLEDnames every ESP32/nRF52/STM32 header it knows behind#ifdef) are not reported; the preprocessor decides whether they are read.CLI surface on the existing
fbuild fqbn:prints
library_count,library.<i>,library_root.<i>,library_include.<i>.<j>,library_source.<i>.<j>,unresolved_header.<i>; JSON carries the same underlibraries. A--compileof the sketch gains the selected include directories, which is the wiring the report would otherwise only describe.Real e2e (no fixtures)
arduino:[email protected]installed from the published index (checksums verified) plus a realFastLED3.10.10 checkout as--library-root:then the sketch TU through the package's own
recipe.cpp.o.pattern:A deliberately-missing
<NotInstalledHere.h>was reported asunresolved_header.0and refused by avr-g++ with that exact name, then removed to make the run green.Gates
soldr cargo test -p fbuild-build-engine --lib: 742 passed / 0 failed / 6 ignored (12 new library tests)soldr cargo test -p fbuild-cli: 598 + 12 passed / 0 failed (4 new CLI tests: text, JSON, include-wiring, in-bandlibrary_error)soldr cargo clippy -p fbuild-build-engine -p fbuild-cli --all-targets -- -D warnings: exit 0ci/enforce_platform_boundary.py --print-totals:rows=0; dylint_rows=0;platform_boundary_research.py --check: exit 0cargo fmt --all --check: cleanfqbn_cmd_library_tests.rs) so every.rsstays under the 1000-line gate.RED proven twice: removing the core-header check fails the core/unresolved test; removing the include-append in
plan_compilefails the include-wiring test.#1298 stays open — the remaining cell is
fbuild build --fqbn.