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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions boards/native/common/natsim_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ get_property(CCACHE GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
target_link_options(native_simulator INTERFACE
"-T ${ZEPHYR_BASE}/boards/native/common/natsim_linker_script.ld")

if(SYSROOT_DIR)
message(NOTICE "Appending --sysroot=${SYSROOT_DIR} to native_simulator")
target_compile_options(native_simulator INTERFACE "--sysroot=${SYSROOT_DIR}")
target_link_options(native_simulator INTERFACE "--sysroot=${SYSROOT_DIR}")
endif()

set(nsi_config_content
${nsi_config_content}
"NSI_AR:=${CMAKE_AR}"
"NSI_BUILD_OPTIONS:=$<JOIN:$<TARGET_PROPERTY:native_simulator,INTERFACE_COMPILE_OPTIONS>,\ >"
"NSI_BUILD_PATH:=${zephyr_build_path}/NSI"
"NSI_CC:=${CCACHE} ${CMAKE_C_COMPILER}"
Expand Down
9 changes: 8 additions & 1 deletion cmake/compiler/clang/target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ endif()
find_program(CMAKE_C_COMPILER clang ${find_program_clang_args})
find_program(CMAKE_CXX_COMPILER clang++ ${find_program_clang_args})

if(SYSROOT_DIR)
# The toolchain has specified a sysroot dir, pass it to the compiler
list(APPEND TOOLCHAIN_C_FLAGS "--sysroot=${SYSROOT_DIR}")
list(APPEND TOOLCHAIN_LD_FLAGS "--sysroot=${SYSROOT_DIR}")
endif()

if(NOT "${ARCH}" STREQUAL "posix")
include(${ZEPHYR_BASE}/cmake/gcc-m-cpu.cmake)
include(${ZEPHYR_BASE}/cmake/gcc-m-fpu.cmake)
Expand Down Expand Up @@ -72,7 +78,8 @@ if(NOT "${ARCH}" STREQUAL "posix")
#
# Other clang/LLVM distributions may come with other pre-built C libraries.
# clang/LLVM supports using an alternative C library, either by direct linking,
# or by specifying '--sysroot <path>'.
# or by specifying '--sysroot <path>'. Sysroot can also be passed using the
# CMake variable SYSROOT_DIR which will append the '--sysroot <path>' flags.
#
# LLVM for Arm provides a 'newlib.cfg' file for newlib C selection.
# Let us support this principle by looking for a dedicated 'newlib.cfg' or
Expand Down