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

Tools: Testbench: Avoid need linux kernel headers in build #7244

Merged

Conversation

singalsu
Copy link
Collaborator

This patch adds a simplified linux/types.h into testbench headers to enable include of ALSA asoc.h to build without other difficult kernel headers content.

The include path for asoc.h is changed in fuzzer, tplg_parser, and testbench to be without prefix alsa/sound/uapi to allow the Makefile headers path to specify only the uapi directory.

This change avoids build fail with xcc toolchain that can't use the gcc toolchain headers from the system where the ALSA headers are located.

@singalsu singalsu marked this pull request as ready for review March 10, 2023 11:40
Copy link
Collaborator

@marc-hb marc-hb left a comment

Choose a reason for hiding this comment

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

Note this was successfully tested as part of larger

@@ -40,6 +40,7 @@ target_include_directories(sof-fuzzer PRIVATE
"${SOF_ROOT_SOURCE_DIRECTORY}/src/arch/host/include"
"${SOF_ROOT_SOURCE_DIRECTORY}/src/platform/library/include"
"${SOF_ROOT_SOURCE_DIRECTORY}"
"/usr/include/alsa/sound/uapi"
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be a CMake macro (with this as the default) as the ALSA lib prefix can be different.

Copy link
Collaborator

@marc-hb marc-hb left a comment

Choose a reason for hiding this comment

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

This change avoids build fail with xcc toolchain that can't use the gcc toolchain headers from the system where the ALSA headers are located.

On second thought this is way too much of a hack.

Instead ask CMake to copy /usr/include/alsa/sound/uapi/asoc.h into something like build_dir/alsa/sound/uapi/asoc.h

Something like this UNTESTED:

# configuration time
configure_file ( /usr/include/alsa/sound/uapi/asoc.h ${CMAKE_CURRENT_BINARY_DIR}/alsa/sound/uapi/asoc.h

# build  time
target_include_directories(sometarget ${CMAKE_CURRENT_BINARY_DIR})

https://www.google.com/search?q=cmake+generated+header

PS: I ran pkg-config --cflags-only-I alsa and made sure it's empty on Ubuntu, Fedora and Arch Linux. In other words the location is standard.

@lgirdwood
Copy link
Member

PS: I ran pkg-config --cflags-only-I alsa and made sure it's empty on Ubuntu, Fedora and Arch Linux. In other words the location is standard.

Thanks for checking @marc-hb - @singalsu I would make sure the comment about running pkg-config --cflags-only-I alsa is next to where you define the location. That way easy to check and update.

@singalsu singalsu force-pushed the testbench_avoid_linux_kernel_headers branch from 88b596f to 9fb2197 Compare March 16, 2023 14:43
@singalsu singalsu requested review from lgirdwood and marc-hb March 16, 2023 14:45
@singalsu
Copy link
Collaborator Author

@lgirdwood @marc-hb I tried to add pkg-config to build. Is this how you wanted it to be?

@marc-hb
Copy link
Collaborator

marc-hb commented Mar 16, 2023

No this is very far from what I suggested, sorry for the confusion.

- I mentioned pkg-config --cflags-only-I alsa only to demonstrate it was always empty hence NOT needed. To test your latest CMake code invoking pkg-config you would need to find a really weird Linux distribution where it is not empty (hence required), I really doubt you found any such distro? So your latest CMake code is not tested and most likely does not work :-) Also, if we ever wanted to use pkg-config (I think we do not) then it should not be invoked from CMake directly, there's a CMake API for that: https://cmake.org/cmake/help/latest/module/FindPkgConfig.html

- There are 3 different asoc.h files in /usr/include/ + maybe others installed manually so I think we should NOT #include <asoc.h> because no one wants to debug the order of -I include flags in very long and usually hidden command lines generated by 2 or 3 layers of build system indirections - multiplied by the number of supported toolchains. Top up that mess with whatever "creative" modifications developers have done to their system; like installing custom ALSA versions in random locations. So I think we should keep #include <alsa/sound/asoc.h>. It is what a non-empty pkg-config would require anyway. To make #include <alsa/sound/asoc.h> work with XCC, simply copy the hardcoded /usr/include/alsa/sound/asoc.h to some ${CMAKE_BINARY_DIR}/alsa/sound/ directory and add ${CMAKE_BINARY_DIR} to target_include_directories( [ SYSTEM ] ). See above.

@marc-hb
Copy link
Collaborator

marc-hb commented Mar 16, 2023

simply copy the hardcoded /usr/include/alsa/sound/asoc.h to some ${CMAKE_BINARY_DIR}/alsa/sound/ directory and add the latter to target_include_directories()

This is actually the example given in https://cmake.org/cmake/help/latest/command/configure_file.html !

Two differences:

@singalsu
Copy link
Collaborator Author

singalsu commented Mar 16, 2023

I tried to manually set the path that pkg-config to /foo and checked that the build tried to find headers from /foo/alsa/sound/uapi

No this is very far from what I suggested, sorry for the confusion.

  • I mentioned pkg-config --cflags-only-I alsa only to demonstrate it was always empty hence NOT needed. To test your latest CMake code invoking pkg-config you would need to find a really weird Linux distribution where it is not empty (hence required), I really doubt you found any such distro?

I could test it only by setting other_alsa_include_path to /foo and check that code build failed with -I/foo/alsa/sound/uapi seen in the command line. But not a real test, agree.

So your latest CMake code is not tested and most likely does not work :-) Also, if we ever wanted to use pkg-config (I think we do not) then it should not be invoked from CMake directly, there's a CMake API for that: https://cmake.org/cmake/help/latest/module/FindPkgConfig.html

OK, I'll learn about that

  • There are 3 different asoc.h files in /usr/include/ + maybe others installed manually so I think we should NOT #include <asoc.h> because no one wants to debug the order of -I include flags in very long and usually hidden command lines generated by 2 or 3 layers of build system indirections - multiplied by the number of supported toolchains. Top up that mess with whatever "creative" modifications developers have done to their system; like installing custom ALSA versions in random locations. So I think we should keep #include <alsa/sound/asoc.h>. It is what a non-empty pkg-config would require anyway. To make #include <alsa/sound/asoc.h> work with XCC, simply copy the hardcoded /usr/include/alsa/sound/asoc.h to some ${CMAKE_BINARY_DIR}/alsa/sound/ directory and add the ${CMAKE_BINARY_DIR} to target_include_directories(). See above and below.

Yep, will try :)

@marc-hb
Copy link
Collaborator

marc-hb commented Mar 16, 2023

copy the hardcoded /usr/include/alsa/sound/asoc.h to some ${CMAKE_BINARY_DIR}/alsa/sound/ directory and add ${CMAKE_BINARY_DIR} to target_include_directories( ). See above and below.

I just realized you may need the SYSTEM keyword in target_include_directories( ... SYSTEM ... ) because we have #include <alsa/sound/asoc.h> with < >.

Unless we switch to #include "alsa/sound/asoc.h"? Hopefully not, this would affect the regular host toolchain.

I'm not sure. However I'm sure that we would have EVEN MORE problems like this if we switch to #include "asoc.h" :-)

@singalsu singalsu force-pushed the testbench_avoid_linux_kernel_headers branch from 9fb2197 to a14774e Compare March 17, 2023 11:09
@singalsu
Copy link
Collaborator Author

I just realized you may need the SYSTEM keyword in target_include_directories( ... SYSTEM ... ) because we have #include <alsa/sound/asoc.h> with < >.

I tried to replace PRIVATE with SYSTEM. The cmake errors with that. Changing to SYSTEM PRIVATE works. But I have no idea what I'm doing. Is this better?

@singalsu singalsu force-pushed the testbench_avoid_linux_kernel_headers branch from a14774e to f204d33 Compare March 17, 2023 11:22
This patch adds simplified linux/types.h into testbench headers
to enable include of ALSA asoc.h to build without other difficult
kernel headers content.

The CMakeLists.txt files are updated to make a build time copy of
asoc.h to subdirectory include of the build directories. The new
directory is added to headers path.

This change avoids build fail with xcc toolchain that can't use the
gcc toolchain headers from the system where the ALSA headers are
located.

Suggested-by: Marc Herbert <[email protected]>
Signed-off-by: Seppo Ingalsuo <[email protected]>
@singalsu singalsu force-pushed the testbench_avoid_linux_kernel_headers branch from f204d33 to ef99cc8 Compare March 17, 2023 17:45
@marc-hb marc-hb requested a review from ranj063 March 17, 2023 20:06
@marc-hb
Copy link
Collaborator

marc-hb commented Mar 20, 2023

Only suspend/resume and PM failures in MTL https://sof-ci.01.org/sofpr/PR7244/build4801/devicetest

Everything else green including all cavs2.5 https://sof-ci.01.org/sofpr/PR7244/build4802/devicetest

@kv2019i kv2019i merged commit e0d8078 into thesofproject:main Mar 20, 2023
@singalsu singalsu deleted the testbench_avoid_linux_kernel_headers branch May 9, 2023 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants