- 
                Notifications
    
You must be signed in to change notification settings  - Fork 8.2k
 
sysbuild: Add support for snippets #73254
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
Conversation
353cac7    to
    6ce64d8      
    Compare
  
    6ce64d8    to
    3dcc794      
    Compare
  
    3dcc794    to
    384d5c9      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the need for extending the snippet functionality to cover sysbuild, but I think we should look into how snippets themselves can be extended to also support sysbuild.
For  example by supporting a sysbuild field.
A loose thought could be:
name: foo
append:
  EXTRA_DTC_OVERLAY_FILE: foo.overlay # Setting still goes to main app.
sysbuild:
  append:
    SB_EXTRA_CONF_FILE: sysbuild_foo.conf  # Setting goes to sysbuild.
this could further allow sysbuild section in the snippet to pass additional settings to images when sysbuild is used, for example:
name: foo
append:
  EXTRA_DTC_OVERLAY_FILE: foo.overlay # Setting still goes to main app.
sysbuild:
  append:
    SB_EXTRA_CONF_FILE: sysbuild_foo.conf  # Setting goes to sysbuild.
  images:
    - name: bar
      append:
          EXTRA_CONF_FILE: bar_foo.conf  # Setting goes to bar image, when using sysbuild.
all of this can of course still be applied on a per-board basis as allowed in snippets today.
A benefit of such approach is that a common snippet name can be used and applied with -DSNIPPET=<snippet> or -S <snippet> when using sysbuild with west.
Has such approach been considered ?
          
 It was the first method I tried, it did not work because you need to validate the file and it failed  | 
    
          
 which validation failed ?  | 
    
          
 I don't remember, it was 2 weeks ago  | 
    
          
 If it was the first method you tried, then it sounds like you also consider it to be a better approach. So please try to post the old code, if lucky you have it in   | 
    
| 
           They changes were never commited  | 
    
| 
           The snippets are applied to a specific image, snippets do not know what sysbuild is, it just knows what a non-specific image is, and if a snippet is used on an image, applies those variables to it in addition, therefore SB_* variables cannot be used  | 
    
384d5c9    to
    8ed2b50      
    Compare
  
    
          
 actually it doesn't even know that. which in CMake is then retrieved by calling  This means that snippets parsing can simply write: if the section within the snippet itself relates to a specific image. What should be considered is whether the sysbuild generated  I think image specific SNIPPET arguments, like   | 
    
8ed2b50    to
    1ac1d30      
    Compare
  
    1ac1d30    to
    969b057      
    Compare
  
    6abeb34    to
    cd23ed8      
    Compare
  
    cd23ed8    to
    b9dccf6      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work.
We should try to keep the code under cmake/modules/ free from sysbuild specific implementation and instead have such adjustments under share/sysbuild/cmake/modules.
        
          
                cmake/modules/snippets.cmake
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sysbuild_SNIPPET should be SB_SNIPPET to follow same naming pattern as SB_CONF_FILE, SB_EXTRA_CONF_FILE, SB_CONFIG_<kconfig_setting>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
        
          
                cmake/modules/snippets.cmake
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two comments.
First, the code in <zephyr_base>/cmake/modules/ should be free of sysbuild specific handling.
Base code should be re-usable and sysbuild specifics should go to <zephyr_base>/share/sysbuild/cmake/modules/ in a sysbuild_snippets.cmake which can then include the snippets.cmake.
Like we do for other CMake modules.
Second comment is for opening a discussion on which behavior we want ?
This code means that if user does -DSNIPPET=foo -DSB_SNIPPET=bar, then both foo and bar will be considered by sysbuild.
Are we sure that's really the behavior we want ?
It makes it harder for users to request sysbuild to opt-out of foo.
Whereas, if SB_SNIPPET supersede values given by SNIPPET, then a user wanting
- All images to use 
fooand sysbuild to usebar, can do:
-DSNIPPET=foo -DSB_SNIPPET=bar - All images to use 
fooand sysbuild to use bothfooandbar, can do
-DSNIPPET=foo -DSB_SNIPPET=foo,bar 
The latter also has the pros of allowing the user to define the order, foo before bar or bar before foo.
The current implementation has decided the order for the user.
In this case, always foo before bar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reworked to support this
        
          
                cmake/modules/snippets.cmake
              
                Outdated
          
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we move SNIPPET_ROOT handling into the common root handling https://github.com/zephyrproject-rtos/zephyr/blob/main/cmake/modules/root.cmake and similar for the sysbuild part https://github.com/zephyrproject-rtos/zephyr/blob/main/share/sysbuild/cmake/modules/sysbuild_root.cmake then it follows the same principle as other roots and we avoid sysbuild specifics in the common snippet module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps SB_EXTRA_CONF_FILE ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
b9dccf6    to
    6dc09f8      
    Compare
  
    6dc09f8    to
    c0302e4      
    Compare
  
    Adds support for sysbuild loading snippets, these can be included by using e.g.: cmake ... -DSB_SNIPPET=blah for sysbuild directly or can be used with an application and sysbuild using -DSNIPPET. Snippets for sysbuild can use SB_EXTRA_CONF_FILE in the snippet file to specify an extra Kconfig fragment for sysbuild Signed-off-by: Jamie McCrae <[email protected]>
Adds a new test that ensures sysbuild snippets work and are applied correctly Signed-off-by: Jamie McCrae <[email protected]>
Adds an example on how to use a snippet with sysbuild Signed-off-by: Jamie McCrae <[email protected]>
Prevents sysbuild from being used as this adds a local snippet root which should only be used (and tested) by application Signed-off-by: Jamie McCrae <[email protected]>
c0302e4    to
    24a3514      
    Compare
  
    | 
           @nordicjm this is causing failures in main, please have a look  | 
    
          
 Typo? The app kconfig did not get overidden.  | 
    
Adds support for sysbuild loading snippets, these can be included by using e.g.: cmake ... -DSB_SNIPPET=blah
Fixes #73250