Skip to content

Conversation

@pillo79
Copy link
Contributor

@pillo79 pillo79 commented Oct 27, 2025

Not for merge in 4.3, obviously - at this stage, looking for feedback on the approach and especially if others had similar issues with the EDK.

The symptom

While developing the Arduino core, we encountered an issue compiling code that used the fatfs module via the EDK; it looked like some defaults were being used in the extension, even though specific compile options were applied during the main Zephyr build.

The actual problem

Tracking down the source revealed that the EDK is not exporting all build information, but only those defined by the Zephyr core (the zephyr_interface target). Modules do not interfere with the Zephyr core but insert themselves as dependencies of the app target, so transitive evaluation applies there only.

Ruled-out solutions

  • The current way of reading properties (e.g. zephyr_get_compile_options_for_lang) cannot be used for the app target, because at the time the main Zephyr CMakeLists.txt is evaluated, that target is not yet available (and definitely not fully configured).

  • Trying to use generator expressions is also not possible, due to CMake not allowing expansion of $<COMPILE_LANGUAGE:...> outside of a proper compile context. These expressions were stripped by complex code in get_*_for_lang functions, but that's no longer possible if the actual flags are hidden in a genex. The process errors out at configuration time.

The proposed solution

To work around this, this change introduces a new CMake subdirectory (misc/llext_edk) that creates a dummy target which imports the build configuration from app, but overrides the C compile rules to simply output the resulting properties (defines, include directories, flags) to text files. The EDK generation script then reads those text files to get the full set of build properties, and includes them in the EDK tarball.

Important

This (ab-)uses the CMake build process in a way that is often cited as an error - setting toolchain variables from a CMakeLists.txt selectively overrides an existing configuration, and is typically discouraged. However, that's 1) documented, stable behavior and 2) exactly what we are after in this case: use every option from the existing toolchain, but "discard" the compiler executable.

A test has been added to verify the functionality by checking if a symbol defined in an interface library that is a dependency of app is properly exported to the extension.

@pillo79 pillo79 added this to the v4.4.0 milestone Oct 27, 2025
Remove extra spaces between 'if' and '(' in CMake code, as identified by
CI linting checks.

Signed-off-by: Luca Burelli <[email protected]>
This changes the LLEXT EDK flag filtering to be done after the main
Zephyr build is completed. Instead of filtering the flags via genexes,
the full set is passed to the script along with the set of filters to be
applied, and the filter is applied later.

No functional change is intended.

Signed-off-by: Luca Burelli <[email protected]>
The current implementation of the LLEXT EDK exports only a partial set
of compiler settings to the EDK build system, specifically only the ones
defined by the Zephyr core (the 'zephyr_interface' target). Extending
this to include application and module-specific settings (from the 'app'
target and its dependencies) is tricky, because:
- while evaluating the main CMakeLists.txt, the 'app' target is not
  fully configured yet, and
- using generator expressions is not possible due to CMake not allowing
  expansion of $<COMPILE_LANGUAGE:...> outside of a proper compile
  context.

To work around this, this change introduces a new CMake subdirectory
(misc/llext_edk) that creates a dummy target which imports the build
configuration from 'app', but overrides the C compile rules to simply
output the resulting properties (defines, include directories, flags)
to text files. The EDK generation script then reads those text files
to get the full set of build properties, and includes them in the EDK
tarball.

Signed-off-by: Luca Burelli <[email protected]>
Add an interface library to the test application that defines a macro
whose value is later used in the extension. This verifies the full
dependency chain for 'app' is evaluated during EDK generation.

Signed-off-by: Luca Burelli <[email protected]>
@pillo79 pillo79 force-pushed the pr-llext-edk-rework branch from fcf2334 to 7df1965 Compare October 27, 2025 20:32
@pillo79 pillo79 added the RFC Request For Comments: want input from the community label Oct 27, 2025
@sonarqubecloud
Copy link

@pillo79 pillo79 marked this pull request as ready for review October 27, 2025 21:18
@zephyrbot zephyrbot added area: Tests Issues related to a particular existing or missing test area: llext Linkable Loadable Extensions area: Build System labels Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Build System area: llext Linkable Loadable Extensions area: Tests Issues related to a particular existing or missing test RFC Request For Comments: want input from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants