Skip to content

feat(fqbn): archive the core and link an executable through the package's own recipes - #2237

Merged
zackees merged 1 commit into
mainfrom
agent/fqbn-link
Dec 2, 2026
Merged

zackees merged 1 commit into
mainfrom
agent/fqbn-link

Conversation

@zackees

@zackees zackees commented Dec 2, 2026

Copy link
Copy Markdown
Member

Follow-up 4c of #1298 — the issue stays open (library discovery, .ino
preprocessing, recipe.hooks.* and fbuild build --fqbn remain).

--compile turned a source into an object. An Arduino build then does two more
things, and both are decisions rather than templates.

Engine — crates/fbuild-build-engine/src/fqbn_link.rs

  • plan_archive / archive: one recipe.ar.pattern invocation per object,
    into one archive. The archive is removed first: ar rcs appends, so a
    member from an earlier build would link code that is no longer in the tree
    and the linker would not say a word about it.
  • plan_link / link: one recipe.c.combine.pattern expansion over the
    caller's objects plus that archive. The image is removed before the link for
    the same reason.
  • Derived, not guessed: build.arch (package architecture uppercased),
    build.core.path, build.variant.path, build.path (the output's
    directory), build.project_name (the .elf stem), object_files (one quoted
    argument per object, in --object order), and archive_file /
    archive_file_path only where the package does not define them itself —
    the real AVR core defines archive_file_path={build.path}/{archive_file},
    and shadowing it was the first thing the real package refused.
  • The command must name what was asked for. After expansion, both recipes
    must name the requested archive (and, for the link, the requested image); a
    package that would compose a different path is refused instead of trusted.
  • A --prop may not shadow any of the derived values.
  • Success is exit 0 and a non-empty archive / image.

CLI — fbuild fqbn --archive and --link

fbuild fqbn arduino:avr:uno --archive ./build/core.a \
  --object ./build/wiring.c.o --object ./build/main.cpp.o \
  --prop runtime.ide.version=10607 --run

fbuild fqbn arduino:avr:uno --link ./build/Blink.elf \
  --object ./build/Blink.cpp.o --core-archive ./build/core.a \
  --prop runtime.ide.version=10607 --run

One step per invocation, in the order the builder runs them. The archive a link
consumes is --core-archive, never --archive: one flag that sometimes builds
and sometimes links against a file would make "rebuild the archive" and "link
this archive" indistinguishable, and a link that silently rebuilt its own input
would discard the members it was built from (measured: it did).

Reports are in-band: archive_file, archive_recipe, archive_object.N,
archive_command.N, then archive_invocations/archive_exit/archive_bytes
with --run; link_output, link_recipe, link_objects, link_object.N,
link_archive, link_command, then link_exit/link_bytes. --json carries
the same under archive / link, with archive_link_error instead of a
non-zero exit when the plan fails.

Real end-to-end, no arduino-cli (Arduino's own published index,
arduino:[email protected], toolchain [email protected]):

  • --sources → 25 core translation units, each compiled through
    recipe.c.o.pattern / recipe.cpp.o.pattern / recipe.S.o.pattern.
  • --archive build/core.a --object ... --run → 25 avr-gcc-ar invocations,
    exit 0, archive 354,868 bytes
    .
  • a sketch unit (#include <Arduino.h> + setup/loop) compiled the same way,
    then --link build/Blink.elf --core-archive build/core.a --run → exit 0,
    9,968 bytes, ELF32, machine "Atmel AVR 8-bit microcontroller", flags avr:5
    .

That last run also produced a fact worth keeping: a hand-written .cpp that
omits #include <Arduino.h> compiles fine and then fails with
undefined reference to 'setup', because that header is what gives
setup/loop C linkage — one more reason the .ino preprocessing stage is the
next cell.

Gates — module 17/17; engine --lib 701 passed / 0 failed; fbuild-cli --bin fbuild 587 passed / 0 failed; clippy -D warnings 0 (linux, and
--target x86_64-pc-windows-msvc); cargo check --target aarch64-apple-darwin
0; fmt 0; boundary rows=0; dylint_rows=0.

RED proved twice — removing the stale-archive removal fails
a_stale_archive_is_removed_before_the_first_invocation (16 passed / 1 failed,
exit 101); always deriving archive_file_path fails both package-composed
archive tests (15 passed / 2 failed, exit 101).

Deliberately not done: no linking of a sketch built from .ino (preprocessing
is the open cell), no library discovery, no recipe.hooks.*, no
fbuild build --fqbn.

…ge's own recipes

Follow-up 4c of #1298 (the issue stays open): the two steps the
Arduino builder runs after compiling.

Engine module `fqbn_link`:
- `plan_archive`/`archive`: one `recipe.ar.pattern` invocation per object, into
  one archive. The archive is removed first, because `ar rcs` appends and a
  stale member would link code that is no longer in the tree.
- `plan_link`/`link`: one `recipe.c.combine.pattern` expansion over the
  caller's objects plus that archive.
- Derived, never guessed: `build.arch`, `build.core.path`,
  `build.variant.path`, `build.path`, `build.project_name`, and
  `archive_file`/`archive_file_path` only where the package does not define
  them itself (the AVR core defines `archive_file_path={build.path}/{archive_file}`).
- The expanded command must name the requested image and archive: a package
  that would compose a different path is refused instead of trusted.
- The image must be `<name>.elf`; a stale image is removed before the link, so
  an exit-0 linker that writes nothing cannot be measured against an older
  build.

CLI: `fbuild fqbn --archive FILE --object ...` and
`fbuild fqbn --link FILE.elf --object ... --core-archive FILE`, one step per
invocation. The archive a link consumes is named by `--core-archive`, never by
`--archive`: a flag that sometimes builds and sometimes links against a file
would make the two indistinguishable, and a link that silently rebuilt its own
input would discard the members it was built from.
@zackees
zackees added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit be97858 Dec 2, 2026
44 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Dec 3, 2026
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