Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yperess
Copy link
Collaborator

@yperess yperess commented May 22, 2025

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.

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]>
Copy link

Comment on lines +1993 to +1998
foreach(flag IN LISTS TOOLCHAIN_C_FLAGS_LIST)
if (flag MATCHES "^--sysroot=.*")
set(NSI_SYSROOT_FLAG "${flag}")
break()
endif()
endforeach()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fix indentation

Suggested change
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()

Comment on lines +2006 to +2007
NSI_BUILD_C_OPTIONS="${NSI_SYSROOT_FLAG}" NSI_AR="${CMAKE_AR}"
NSI_EXTRA_LINK_OPTIONS="${NSI_SYSROOT_FLAG}"
Copy link
Collaborator

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

Suggested change
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}"
Copy link
Member

@aescolar aescolar May 23, 2025

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
Copy link
Member

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)

Copy link
Collaborator Author

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

@aescolar aescolar assigned aescolar and unassigned tejlmand May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Build System area: native port Host native arch port (native_sim)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants