Repository navigation
feat(fqbn): compile an Arduino sketch by preprocess-reusing SourceScanner (#1298) - #2242
Merged
Merged
Conversation
…nner `fbuild fqbn --compile <sketch>.ino` now plans the unit Arduino's builder would compile: the sketch directory's `.ino` tabs are concatenated with `#include <Arduino.h>` and the auto-generated prototype block into `build.path/sketch/<name>.ino.cpp`, which `recipe.cpp.o.pattern` compiles. The preprocessing is not re-derived: it goes through `SourceScanner`, the same code that preprocesses a PlatformIO sketch, so tab order, hoisted includes, `#line` mapping and prototypes cannot drift between the two build paths. The sketch directory stays on the include path because the generated unit lives under `build.path/sketch` and a quoted include must still resolve next to its tab. Refs #1298
6 tasks
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 fqbn <FQBN> --compile Blink.inonow compiles an Arduino sketch. Asketch has no recipe of its own; the Arduino builder preprocesses it into one
C++ translation unit first, and this is that stage:
.inotabs are concatenated (primary tab first, eachwith its own
#line 1 "<tab>"),#include <Arduino.h>is prepended when the core provides it, plus theauto-generated prototype block,
build.path/sketch/<name>.ino.cppand compiledwith
recipe.cpp.o.pattern.The preprocessing is reused, not re-derived: it goes through
SourceScanner::scan_sketch_sources_filtered_with_include_roots, the same codethat preprocesses a PlatformIO sketch, so tab order, hoisted includes, line
mapping and prototypes cannot diverge between the two build paths. The sketch
directory is kept on the include path because the generated unit lives under
build.path/sketchwhile a quoted#include "foo.h"must resolve next to itstab (Arduino copies sketch headers into
build.path/sketch; naming the sketchdirectory reaches the same files without copying).
A sketch directory that carries its own
main.cppis refused by name: thescanner does not generate a unit there, and compiling one anyway would
duplicate the entry point.
Refs #1298 (follow-up 4d). #1298 stays open.
Real end-to-end evidence
Installed from the vendors' own package indexes (
fbuild fqbn --install),nothing hand-assembled:
arduino:avr:uno— a full Blink build. 24/24 core units compiled, archive340,294 B, link exit 0:
setup/loop/blink_onceare inlined intomainby the core's own-flto -Oslink recipe (hence local symbols only).Seeeduino:mbed:xiaonRF52840Plus— the motivating slice. RealSeeeduino:[email protected](34,722,259 B) +arm-none-eabi-gcc@7-2017q4(99.8 MB);the preprocessed unit compiles through the native path:
Remaining cell (deliberately not attempted here): linking the full mbed core —
hundreds of TUs plus the mbed-os framework tree.
Gates
soldr cargo test -p fbuild-build-engine --lib: 705 passed, 0 failed, 6 ignoredsoldr cargo test -p fbuild-cli --bin fbuild: 588 passed, 0 failedsoldr cargo clippy -p fbuild-build-engine -p fbuild-cli --all-targets -- -D warnings: cleansoldr cargo fmt --all -- --check: cleanci/enforce_platform_boundary.py --print-totals:rows=0; dylint_rows=0is_sketch_sourcebranch removed the new tests fail(13 passed / 4 failed, exit 101).
New tests:
plans_a_sketch_by_preprocessing_it_into_one_translation_unit,a_sketch_keeps_its_own_directory_on_the_include_path,every_tab_is_concatenated_under_its_own_line_map,a_sketch_with_its_own_main_cpp_is_refused_rather_than_double_compiled(engine) and
a_sketch_is_planned_through_its_preprocessed_unit(CLI).