Repository navigation
feat(fqbn): archive the core and link an executable through the package's own recipes - #2237
Merged
Merged
Conversation
…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.
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.
Follow-up 4c of #1298 — the issue stays open (library discovery,
.inopreprocessing,
recipe.hooks.*andfbuild build --fqbnremain).--compileturned a source into an object. An Arduino build then does two morethings, and both are decisions rather than templates.
Engine —
crates/fbuild-build-engine/src/fqbn_link.rsplan_archive/archive: onerecipe.ar.patterninvocation per object,into one archive. The archive is removed first:
ar rcsappends, so amember 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: onerecipe.c.combine.patternexpansion over thecaller's objects plus that archive. The image is removed before the link for
the same reason.
build.arch(package architecture uppercased),build.core.path,build.variant.path,build.path(the output'sdirectory),
build.project_name(the.elfstem),object_files(one quotedargument per object, in
--objectorder), andarchive_file/archive_file_pathonly 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.
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.
--propmay not shadow any of the derived values.CLI —
fbuild fqbn --archiveand--linkOne step per invocation, in the order the builder runs them. The archive a link
consumes is
--core-archive, never--archive: one flag that sometimes buildsand 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, thenarchive_invocations/archive_exit/archive_byteswith
--run;link_output,link_recipe,link_objects,link_object.N,link_archive,link_command, thenlink_exit/link_bytes.--jsoncarriesthe same under
archive/link, witharchive_link_errorinstead of anon-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 throughrecipe.c.o.pattern/recipe.cpp.o.pattern/recipe.S.o.pattern.--archive build/core.a --object ... --run→ 25avr-gcc-arinvocations,exit 0, archive 354,868 bytes.
#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
.cppthatomits
#include <Arduino.h>compiles fine and then fails withundefined reference to 'setup', because that header is what givessetup/loopC linkage — one more reason the.inopreprocessing stage is thenext cell.
Gates — module 17/17; engine
--lib701 passed / 0 failed;fbuild-cli --bin fbuild587 passed / 0 failed; clippy-D warnings0 (linux, and--target x86_64-pc-windows-msvc);cargo check --target aarch64-apple-darwin0; 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_pathfails both package-composedarchive tests (15 passed / 2 failed, exit 101).
Deliberately not done: no linking of a sketch built from
.ino(preprocessingis the open cell), no library discovery, no
recipe.hooks.*, nofbuild build --fqbn.