Skip to content

Commit

Permalink
build: namespace the generated headers with zephyr/
Browse files Browse the repository at this point in the history
Namespaced the generated headers with `zephyr` to prevent
potential conflict with other headers.

Introduce a temporary Kconfig `LEGACY_GENERATED_INCLUDE_PATH`
that is enabled by default. This allows the developers to
continue the use of the old include paths for the time being
until it is deprecated and eventually removed. The Kconfig will
generate a build-time warning message, similar to the
`CONFIG_TIMER_RANDOM_GENERATOR`.

Updated the includes path of in-tree sources accordingly.

Most of the changes here are scripted, check the PR for more
info.

Signed-off-by: Yong Cong Sin <[email protected]>
  • Loading branch information
ycsin authored and henrikbrixandersen committed May 28, 2024
1 parent d034106 commit bbe5e1e
Show file tree
Hide file tree
Showing 294 changed files with 770 additions and 726 deletions.
58 changes: 40 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ add_library(zephyr_interface INTERFACE)
# flags that come with zephyr_interface.
zephyr_library_named(zephyr)

if(CONFIG_LEGACY_GENERATED_INCLUDE_PATH)
zephyr_include_directories(${PROJECT_BINARY_DIR}/include/generated/zephyr)
message(WARNING "
Warning: CONFIG_LEGACY_GENERATED_INCLUDE_PATH is currently enabled by default
so that user applications can continue to use the legacy include paths for the
generated headers. This Kconfig will be deprecated and eventually removed in
the future releases.")
endif()

zephyr_include_directories(
include
${PROJECT_BINARY_DIR}/include/generated
Expand Down Expand Up @@ -541,9 +550,9 @@ if(ZEPHYR_GIT_INDEX)
endif()

add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/include/generated/version.h
OUTPUT ${PROJECT_BINARY_DIR}/include/generated/zephyr/version.h
COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE}
-DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/version.h
-DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/zephyr/version.h
-DVERSION_TYPE=KERNEL
-DVERSION_FILE=${ZEPHYR_BASE}/VERSION
-DKERNEL_VERSION_CUSTOMIZATION="$<TARGET_PROPERTY:version_h,KERNEL_VERSION_CUSTOMIZATION>"
Expand All @@ -552,13 +561,13 @@ add_custom_command(
DEPENDS ${ZEPHYR_BASE}/VERSION ${git_dependency}
COMMAND_EXPAND_LISTS
)
add_custom_target(version_h DEPENDS ${PROJECT_BINARY_DIR}/include/generated/version.h)
add_custom_target(version_h DEPENDS ${PROJECT_BINARY_DIR}/include/generated/zephyr/version.h)

if(EXISTS ${APPLICATION_SOURCE_DIR}/VERSION)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/include/generated/app_version.h
OUTPUT ${PROJECT_BINARY_DIR}/include/generated/zephyr/app_version.h
COMMAND ${CMAKE_COMMAND} -DZEPHYR_BASE=${ZEPHYR_BASE}
-DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/app_version.h
-DOUT_FILE=${PROJECT_BINARY_DIR}/include/generated/zephyr/app_version.h
-DVERSION_TYPE=APP
-DVERSION_FILE=${APPLICATION_SOURCE_DIR}/VERSION
-DAPP_VERSION_CUSTOMIZATION="$<TARGET_PROPERTY:app_version_h,APP_VERSION_CUSTOMIZATION>"
Expand All @@ -567,7 +576,9 @@ if(EXISTS ${APPLICATION_SOURCE_DIR}/VERSION)
DEPENDS ${APPLICATION_SOURCE_DIR}/VERSION ${git_dependency}
COMMAND_EXPAND_LISTS
)
add_custom_target(app_version_h DEPENDS ${PROJECT_BINARY_DIR}/include/generated/app_version.h)
add_custom_target(
app_version_h
DEPENDS ${PROJECT_BINARY_DIR}/include/generated/zephyr/app_version.h)
add_dependencies(zephyr_interface app_version_h)
endif()

Expand Down Expand Up @@ -622,8 +633,8 @@ set(ZEPHYR_CURRENT_CMAKE_DIR)
get_property(LIBC_LINK_LIBRARIES TARGET zephyr_interface PROPERTY LIBC_LINK_LIBRARIES)
zephyr_link_libraries(${LIBC_LINK_LIBRARIES})

set(syscall_list_h ${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscall_list.h)
set(edk_syscall_list_h ${CMAKE_CURRENT_BINARY_DIR}/edk/include/generated/syscall_list.h)
set(syscall_list_h ${CMAKE_CURRENT_BINARY_DIR}/include/generated/zephyr/syscall_list.h)
set(edk_syscall_list_h ${CMAKE_CURRENT_BINARY_DIR}/edk/include/generated/zephyr/syscall_list.h)
set(syscalls_json ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/syscalls.json)
set(struct_tags_json ${CMAKE_CURRENT_BINARY_DIR}/misc/generated/struct_tags.json)

Expand Down Expand Up @@ -761,7 +772,7 @@ add_custom_target(${SYSCALL_LIST_H_TARGET} DEPENDS ${syscall_list_h} ${picolibc_
set_property(TARGET ${SYSCALL_LIST_H_TARGET}
APPEND PROPERTY
ADDITIONAL_CLEAN_FILES
${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscalls
${CMAKE_CURRENT_BINARY_DIR}/include/generated/zephyr/syscalls
)

add_custom_target(${PARSE_SYSCALLS_TARGET}
Expand All @@ -781,27 +792,38 @@ if(CONFIG_TIMEOUT_64BIT)
set(SYSCALL_SPLIT_TIMEOUT_ARG --split-type k_timeout_t --split-type k_ticks_t)
endif()

# percepio/TraceRecorder/kernelports/Zephyr/scripts/tz_parse_syscalls.py hardcodes the path
# to the `syscall_list.h`, make a copy of the generated file so that percepio is able to build
if(CONFIG_LEGACY_GENERATED_INCLUDE_PATH)
set(LEGACY_SYSCALL_LIST_H_ARGS
${CMAKE_COMMAND} -E copy
${syscall_list_h}
${CMAKE_CURRENT_BINARY_DIR}/include/generated/syscall_list.h)
endif()

add_custom_command(OUTPUT include/generated/syscall_dispatch.c ${syscall_list_h}
# Also, some files are written to include/generated/syscalls/
# Also, some files are written to include/generated/zephyr/syscalls/
COMMAND
${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/scripts/build/gen_syscalls.py
--json-file ${syscalls_json} # Read this file
--base-output include/generated/syscalls # Write to this dir
--base-output include/generated/zephyr/syscalls # Write to this dir
--syscall-dispatch include/generated/syscall_dispatch.c # Write this file
--syscall-export-llext include/generated/syscall_export_llext.c
--syscall-list ${syscall_list_h}
$<$<BOOL:${CONFIG_USERSPACE}>:--gen-mrsh-files>
${SYSCALL_LONG_REGISTERS_ARG}
${SYSCALL_SPLIT_TIMEOUT_ARG}
COMMAND
${LEGACY_SYSCALL_LIST_H_ARGS}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${PARSE_SYSCALLS_TARGET}
)

# This is passed into all calls to the gen_kobject_list.py script.
set(gen_kobject_list_include_args --include-subsystem-list ${struct_tags_json})

set(DRV_VALIDATION ${PROJECT_BINARY_DIR}/include/generated/driver-validation.h)
set(DRV_VALIDATION ${PROJECT_BINARY_DIR}/include/generated/zephyr/driver-validation.h)
add_custom_command(
OUTPUT ${DRV_VALIDATION}
COMMAND
Expand Down Expand Up @@ -834,7 +856,7 @@ add_dependencies(zephyr_generated_headers
set(OFFSETS_LIB offsets)

set(OFFSETS_C_PATH ${ARCH_DIR}/${ARCH}/core/offsets/offsets.c)
set(OFFSETS_H_PATH ${PROJECT_BINARY_DIR}/include/generated/offsets.h)
set(OFFSETS_H_PATH ${PROJECT_BINARY_DIR}/include/generated/zephyr/offsets.h)

add_library( ${OFFSETS_LIB} OBJECT ${OFFSETS_C_PATH})
target_include_directories(${OFFSETS_LIB} PRIVATE
Expand Down Expand Up @@ -1197,15 +1219,15 @@ if(CONFIG_USERSPACE)
PUBLIC $<TARGET_PROPERTY:zephyr_interface,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>
)

set(KOBJECT_LINKER_HEADER_DATA "${PROJECT_BINARY_DIR}/include/generated/linker-kobject-prebuilt-data.h")
set(KOBJECT_LINKER_HEADER_DATA "${PROJECT_BINARY_DIR}/include/generated/zephyr/linker-kobject-prebuilt-data.h")

add_custom_command(
OUTPUT ${KOBJECT_LINKER_HEADER_DATA}
COMMAND
${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/scripts/build/gen_kobject_placeholders.py
--object $<TARGET_OBJECTS:kobj_prebuilt_hash_output_lib>
--outdir ${PROJECT_BINARY_DIR}/include/generated
--outdir ${PROJECT_BINARY_DIR}/include/generated/zephyr
--datapct ${CONFIG_KOBJECT_DATA_AREA_RESERVE_EXTRA_PERCENT}
--rodata ${CONFIG_KOBJECT_RODATA_AREA_EXTRA_BYTES}
$<$<BOOL:${CMAKE_VERBOSE_MAKEFILE}>:--verbose>
Expand Down Expand Up @@ -1962,7 +1984,7 @@ if(LOG_DICT_DB_NAME_ARG)
${ZEPHYR_BASE}/scripts/logging/dictionary/database_gen.py
${KERNEL_ELF_NAME}
${LOG_DICT_DB_NAME_ARG}=${LOG_DICT_DB_NAME}
--build-header ${PROJECT_BINARY_DIR}/include/generated/version.h
--build-header ${PROJECT_BINARY_DIR}/include/generated/zephyr/version.h
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMENT "Generating logging dictionary database: ${LOG_DICT_DB_NAME}"
DEPENDS ${logical_target_for_zephyr_elf}
Expand Down Expand Up @@ -2093,12 +2115,12 @@ add_custom_command(
OUTPUT ${llext_edk_file}
# Regenerate syscalls in case CONFIG_LLEXT_EDK_USERSPACE_ONLY
COMMAND ${CMAKE_COMMAND}
-E make_directory edk/include/generated
-E make_directory edk/include/generated/zephyr
COMMAND
${PYTHON_EXECUTABLE}
${ZEPHYR_BASE}/scripts/build/gen_syscalls.py
--json-file ${syscalls_json} # Read this file
--base-output edk/include/generated/syscalls # Write to this dir
--base-output edk/include/generated/zephyr/syscalls # Write to this dir
--syscall-dispatch edk/include/generated/syscall_dispatch.c # Write this file
--syscall-list ${edk_syscall_list_h}
$<$<BOOL:${CONFIG_LLEXT_EDK_USERSPACE_ONLY}>:--userspace-only>
Expand Down
17 changes: 17 additions & 0 deletions Kconfig.zephyr
Original file line number Diff line number Diff line change
Expand Up @@ -1048,3 +1048,20 @@ config BOOTLOADER_BOSSA_ADAFRUIT_UF2
endchoice

endmenu

menu "Compatibility"

config LEGACY_GENERATED_INCLUDE_PATH
bool "Legacy include path for generated headers"
default y
help
Allow applications and libraries to use the Zephyr legacy include
path for the generated headers which does not use the `zephyr/` prefix.

From now on, i.e., the preferred way to include the `version.h` header is to
use <zephyr/version.h>, this Kconfig is currently enabled by default so that
user applications won't immediately fail to compile.

This Kconfig will be deprecated and eventually removed in the future releases.

endmenu
2 changes: 1 addition & 1 deletion arch/arc/include/offsets_short_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef ZEPHYR_ARCH_ARC_INCLUDE_OFFSETS_SHORT_ARCH_H_
#define ZEPHYR_ARCH_ARC_INCLUDE_OFFSETS_SHORT_ARCH_H_

#include <offsets.h>
#include <zephyr/offsets.h>

/* kernel */

Expand Down
2 changes: 1 addition & 1 deletion arch/arm/include/offsets_short_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef ZEPHYR_ARCH_ARM_INCLUDE_OFFSETS_SHORT_ARCH_H_
#define ZEPHYR_ARCH_ARM_INCLUDE_OFFSETS_SHORT_ARCH_H_

#include <offsets.h>
#include <zephyr/offsets.h>

/* kernel */

Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/core/reset.S
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <zephyr/toolchain.h>
#include <zephyr/linker/sections.h>
#include <zephyr/arch/cpu.h>
#include <offsets.h>
#include <zephyr/offsets.h>
#include "boot.h"
#include "macro_priv.inc"

Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/core/vector_table.S
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <zephyr/toolchain.h>
#include <zephyr/linker/sections.h>
#include <offsets.h>
#include <zephyr/offsets.h>
#include <zephyr/arch/cpu.h>
#include <zephyr/arch/arm64/tpidrro_el0.h>
#include <offsets_short.h>
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/include/offsets_short_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef ZEPHYR_ARCH_ARM64_INCLUDE_OFFSETS_SHORT_ARCH_H_
#define ZEPHYR_ARCH_ARM64_INCLUDE_OFFSETS_SHORT_ARCH_H_

#include <offsets.h>
#include <zephyr/offsets.h>

#define _thread_offset_to_exception_depth \
(___thread_t_arch_OFFSET + ___thread_arch_t_exception_depth_OFFSET)
Expand Down
2 changes: 1 addition & 1 deletion arch/mips/include/offsets_short_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef ZEPHYR_ARCH_MIPS_INCLUDE_OFFSETS_SHORT_ARCH_H_
#define ZEPHYR_ARCH_MIPS_INCLUDE_OFFSETS_SHORT_ARCH_H_

#include <offsets.h>
#include <zephyr/offsets.h>

#define _thread_offset_to_sp \
(___thread_t_callee_saved_OFFSET + ___callee_saved_t_sp_OFFSET)
Expand Down
2 changes: 1 addition & 1 deletion arch/nios2/include/offsets_short_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef ZEPHYR_ARCH_NIOS2_INCLUDE_OFFSETS_SHORT_ARCH_H_
#define ZEPHYR_ARCH_NIOS2_INCLUDE_OFFSETS_SHORT_ARCH_H_

#include <offsets.h>
#include <zephyr/offsets.h>

/* kernel */

Expand Down
2 changes: 1 addition & 1 deletion arch/posix/include/offsets_short_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef ZEPHYR_ARCH_POSIX_INCLUDE_OFFSETS_SHORT_ARCH_H_
#define ZEPHYR_ARCH_POSIX_INCLUDE_OFFSETS_SHORT_ARCH_H_

#include <offsets.h>
#include <zephyr/offsets.h>

/* kernel */

Expand Down
2 changes: 1 addition & 1 deletion arch/riscv/core/fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,6 @@ static void z_vrfy_user_fault(unsigned int reason)
z_impl_user_fault(reason);
}

#include <syscalls/user_fault_mrsh.c>
#include <zephyr/syscalls/user_fault_mrsh.c>

#endif /* CONFIG_USERSPACE */
2 changes: 1 addition & 1 deletion arch/riscv/core/fpu.S
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <zephyr/toolchain.h>
#include <zephyr/linker/sections.h>
#include <offsets.h>
#include <zephyr/offsets.h>

#ifdef CONFIG_CPU_HAS_FPU_DOUBLE_PRECISION
#define LOAD fld
Expand Down
2 changes: 1 addition & 1 deletion arch/riscv/core/reset.S
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <zephyr/toolchain.h>
#include <zephyr/linker/sections.h>
#include <zephyr/arch/cpu.h>
#include <offsets.h>
#include <zephyr/offsets.h>
#include "asm_macros.inc"

/* exports */
Expand Down
2 changes: 1 addition & 1 deletion arch/riscv/include/offsets_short_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef ZEPHYR_ARCH_RISCV_INCLUDE_OFFSETS_SHORT_ARCH_H_
#define ZEPHYR_ARCH_RISCV_INCLUDE_OFFSETS_SHORT_ARCH_H_

#include <offsets.h>
#include <zephyr/offsets.h>

#define _thread_offset_to_sp \
(___thread_t_callee_saved_OFFSET + ___callee_saved_t_sp_OFFSET)
Expand Down
2 changes: 1 addition & 1 deletion arch/sparc/include/offsets_short_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef ZEPHYR_ARCH_SPARC_INCLUDE_OFFSETS_SHORT_ARCH_H_
#define ZEPHYR_ARCH_SPARC_INCLUDE_OFFSETS_SHORT_ARCH_H_

#include <offsets.h>
#include <zephyr/offsets.h>

#define _thread_offset_to_y \
(___thread_t_callee_saved_OFFSET + ___callee_saved_t_y_OFFSET)
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/ia32/offsets_short_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef ZEPHYR_ARCH_X86_INCLUDE_IA32_OFFSETS_SHORT_ARCH_H_
#define ZEPHYR_ARCH_X86_INCLUDE_IA32_OFFSETS_SHORT_ARCH_H_

#include <offsets.h>
#include <zephyr/offsets.h>

/* kernel */

Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/intel64/offsets_short_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef ZEPHYR_ARCH_X86_INCLUDE_INTEL64_OFFSETS_SHORT_ARCH_H_
#define ZEPHYR_ARCH_X86_INCLUDE_INTEL64_OFFSETS_SHORT_ARCH_H_

#include <offsets.h>
#include <zephyr/offsets.h>

#define _thread_offset_to_rsp \
(___thread_t_callee_saved_OFFSET + ___callee_saved_t_rsp_OFFSET)
Expand Down
4 changes: 2 additions & 2 deletions arch/xtensa/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ add_subdirectory(startup)
# are the official places where we find core-isa.h. (Also that we
# undefine __XCC_ because that compiler actually trips an error trying
# to build this file to protect against mismatched versions.)
set(CORE_ISA_DM ${CMAKE_BINARY_DIR}/zephyr/include/generated/core-isa-dM.h)
set(CORE_ISA_DM ${CMAKE_BINARY_DIR}/zephyr/include/generated/zephyr/core-isa-dM.h)
set(CORE_ISA_IN ${CMAKE_BINARY_DIR}/zephyr/include/generated/core-isa-dM.c)
file(WRITE ${CORE_ISA_IN} "#include <xtensa/config/core-isa.h>\n")
add_custom_command(OUTPUT ${CORE_ISA_DM}
Expand All @@ -73,7 +73,7 @@ else()
endif()

# Generates a list of device-specific scratch register choices
set(ZSR_H ${CMAKE_BINARY_DIR}/zephyr/include/generated/zsr.h)
set(ZSR_H ${CMAKE_BINARY_DIR}/zephyr/include/generated/zephyr/zsr.h)
add_custom_command(OUTPUT ${ZSR_H} DEPENDS ${CORE_ISA_DM}
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gen_zsr.py
$<$<BOOL:${CONFIG_XTENSA_MMU}>:--mmu>
Expand Down
2 changes: 1 addition & 1 deletion arch/xtensa/core/coredump.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <string.h>
#include <zephyr/debug/coredump.h>
#include <xtensa_asm2_context.h>
#include <offsets.h>
#include <zephyr/offsets.h>

#define ARCH_HDR_VER 1
#define XTENSA_BLOCK_HDR_VER 2
Expand Down
2 changes: 1 addition & 1 deletion arch/xtensa/core/debug_helpers_asm.S
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <xtensa/hal.h>
#include <xtensa_asm2_context.h>

#include <offsets.h>
#include <zephyr/offsets.h>

.section .iram1, "ax"
.align 4
Expand Down
2 changes: 1 addition & 1 deletion arch/xtensa/core/fatal.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,6 @@ static void z_vrfy_xtensa_user_fault(unsigned int reason)
z_impl_xtensa_user_fault(reason);
}

#include <syscalls/xtensa_user_fault_mrsh.c>
#include <zephyr/syscalls/xtensa_user_fault_mrsh.c>

#endif /* CONFIG_USERSPACE */
2 changes: 1 addition & 1 deletion arch/xtensa/core/irq_offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <zephyr/kernel.h>
#include <zephyr/irq_offload.h>
#include <zsr.h>
#include <zephyr/zsr.h>
#include <zephyr/irq.h>

static struct {
Expand Down
4 changes: 2 additions & 2 deletions arch/xtensa/core/userspace.S
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
*/

#include <xtensa_asm2_s.h>
#include <offsets.h>
#include <zephyr/offsets.h>
#include <offsets_short.h>
#include <zephyr/syscall.h>
#include <zsr.h>
#include <zephyr/zsr.h>

#include <xtensa/config/core-isa.h>

Expand Down
Loading

0 comments on commit bbe5e1e

Please sign in to comment.