-
Notifications
You must be signed in to change notification settings - Fork 7.4k
build: Allow custom sysroot in native_sim builds #90357
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
base: main
Are you sure you want to change the base?
build: Allow custom sysroot in native_sim builds #90357
Conversation
When running naive sim builds, any custom cflags and toolchains we've set are lost. Specifically for us this included a custom directory for the sysroot and archive tool. Add the sysroot (if available) to both NSI_BUILD_C_OPTIONS and a new NSI_EXTRA_LINK_OPTIONS. Additionally pass CMAKE_AR to NSI_AR. Signed-off-by: Yuval Peress <[email protected]>
|
foreach(flag IN LISTS TOOLCHAIN_C_FLAGS_LIST) | ||
if (flag MATCHES "^--sysroot=.*") | ||
set(NSI_SYSROOT_FLAG "${flag}") | ||
break() | ||
endif() | ||
endforeach() |
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.
Fix indentation
foreach(flag IN LISTS TOOLCHAIN_C_FLAGS_LIST) | |
if (flag MATCHES "^--sysroot=.*") | |
set(NSI_SYSROOT_FLAG "${flag}") | |
break() | |
endif() | |
endforeach() | |
foreach(flag IN LISTS TOOLCHAIN_C_FLAGS_LIST) | |
if (flag MATCHES "^--sysroot=.*") | |
set(NSI_SYSROOT_FLAG "${flag}") | |
break() | |
endif() | |
endforeach() |
NSI_BUILD_C_OPTIONS="${NSI_SYSROOT_FLAG}" NSI_AR="${CMAKE_AR}" | ||
NSI_EXTRA_LINK_OPTIONS="${NSI_SYSROOT_FLAG}" |
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.
Use spaces instead of tabs
NSI_BUILD_C_OPTIONS="${NSI_SYSROOT_FLAG}" NSI_AR="${CMAKE_AR}" | |
NSI_EXTRA_LINK_OPTIONS="${NSI_SYSROOT_FLAG}" | |
NSI_BUILD_C_OPTIONS="${NSI_SYSROOT_FLAG}" NSI_AR="${CMAKE_AR}" | |
NSI_EXTRA_LINK_OPTIONS="${NSI_SYSROOT_FLAG}" |
add_custom_target(native_runner_executable | ||
ALL | ||
COMMENT "Building native simulator runner, and linking final executable" | ||
COMMAND | ||
${MAKE} -f ${ZEPHYR_BASE}/scripts/native_simulator/Makefile all --warn-undefined-variables | ||
-r NSI_CONFIG_FILE=${APPLICATION_BINARY_DIR}/zephyr/NSI/nsi_config | ||
NSI_BUILD_C_OPTIONS="${NSI_SYSROOT_FLAG}" NSI_AR="${CMAKE_AR}" |
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.
We set the native simulator configuration in
https://github.com/zephyrproject-rtos/zephyr/blob/main/boards/native/common/natsim_config.cmake#L15
That's where we'd want to set more options like NSI_AR
# By default we have no NSI build C options | ||
set(NSI_SYSROOT_FLAG "") | ||
|
||
# Check for custom --sysroot flags |
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 you want to set a different sysroot for the compiler and linker of the native_simulator runner, wouldn't calling directly
target_compile_options(native_simulator INTERFACE "--sysroot=blabla")
target_link_options(native_simulator INTERFACE "--sysroot=blabla")
from your own cmake file do the trick?
(I would think it is not given that somebody wanting to build the embedded/zephyr side with one sysroot will want to build the native simulator runner with the same one)
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.
The goal here is to run this through our CI when we uprev Zephyr. So we want to pass things like -xTOOLCHAIN_C_FLAGS_LIST=--sysroot=path/to/sysroot
and be able to use it across the board for all the test run by twister. Some of these we don't have access to the CMake file
When running naive sim builds, any custom cflags and toolchains we've set are lost. Specifically for us this included a custom directory for the sysroot and archive tool.
Add the sysroot (if available) to both NSI_BUILD_C_OPTIONS and a new NSI_EXTRA_LINK_OPTIONS. Additionally pass CMAKE_AR to NSI_AR.