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

Revert breaking change to CMAKE_SYSTEM_NAME and unnecessary introduction of cmake/modules/Platform/Zephyr.cmake #71468

Merged
merged 1 commit into from
Apr 29, 2024

Conversation

nlebedenco
Copy link
Contributor

This PR reverts a breaking change in CMAKE_SYSTEM_NAME introduced by #67997 (changing it from "Zephyr" back to "Generic") and removes the file
cmake/modules/Platform/Zephyr.

Both changes in the aforementioned PR were only introduced to ultimately modify the value of the global CMake property TARGET_SUPPORTS_SHARED_LIBS for the special case of building for Xtensa with LLEXT.

The modification of CMAKE_SYSTEM_NAME is considered a breaking change because it has the potential to alter the build of any non-trivial project that previously checked for the "Generic" system identifier as corresponding to Zephyr - for example by doing if (CMAKE_SYSTEM_NAME STREQUAL "Generic"). Such builds may now break in many ways including silently when there is no else clause with a message(FATAL_ERROR) or message(WARNING) to alert the user that a whole
configuration block had been skipped.

In essence, that CMAKE_SYSTEM_NAME modification was only introduced in order to have CMake to load cmake/modules/Platform/Zephyr.cmake which in turn adjusted the value of TARGET_SUPPORTS_SHARED_LIBS.

But the use of a CMake platform file is ineffective for non-trivial projects where one or more top level CMake projects may be defined before the first call to find_package(Zephyr) because in such cases CMAKE_MODULE_PATH will not have been modified yet to contain the path to <Zephyr_ROOT>/cmake/modules.

This patch moves the conditional override of TARGET_SUPPORTS_SHARED_LIBS into the kernel.cmake module which is known to be the first call to project() that enables any language and thus the one that must come
before any artifact target can be defined.

This is the command line one would use prior to #67997 (or with the
patched branch) followed by its respective output:

(.venv) C:\Dev\SomeTopLevelProject>cmake -B .build -G Ninja -DCMAKE_SYSTEM_NAME=Generic -DBOARD=nucleo_u575zi_q
Loading Zephyr default modules (Zephyr base).
-- Application: C:/Dev/SomeTopLevelProject/my_zephyr_app
-- CMake version: 3.27.9
-- Found Python3: C:/Dev/SomeTopLevelProject/.venv/Scripts/python.exe (found suitable version "3.11.6", minimum required is "3.8") found components: Interpreter
-- Cache files will be written to: C:/Dev/zephyr/.cache
-- Zephyr version: 3.6.99 (C:/Dev/zephyr)
-- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
-- Board: nucleo_u575zi_q, qualifiers: stm32u575xx
-- Found host-tools: zephyr 0.16.5 (C:/Portable/Zephyr/zephyr-sdk-0.16.5)
-- Found toolchain: zephyr 0.16.5 (C:/Portable/Zephyr/zephyr-sdk-0.16.5)
-- Found Dtc: C:/ProgramData/chocolatey/bin/dtc.exe (found suitable version "1.5.0", minimum required is "1.4.6")
-- Found BOARD.dts: C:/Dev/zephyr/boards/st/nucleo_u575zi_q/nucleo_u575zi_q.dts
-- Generated zephyr.dts: C:/Dev/SomeTopLevelProject/.build/my_zephyr_app/zephyr/zephyr.dts
-- Generated devicetree_generated.h: C:/Dev/SomeTopLevelProject/.build/my_zephyr_app/zephyr/include/generated/devicetree_generated.h
-- Including generated dts.cmake file: C:/Dev/SomeTopLevelProject/.build/my_zephyr_app/zephyr/dts.cmake
Parsing C:/Dev/SomeTopLevelProject/my_zephyr_app/Kconfig
Loaded configuration 'C:/Dev/zephyr/boards/st/nucleo_u575zi_q/nucleo_u575zi_q_defconfig'
Merged configuration 'C:/Dev/SomeTopLevelProject/my_zephyr_app/prj.conf'
Configuration saved to 'C:/Dev/SomeTopLevelProject/.build/my_zephyr_app/zephyr/.config'
Kconfig header saved to 'C:/Dev/SomeTopLevelProject/.build/my_zephyr_app/zephyr/include/generated/autoconf.h'
-- Found GnuLd: c:/portable/zephyr/zephyr-sdk-0.16.5/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe (found version "2.38")
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- The ASM compiler identification is GNU
-- Found assembler: C:/Portable/Zephyr/zephyr-sdk-0.16.5/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
-- Configuring done (31.7s)
-- Generating done (0.8s)
-- Build files have been written to: C:/Dev/SomeTopLevelProject/.build

This is the command line one would use with the current main followed by its respective output:

(.venv) C:\Dev\SomeTopLevelProject>cmake -B .build -G Ninja -DCMAKE_SYSTEM_NAME=Zephyr -DBOARD=nucleo_u575zi_q
System is unknown to cmake, create:
Platform/Zephyr to use this system, please post your config file on discourse.cmake.org so it can be added to cmake
-- CMAKE_SYSTEM_NAME="Zephyr"
Loading Zephyr default modules (Zephyr base).
-- Application: C:/Dev/SomeTopLevelProject/my_zephyr_app
-- CMake version: 3.27.9
-- Found Python3: C:/Dev/SomeTopLevelProject/.venv/Scripts/python.exe (found suitable version "3.11.6", minimum required is "3.8") found components: Interpreter
-- Cache files will be written to: C:/Dev/zephyr/.cache
-- Zephyr version: 3.6.99 (C:/Dev/zephyr)
-- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
-- Board: nucleo_u575zi_q, qualifiers: stm32u575xx
-- Found host-tools: zephyr 0.16.5 (C:/Portable/Zephyr/zephyr-sdk-0.16.5)
-- Found toolchain: zephyr 0.16.5 (C:/Portable/Zephyr/zephyr-sdk-0.16.5)
-- Found Dtc: C:/ProgramData/chocolatey/bin/dtc.exe (found suitable version "1.5.0", minimum required is "1.4.6")
-- Found BOARD.dts: C:/Dev/zephyr/boards/st/nucleo_u575zi_q/nucleo_u575zi_q.dts
-- Generated zephyr.dts: C:/Dev/SomeTopLevelProject/.build/my_zephyr_app/zephyr/zephyr.dts
-- Generated devicetree_generated.h: C:/Dev/SomeTopLevelProject/.build/my_zephyr_app/zephyr/include/generated/devicetree_generated.h
-- Including generated dts.cmake file: C:/Dev/SomeTopLevelProject/.build/my_zephyr_app/zephyr/dts.cmake
Parsing C:/Dev/SomeTopLevelProject/my_zephyr_app/Kconfig
Loaded configuration 'C:/Dev/zephyr/boards/st/nucleo_u575zi_q/nucleo_u575zi_q_defconfig'
Merged configuration 'C:/Dev/SomeTopLevelProject/my_zephyr_app/prj.conf'
Configuration saved to 'C:/Dev/SomeTopLevelProject/.build/my_zephyr_app/zephyr/.config'
Kconfig header saved to 'C:/Dev/SomeTopLevelProject/.build/my_zephyr_app/zephyr/include/generated/autoconf.h'
-- Found GnuLd: c:/portable/zephyr/zephyr-sdk-0.16.5/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe (found version "2.38")
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- The ASM compiler identification is GNU
-- Found assembler: C:/Portable/Zephyr/zephyr-sdk-0.16.5/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
-- Configuring done (31.5s)
-- Generating done (0.8s)
-- Build files have been written to: C:/Dev/SomeTopLevelProject/.build

Note how CMake is complaining that a platform cmake module could not be found for the target system. In fact, the file
<Zephyr_ROOT>/cmake/modules/Platform/Zephyr.cmake is never included. The configuration seems to succeed but
the stock Generic.cmake shipped with CMake was not included either.

Note that omiting -DCMAKE_SYSTEM_NAME=Zephyr is not an option because without it CMake will set CMAKE_SYSTEM_NAME to
the value of CMAKE_HOST_SYSTEM_NAME resulting in this:

(.venv) C:\Dev\SomeTopLevelProject>cmake -B .build -G Ninja -DBOARD=nucleo_u575zi_q
-- CMAKE_SYSTEM_NAME="Windows"
Loading Zephyr default modules (Zephyr base).
-- Application: C:/Dev/SomeTopLevelProject/my_zephyr_app
-- CMake version: 3.27.9
-- Found Python3: C:/Dev/SomeTopLevelProject/.venv/Scripts/python.exe (found suitable version "3.11.6", minimum required is "3.8") found components: Interpreter
-- Cache files will be written to: C:/Dev/zephyr/.cache
-- Zephyr version: 3.6.99 (C:/Dev/zephyr)
-- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
-- Board: nucleo_u575zi_q, qualifiers: stm32u575xx
-- Found host-tools: zephyr 0.16.5 (C:/Portable/Zephyr/zephyr-sdk-0.16.5)
-- Found toolchain: zephyr 0.16.5 (C:/Portable/Zephyr/zephyr-sdk-0.16.5)
-- Found Dtc: C:/ProgramData/chocolatey/bin/dtc.exe (found suitable version "1.5.0", minimum required is "1.4.6")
-- Found BOARD.dts: C:/Dev/zephyr/boards/st/nucleo_u575zi_q/nucleo_u575zi_q.dts
-- Generated zephyr.dts: C:/Dev/SomeTopLevelProject/.build/my_zephyr_app/zephyr/zephyr.dts
-- Generated devicetree_generated.h: C:/Dev/SomeTopLevelProject/.build/my_zephyr_app/zephyr/include/generated/devicetree_generated.h
-- Including generated dts.cmake file: C:/Dev/SomeTopLevelProject/.build/my_zephyr_app/zephyr/dts.cmake
Parsing C:/Dev/SomeTopLevelProject/my_zephyr_app/Kconfig
Loaded configuration 'C:/Dev/zephyr/boards/st/nucleo_u575zi_q/nucleo_u575zi_q_defconfig'
Merged configuration 'C:/Dev/SomeTopLevelProject/my_zephyr_app/prj.conf'
Configuration saved to 'C:/Dev/SomeTopLevelProject/.build/my_zephyr_app/zephyr/.config'
Kconfig header saved to 'C:/Dev/SomeTopLevelProject/.build/my_zephyr_app/zephyr/include/generated/autoconf.h'
-- Found GnuLd: c:/portable/zephyr/zephyr-sdk-0.16.5/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe (found version "2.38")
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- The ASM compiler identification is GNU
-- Found assembler: C:/Portable/Zephyr/zephyr-sdk-0.16.5/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc.exe
-- Configuring done (301.7s)
-- Generating done (0.8s)
-- Build files have been written to: C:/Dev/SomeTopLevelProject/.build

Again <Zephyr_ROOT>/cmake/modules/Platform/Zephyr.cmake is never included. This can be verified by temporarily adding
message(STATUS "Included ${CMAKE_CURRENT_LIST_FILE}") at the top of the file. The configuration seems to succeed but
the stock Generic.cmake shipped with CMake was not included either. Instead it was Windows.cmake that was included.

Here is the example project that I used to produce the output listed.
SomeTopLevelProject.zip

Copy link
Collaborator

@nordicjm nordicjm left a comment

Choose a reason for hiding this comment

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

For reverts do git revert <commit> then update the commit message but keep the revert line present

@nlebedenco
Copy link
Contributor Author

@nordicjm This is not reverting the whole of #67997 as that PR had 4 separate commits. It is in effect reverting c2b6016 but also providing an alternative place for the adjustment of TARGET_SUPPORTS_SHARED_LIBS which is still necessary for Xtensa support. The intention is not to undo #67997 but fix a breaking change it unnecessarily introduced.

Copy link
Collaborator

@pillo79 pillo79 left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this! There had to be some caveat with introducing a new platform, but I was not able to find any issue with the many basic setups I tried.

Love to +1 this PR with only a minor change below.

Comment on lines 171 to 172
# Enable dynamic library support required by CONFIG_XTENSA for CONFIG_LLEXT support.
if(CONFIG_XTENSA AND CONFIG_LLEXT)
Copy link
Collaborator

Choose a reason for hiding this comment

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

64e7d85 added a Kconfig to specify the object type for the llext being built, so it's not tied to the arch anymore.
Thus, I believe this should now be:

Suggested change
# Enable dynamic library support required by CONFIG_XTENSA for CONFIG_LLEXT support.
if(CONFIG_XTENSA AND CONFIG_LLEXT)
# Enable dynamic library support when required by LLEXT.
if(CONFIG_LLEXT AND CONFIG_LLEXT_TYPE_SHAREDLIB)

Copy link
Contributor Author

@nlebedenco nlebedenco Apr 25, 2024

Choose a reason for hiding this comment

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

Thx @pillo79
I amended the branch to include your suggestion.

Copy link
Contributor Author

@nlebedenco nlebedenco Apr 25, 2024

Choose a reason for hiding this comment

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

Only thing is there is now a compliance check failing due to CONFIG_LLEXT_TYPE_SHAREDLIB. So I'm confused.
EDIT: My bad. I had not done a proper rebase onto main. That should be good now.
EDIT2: ha now I see the actual option name is CONFIG_LLEXT_TYPE_ELF_SHAREDLIB. Fixed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry for the misdirection - in fact it's CONFIG_LLEXT_TYPE_ELF_SHAREDLIB, my bad! 😉

@nlebedenco nlebedenco force-pushed the patch-4 branch 2 times, most recently from 74e6bb8 to be6b51e Compare April 25, 2024 12:40
This commit reverts a breaking change in CMAKE_SYSTEM_NAME introduced by
"Zephyr" back to "Generic") and removes the file
`cmake/modules/Platform/Zephyr`.

Both changes in the aforementioned PR were only introduced to ultimately
modify the value of the global CMake property TARGET_SUPPORTS_SHARED_LIBS
for the special case of building for Xtensa with LLEXT.

The modification of CMAKE_SYSTEM_NAME is considered a breaking change
because it has the potential to alter the build of any non-trivial project
that previously checked for the "Generic" system identifier as
corresponding to Zephyr - for example by doing
`if (CMAKE_SYSTEM_NAME STREQUAL "Generic")`. Such builds may now break in
many ways including silently when there is no `else()` clause with a
`message()` to alert the user that a whole configuration block had been
skipped.

In essence, that CMAKE_SYSTEM_NAME modification was only introduced in
order to have CMake to load `cmake/modules/Platform/Zephyr.cmake` which in
turn adjusted the value of TARGET_SUPPORTS_SHARED_LIBS.

But the use of a CMake platform file like this is ineffective for
non-trivial projects where one or more top level CMake `project()` calls
may happen before the first call to `find_package(Zephyr)` because in such
cases CMAKE_MODULE_PATH will not have been modified yet to contain the
path to <Zephyr_ROOT>/cmake/modules and thus no platform file will be
include by CMake.

This patch moves the conditional override of TARGET_SUPPORTS_SHARED_LIBS
needed by some archs (e.g. Xtensa) into the `kernel.cmake` module which
is known to be the first call to `project()` that enables any language and
thus the one that must come before any artifact target can be defined.

Note commit 64e7d85 added a Kconfig to specify the object type of llext
being built, so it's not tied to the arch anymore but to the
CONFIG_LLEXT_TYPE_ELF_SHAREDLIB option.

Signed-off-by: Nicolas Lebedenco <nicolas@lebedenco.net>
Copy link
Collaborator

@pillo79 pillo79 left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

@pillo79 pillo79 requested a review from teburd April 26, 2024 14:23
@nordicjm nordicjm dismissed their stale review April 29, 2024 06:13

Justified

@nlebedenco
Copy link
Contributor Author

Thank you all for the reviews.
Still need someone to merge this as I don't have the authorization and auto-merge is not kicking.

@carlescufi carlescufi merged commit 6837ca8 into zephyrproject-rtos:main Apr 29, 2024
21 checks passed
@nlebedenco nlebedenco deleted the patch-4 branch April 29, 2024 15:27
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.

8 participants