Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Kconfig.zephyr
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,23 @@ config ENFORCE_ZEPHYR_STDINT
should be turned off with the caveat that argument type validation
on Zephyr code will be skipped.

config OMIT_ZEPHYR_STDINT_FOR_APPS
bool "Omit Zephyr stdint convention for application code"
depends on ENFORCE_ZEPHYR_STDINT
help
When enabled, the "app" build target (i.e. source files under
APPLICATION_SOURCE_DIR) is compiled with the toolchain's native
integer type definitions instead of Zephyr's enforced convention.
This is useful when application code includes compiler-provided
headers that are incompatible with Zephyr's type mappings.

The Zephyr kernel, drivers, subsystems, and any libraries built
via zephyr_library() remain under the enforced convention.
Because Zephyr is C-only, there is no symbol mangling dependency
on the underlying types, and the affected types (e.g. int vs long
on ILP32) share the same size and ABI, so linkage between
application and Zephyr object code remains fully compatible.

endmenu


Expand Down
4 changes: 4 additions & 0 deletions cmake/modules/kernel.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ add_custom_target(zephyr_property_target)
zephyr_library_named(app)
set_property(TARGET app PROPERTY ARCHIVE_OUTPUT_DIRECTORY app)

if(CONFIG_OMIT_ZEPHYR_STDINT_FOR_APPS)
target_compile_definitions(app PRIVATE ZEPHYR_INCLUDE_TOOLCHAIN_STDINT_H_)
endif()

add_subdirectory(${ZEPHYR_BASE} ${__build_dir})

# Link 'app' with the Zephyr interface libraries.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(omit_zephyr_stdint)

target_sources(app PRIVATE src/main.c)
1 change: 1 addition & 0 deletions tests/application_development/omit_zephyr_stdint/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_COMPILER_WARNINGS_AS_ERRORS=y
53 changes: 53 additions & 0 deletions tests/application_development/omit_zephyr_stdint/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2026 BayLibre SAS
*
* SPDX-License-Identifier: Apache-2.0
*/

/*
* Validate CONFIG_OMIT_ZEPHYR_STDINT_FOR_APPS.
*
* When the option is enabled, application code gets the toolchain's native
* integer type definitions. The correct printf format specifiers then
* depend on the data model:
*
* ILP32 (32-bit targets): int32_t is "long" -> %ld
* LP64 (64-bit targets): int64_t is "long" -> %ld
*
* Under Zephyr's enforced convention (the default), the mapping is:
*
* int32_t is always "int" -> %d
* int64_t is always "long long" -> %lld
*
* This test uses the format specifiers matching each convention and
* must compile cleanly (no -Wformat warnings, which are errors with
* -Werror) to pass.
*/

#include <zephyr/kernel.h>
#include <stdint.h>

int main(void)
{
int32_t val32 = 32;
int64_t val64 = 64;

#ifdef CONFIG_OMIT_ZEPHYR_STDINT_FOR_APPS
/* Native toolchain types */
#if __SIZEOF_POINTER__ == 4
/* ILP32: int32_t is long */
printk("int32_t = %ld\n", val32);
printk("int64_t = %lld\n", val64);
#else
/* LP64: int64_t is long */
printk("int32_t = %d\n", val32);
printk("int64_t = %ld\n", val64);
#endif
#else
/* Zephyr convention: int32_t = int, int64_t = long long */
printk("int32_t = %d\n", val32);
printk("int64_t = %lld\n", val64);
#endif

return 0;
}
17 changes: 17 additions & 0 deletions tests/application_development/omit_zephyr_stdint/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
common:
tags: toolchain
build_only: true
arch_allow:
- arm
- arm64
tests:
buildsystem.app_dev.omit_zephyr_stdint.enabled:
extra_configs:
- CONFIG_OMIT_ZEPHYR_STDINT_FOR_APPS=y
platform_allow:
- qemu_cortex_m3
- qemu_cortex_a53
buildsystem.app_dev.omit_zephyr_stdint.disabled:
platform_allow:
- qemu_cortex_m3
- qemu_cortex_a53