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

[FEATURE][Zephyr] Remove duplication of CMake rules between Zephyr and XTOS #8260

Open
kv2019i opened this issue Sep 25, 2023 · 19 comments
Open
Assignees
Labels
enhancement New feature or request Zephyr Issues only observed with Zephyr integrated
Milestone

Comments

@kv2019i
Copy link
Collaborator

kv2019i commented Sep 25, 2023

Is your feature request related to a problem? Please describe.
When a software module is added to SOF that can be used both in XTOs and in Zephyr builds, the module sources need to be added to CMake rules twice:

  • first in sof/src/foo/CMakeLists.txt (for XTOS), and
  • second time to sof/zephyr/CMakeLists.txt (for Zephyr)

This split of Cmake rules dates back to the time when Zephyr support was introduced and codebase was not cleanly split between operating systems. Now we have a cleaner split at top-level source directories, so it should be possible to start cleaning up this overlap in definitions.

Describe the solution you'd like

Describe alternatives you've considered

Additional context
Platforms where transition to Zephyr is still in progress might cause some extra challenges to doing this makefile cleanup. E.g. see XTOS-only a

@kv2019i kv2019i added the enhancement New feature or request label Sep 25, 2023
@kv2019i
Copy link
Collaborator Author

kv2019i commented Sep 25, 2023

FYI @dbaluta @lgirdwood @marc-hb @marcinszkudlinski -- not tagging to v2.8 yet. A bit more feasibility and work effort analysis is needed to gauge the effort and options. But sooner or later we need to get rid of the duplication.

@kv2019i kv2019i added the Zephyr Issues only observed with Zephyr integrated label Sep 25, 2023
@lgirdwood lgirdwood added this to the v2.8 milestone Oct 2, 2023
@lgirdwood
Copy link
Member

@kv2019i I'm going to track this for v2.8, even if its likely to complet in v2.9. Just to keep it on our radar.

@lyakh
Copy link
Collaborator

lyakh commented Oct 26, 2023

the best would be of course if we could re-use CMakeLists.txt in subdirectories for both XTOS and Zephyr. If this is impossible, we could move XTOS specific code to xtos.cmake, add Zephyr to zephyr.cmake and put any common code in CMakeLists.txt

@marc-hb
Copy link
Collaborator

marc-hb commented Oct 26, 2023

if we could re-use CMakeLists.txt in subdirectories for both XTOS and Zephyr.

I noticed sof/zephyr/CMakeLists.txt uses zephyr_sources(), not the plain target_sources(). I'm not sure why. I found these:

zephyr/samples/**/CMakeLists.txt and zephyr/tests/**/CMakeLists.txt use target_sources().

EDIT: there is some "documentation" in zephyr/cmake/modules/extensions.cmake

@lgirdwood
Copy link
Member

Can we drop target_sources everywhere and use zephyr sources e.g. somethimg like for xtos

#define zephyr_sources(x) target_sources(x)

@marc-hb
Copy link
Collaborator

marc-hb commented Oct 30, 2023

#define zephyr_sources(x) target_sources(x)

Not without first understanding the difference between the two... even then, that would be super confusing considering Zephyr itself uses both. CMake is painful enough and short-staffed enough already.

When a software module is added to SOF that can be used both in XTOS and in Zephyr builds, the module sources need to be added to CMake rules twice:

I think this is a feature, not a bug. Pretty much every SOF engineer I've seen is either working with Zephyr or with XTOS but never with both. So, any engineer adding a new .c file will most likely have tested the new file in ONLY one of these environments (if tested at all, see for instance smart_amp.c that never compiled #8411). So why should they (accidentally?) add the new .c file to the other, totally untested environment? If another engineer wants to re-use the new .c file in the other environment then they can add it there after testing it.

All this being said, the list of common *.c files could be shared in a CMake list and then added by a foreach loop. But again I think this would be the wrong thing to do.

second time to sof/zephyr/CMakeLists.txt (for Zephyr)

I agree this location is inconvenient. Let me think about it.

@marc-hb
Copy link
Collaborator

marc-hb commented Oct 31, 2023

I agree this location is inconvenient. Let me think about it.

I have something promising, stay tuned.

@marc-hb
Copy link
Collaborator

marc-hb commented Oct 31, 2023

@lgirdwood
Copy link
Member

@marc-hb what do you think the next steps are now that #8422 is merged ?

@marc-hb
Copy link
Collaborator

marc-hb commented Nov 10, 2023

My plan is to wait ~1 week for the sky to fall (e.g: people compiling SOF in some unusual Zephyr configurations) and if that has not happened then just keep at it: moving more and more files gradually. It should only take a few shots.

@marc-hb marc-hb self-assigned this Nov 10, 2023
marc-hb added a commit to marc-hb/sof that referenced this issue Nov 18, 2023
For reducing CMake duplication and centralization, see thesofproject#8260

Not used yet.

Signed-off-by: Marc Herbert <[email protected]>
marc-hb added a commit to marc-hb/sof that referenced this issue Nov 18, 2023
This makes the code shorter and will help with thesofproject#8260

Zero functional change.

Do not use it when Zephyr use is not conditional.

Signed-off-by: Marc Herbert <[email protected]>
marc-hb added a commit to marc-hb/sof that referenced this issue Nov 18, 2023
@kv2019i
Copy link
Collaborator Author

kv2019i commented Nov 24, 2023

This is well under way, but I think completing the task will go beyond SOF2.8, bumping milestone.

@kv2019i kv2019i modified the milestones: v2.8, v2.9 Nov 24, 2023
marc-hb added a commit to marc-hb/sof that referenced this issue Nov 28, 2023
For reducing CMake duplication and centralization, see thesofproject#8260

Not used yet.

Signed-off-by: Marc Herbert <[email protected]>
marc-hb added a commit to marc-hb/sof that referenced this issue Nov 28, 2023
This makes the code shorter and will help with thesofproject#8260

Zero functional change.

Do not use it when Zephyr use is not conditional.

Signed-off-by: Marc Herbert <[email protected]>
lgirdwood pushed a commit that referenced this issue Nov 29, 2023
For reducing CMake duplication and centralization, see #8260

Not used yet.

Signed-off-by: Marc Herbert <[email protected]>
lgirdwood pushed a commit that referenced this issue Nov 29, 2023
This makes the code shorter and will help with #8260

Zero functional change.

Do not use it when Zephyr use is not conditional.

Signed-off-by: Marc Herbert <[email protected]>
marc-hb added a commit to marc-hb/sof that referenced this issue Nov 29, 2023
marc-hb added a commit to marc-hb/sof that referenced this issue Dec 6, 2023
CMake decentralization per thesofproject#8260

The purpose of thesofproject#8260 is to divide and conquer the giant
zephyr/CMakeLists.txt file while staying _bug-for-bug compatible_.

Signed-off-by: Marc Herbert <[email protected]>
@marc-hb
Copy link
Collaborator

marc-hb commented Jan 12, 2024

This is still high on my list but unlikely to happen for v2.9

@lgirdwood
Copy link
Member

This is still high on my list but unlikely to happen for v2.9

We can do this incrementally, module by module if needed.

@marc-hb
Copy link
Collaborator

marc-hb commented Jan 17, 2024

This is still high on my list but unlikely to happen for v2.9

Very bad phrasing sorry, I meant unlikely to be completed for v2.9. I will hopefully have time to make some progress before v2.9.

marc-hb added a commit to marc-hb/sof that referenced this issue Feb 29, 2024
Commit 7680a7b ("cmake: add testbench host build") added a
`return()` in the middle of `src/audio/CMakeLists.txt` to exclude some
C files from testbench compilation.

It wasn't easy to read already at the time. Now that the file has grown
bigger it's become even harder to spot and even more confusing.

Soon, thesofproject#8260 will also add Zephyr to this file which will make things
much worse.

Solve all this by moving testbench and plugin compilation to a new,
separate, `native.cmake` file.

Reported in thesofproject#8606

Signed-off-by: Marc Herbert <[email protected]>
@kv2019i
Copy link
Collaborator Author

kv2019i commented Mar 4, 2024

Stable-v2.9 branched, this didn't make the cut, bumping to 2.10.

@kv2019i kv2019i modified the milestones: v2.9, v2.10 Mar 4, 2024
@lgirdwood lgirdwood modified the milestones: v2.10, v2.11 Jun 10, 2024
@marc-hb marc-hb removed their assignment Aug 1, 2024
@kv2019i
Copy link
Collaborator Author

kv2019i commented Sep 6, 2024

No owner, moving to v2.12

@kv2019i kv2019i modified the milestones: v2.11, v2.12 Sep 6, 2024
@marc-hb
Copy link
Collaborator

marc-hb commented Sep 6, 2024

#8892 should still work

@kv2019i
Copy link
Collaborator Author

kv2019i commented Dec 13, 2024

Feature cutoff for v2.12, moving this to v2.13.

@kv2019i kv2019i modified the milestones: v2.12, v2.13 Dec 13, 2024
@lgirdwood
Copy link
Member

@kv2019i one for your planning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Zephyr Issues only observed with Zephyr integrated
Projects
None yet
Development

No branches or pull requests

4 participants