Repository navigation
feat(fqbn): run pre-link hooks and compile the variant folder (#1298 4e) - #2243
Merged
Merged
Conversation
A vendor core's link is not one template: `Seeeduino:mbed` composes its
linker script with `recipe.hooks.linking.prelink.1.pattern` (`-E -P -x c`
variant -> build.path) and links the composed copy with
`-T{build.path}/{build.ldscript}`, and its pin tables live in
`variants/<board>/variant.cpp`, which Arduino compiles into the core
archive.
- plan every `recipe.hooks.linking.prelink.<n>.pattern` in numeric order
(prelink.10 after prelink.2) and run them before the linker; a hook
that exits non-zero stops the link and names its key
- include the variant folder's own sources in `core_sources` (top level
only, matching Arduino; a variant's subdirectories are not compiled)
- CLI: link_hooks=N / link_hook.<i>= / link_hooks_run=N, and
link.hooks[] in JSON
Real e2e on the published Seeeduino mbed 2.9.3 core + arm-none-eabi
7-2017q4: 42 core units -> core.a 27,637,612 B, prelink hook ran,
link exit 0 -> Blink.elf 1,732,660 B ELF32 ARM EXEC with main/setup/loop.
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.
Follow-up 4e of #1298: an FQBN build now links a sketch through a vendor core's own pre-link hooks and variant sources, proven end-to-end on the published Seeeduino
mbed2.9.3 core (XIAO nRF52840 Plus).#1298 stays open — the upload/objcopy half is a separate cell.
What was missing (both found from the real package, not from a fixture)
recipe.hooks.linking.prelink.<n>.pattern. Arduino runs these in numeric order beforerecipe.c.combine.pattern. Thembedcore uses exactly that to compose the linker script into the build directory:So the linker's script does not exist until the builder runs the hook — and a plain copy is wrong too, because the script is C-preprocessed (
#define FLASH_ORIGIN …collapses to a number).fbuild fqbn --linknow plans every prelink hook (expanded over the same properties as the link, ordered numerically —prelink.10afterprelink.2), runs them before the linker, and stops the link when a hook exits non-zero, naming the hook key and leaving no image.The board's variant folder is part of the core archive. Arduino compiles
variants/<build.variant>/*intocore.aalongsidecores/<build.core>/**(its own files only, not subdirectories). Withoutvariant.cppthe archive builds clean and the ELF dies withundefined reference to g_APinDescription / PINCOUNT_fn / getUniqueSerialNumber / _ontouch1200bps_.core_sourcesnow includes those files.CLI:
--linkreportslink_hooks=Nandlink_hook.<i>=<command>, and after--runlink_hooks_run=N; the JSON gainslink.hooks[]andlink_outcome.hooks.Real end-to-end (not a fixture)
Data dir built from the published index: core tarball
ArduinoCore-mbed-2.9.3.tar.bz2(34,722,259 B, sha25665d9de0b…fd784f, matches the index) and toolchainarm-none-eabi-gcc 7-2017q4(index sha25696a029e2ae13…), installed at the canonical<data>/packages/<vendor>/{hardware,tools}layout.cores/arduino+variants/SEEED_XIAO_NRF52840_PLUS/variant.cpp)--archivearm-none-eabi-arinvocations →core.a27,637,612 BBlink.cpp→ 936,772 B--linklink_hooks_run=1,link_exit=0→Blink.elf1,732,660 Breadelf -h0x2fb6dmain(WEAK, the mbed starter),setup,loopbuild_mbed/linker_script.ld4,242 B, preprocessed (FLASH ORIGIN = 0x27000, no#defineleft)Gates (real output)
soldr cargo test -p fbuild-build-engine --lib→ 709 passed, 0 failed, 6 ignoredsoldr cargo test -p fbuild-cli --bin fbuild→ 589 passed, 0 failedsoldr cargo clippy -p fbuild-build-engine -p fbuild-cli --all-targets -- -D warnings→ 0uv run --no-project python ci/enforce_platform_boundary.py --print-totals→ rows=0; dylint_rows=0cargo fmt --all -- --check→ cleanRED, twice:
take(0)) →a_prelink_hook_runs_before_the_linker_and_blocks_it_when_it_cannot_runfails, 19 passed / 1 failed, exit 101;the_variant_folder_sources_join_the_core_but_not_its_subdirectoriesfails, 17 passed / 1 failed, exit 101.undefined referenceblock above.Tests added
prelink_hooks_are_planned_in_numeric_order_and_name_the_composed_script(1, 2, 10 — a lexical sort would reverse 2 and 10)a_package_without_prelink_hooks_plans_nonea_prelink_hook_runs_before_the_linker_and_blocks_it_when_it_cannot_runthe_variant_folder_sources_join_the_core_but_not_its_subdirectoriesthe_link_report_names_the_prelink_hooks_in_order(text + JSON)