From bf188a3de9bc10d0f85383e7bcfae88f91b3b39c Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 30 Mar 2026 22:44:57 -0400 Subject: [PATCH] Add Zephyr RTOS (Generic) platform support Recognize CMAKE_SYSTEM_NAME="Generic" as a valid platform (used by Zephyr RTOS and other baremetal targets). Also add Zephyr to the STDERR_FILENO/STDOUT_FILENO fallback path in log.c, matching the existing Hexagon pattern. Signed-off-by: Nicolas Pitre --- CMakeLists.txt | 2 +- src/log.c | 6 +++++- src/xnnpack/common.h | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b24f200aa85..9a177b013ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -390,7 +390,7 @@ ENDIF() # ---[ Build flags IF(NOT CMAKE_SYSTEM_NAME) MESSAGE(FATAL_ERROR "CMAKE_SYSTEM_NAME not defined") -ELSEIF(NOT CMAKE_SYSTEM_NAME MATCHES "^(Android|Darwin|iOS|Linux|Windows|CYGWIN|MSYS|QURT|Emscripten)$") +ELSEIF(NOT CMAKE_SYSTEM_NAME MATCHES "^(Android|Darwin|iOS|Linux|Windows|CYGWIN|MSYS|QURT|Emscripten|Generic)$") MESSAGE(FATAL_ERROR "Unrecognized CMAKE_SYSTEM_NAME value \"${CMAKE_SYSTEM_NAME}\"") ENDIF() IF(CMAKE_SYSTEM_NAME MATCHES "Windows") diff --git a/src/log.c b/src/log.c index d42b1c04317..6895e7508d2 100644 --- a/src/log.c +++ b/src/log.c @@ -45,7 +45,7 @@ #define XNN_LOG_STDERR STD_ERROR_HANDLE #define XNN_LOG_STDOUT STD_OUTPUT_HANDLE -#elif defined(__hexagon__) +#elif defined(__hexagon__) || defined(__ZEPHYR__) #define XNN_LOG_NEWLINE_LENGTH 1 #define XNN_LOG_STDERR 0 @@ -113,6 +113,10 @@ static void xnn_vlog(int output_handle, const char* prefix, GetStdHandle((DWORD)output_handle), out_buffer, (prefix_length + format_length + XNN_LOG_NEWLINE_LENGTH) * sizeof(char), &bytes_written, NULL); +#elif defined(__ZEPHYR__) + out_buffer[prefix_length + format_length] = '\n'; + out_buffer[prefix_length + format_length + 1] = '\0'; + printf("%s", out_buffer); #else out_buffer[prefix_length + format_length] = '\n'; diff --git a/src/xnnpack/common.h b/src/xnnpack/common.h index 9e25ca85a2f..3ae67953e96 100644 --- a/src/xnnpack/common.h +++ b/src/xnnpack/common.h @@ -140,11 +140,13 @@ #define XNN_PLATFORM_QURT 0 #endif +#ifndef XNN_HAS_MMAP #if XNN_PLATFORM_WINDOWS #define XNN_HAS_MMAP 0 #else #define XNN_HAS_MMAP 1 #endif +#endif #if XNN_PLATFORM_WINDOWS #define XNN_HAS_PTHREADS 0