Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: New target which generates a sort of development kit for llext #69831

Merged
merged 8 commits into from
May 17, 2024

Conversation

edersondisouza
Copy link
Collaborator

Loadable extensions need access to Zephyr (and Zephyr application) includes and some CFLAGS to be properly built. This RFC adds a new target, llext-edk, which generates a tar file with those includes and flags that can be loaded from make and make files.

This tar file can then be used by extension developers to build extensions that can be loaded by the Zephyr application - it becomes some sort of - for a better name, suggestions welcome =D - Extension Development Kit or EDK.

The main point of the EDK is to provide an interface for extension developers, which may not have access to the Zephyr application source code, so their build is entirely out of tree. The expected usage flow would be like:

  1. Application developer creates an application, with its own API in addition to that of Zephyr;
  2. Application developer builds the EDK via west build -t llext-edk;
  3. Application developer somehow makes the EDK available to extension developer;
  4. Extension developer extracts EDK and includes it in its build system - the EDK provides some files to aid getting CFLAGS for cmake or make;
  5. Extension developer can build the extension.

The final form of the extension or how it is loaded by the application is beyond the scope of the EDK - it's a "contract" between application and extension developers. That said, I can see how in the future some features for this could be included in Zephyr and the EDK.

Last patch in this series is an example of an application and a few extensions. The README contains the instructions for building everything, and should give a good feeling of how everything fits together. Ideally, this sample would live in several repositories: one for the application, and one for each extension, to show how the EDK acts as the bridge to build the extensions. But to ease review (and because having several repositories is too much), it's another sample.

As with any RFC, comments/critics/suggestions are welcome =D

Note 1: One of the patches is actually taken from #69540 - and it's here because it's needed for the sample to work. Once that PR is in, I'll rebase this one.
Note 2: The sample uses EXPORT_SYMBOL to export some Zephyr APIs to the extensions (like semaphores and threads). However, checkpatch.pl complains that the exports should be close to the symbols being exported. I didn't go changing several places in Zephyr just for this, to avoid distraction during review, but I can update the PR to do that. Not sure how Zephyr will handle this: will every API be exported at some point?

Copy link
Member

@cfriedt cfriedt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it!

Copy link
Collaborator

@teburd teburd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a really high quality pr and feature add. Adding the exports as proper exports seems like an easy improvement. Reuse of the cmake work @pillo79 has done would be great to see.

fantastic stuff!

cmake/compiler/gcc/target_arm.cmake Outdated Show resolved Hide resolved
samples/subsys/llext/edk/app/src/main.c Outdated Show resolved Hide resolved
samples/subsys/llext/edk/ext1/CMakeLists.txt Show resolved Hide resolved
@edersondisouza edersondisouza force-pushed the llext-edk branch 3 times, most recently from 5ec17b3 to 3d32e9c Compare March 7, 2024 01:20
pillo79
pillo79 previously approved these changes May 13, 2024
teburd
teburd previously approved these changes May 13, 2024
kartben
kartben previously approved these changes May 13, 2024
Copy link
Collaborator

@tejlmand tejlmand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my main concern still lies with the comment here: #69831 (comment)

I need some more info / investigation on this.
How much has this been tested / verified ?
Especially, has the loadable extension been tested with floating point instructions ?

I need a bit more detailed info on exactly what / why this happens before approving something which just removes ABI flags.

Comment on lines 12 to 13
set(LLEXT_EDK_INSTALL_DIR $ENV{LLEXT_EDK_INSTALL_DIR})
include($ENV{LLEXT_EDK_INSTALL_DIR}/cmake.cflags)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two observations.
First you create a local scoped variable with value from the environment setting, but then the line below uses the environment value in the include, like: include($ENV{LLEXT_EDK_INSTALL_DIR} ...

Why not use the local scoped variable ?

Second, while environment variables are useful, then leftover variables can be annoying as well as making it harder to just do a quick test.

So please also support / provide example on just passing the variable directly on CMake invocation, so this is also supported -DLLEXT_EDK_INSTALL_DIR=<path> and takes precedence over env setting.

Comment on lines +434 to +435
parser.add_argument("-u", "--userspace-only", action="store_true",
help="Only generate the userpace path of wrappers")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your reasoning, but that doesn't really remove the concern.
Note, I will not block PR on this.

@dcpleung please take a look.

Comment on lines +62 to +67
list(APPEND LLEXT_EDK_REMOVE_FLAGS
--sysroot=.*
-fmacro-prefix-map=.*
)

list(APPEND LLEXT_EDK_APPEND_FLAGS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your line of thought, but the toolchain infrastructure, and thus the cmake/compiler/gcc/* is for setting up the toolchain for building Zephyr. Something which is done in the current CMake invocation.

Where those flags are for exporting when building the extension, which is something quite different.

There is no obvious place for an alternative location atm.
I did consider if llext should have its own CMake module, but that collides a bit with the fact that a llext-edk target in now created.

Accepted to keep for now, but could you file an enhancement issue so that we don't forget a later cleanup, as well as providing a bit of history as to why this location was accepted. So that we can reference in future PRs.

cfriedt
cfriedt previously approved these changes May 15, 2024
Besides the LLEXT_CFLAGS, which have all that is needed to compile,
generate more granular ones, LLEXT_INCLUDE_CFLAGS,
LLEXT_ALL_INCLUDE_CFLAGS, LLEXT_GENERATED_INCLUDE_CFLAGS and
LLEXT_BASE_CFLAGS. These are done for convenience, as they can help on
different setups, such as unit testing.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
This way they can be reused by the LLEXT EDK.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
Some flags are common between in tree extensions and out of tree
supported by the EDK. Instead of duplicating those flags, the EDK reuses
the llext ones.

However, as the EDK has its own needs, two new lists,
`LLEXT_EDK_APPEND_FLAGS` and `LLEXT_EDK_REMOVE_FLAGS` are defined to
allow EDK to append or remove flags as needed.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
Instead of hardcoding `autoconf.h` imacro, get the list of imacros from
the llext flags. As those come in the form of absolute paths, they also
need to be massaged to point from the EDK directory without revealing
host complete paths.

Also, the EDK now keeps the imacros on a different flag,
`LLEXT_GENERATED_IMACROS_CFLAGS`, to keep it similar to other generated
includes.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
This test uses pytest to generate an EDK from a simple Zephyr
application, and uses this EDK to build a simple extension, to ensure
that EDK generation is sane.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
Shows a simple application which loads extensions and some simple
extensions. While everything is inside Zephyr tree, everything can
actually be build from different directories (even machines), as long as
the EDK is generated from the application and used by the extensions.
More information is available at sample's README.

This sample is build only for twister, as it requires a few steps to be
properly run, namely build the EDK, install it somewhere, build the
extensions using the EDK and finally build the application with the
extensions.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
@edersondisouza
Copy link
Collaborator Author

edersondisouza commented May 16, 2024

v8:

  • Preserve order of includes on generated flags;
  • Allow one to use -DLLEXT_EDK_INSTALL_DIR directly on CMake for extensions (in addition to env var);
  • Better describe the workaround needed to run the sample application.

Copy link
Collaborator

@tejlmand tejlmand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

Still concerned on the removal, but at least the code is better commented and there is a followup issue, #72832.
Currently the best that can be done, while also allowing the feature to be merged and get more user feedback.

@fabiobaltieri fabiobaltieri merged commit 972eecf into zephyrproject-rtos:main May 17, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet