Add WASI support for esp-idf platform (#3348)
Add WASI support for esp-idf platform: 1. add Kconfig and cmake scripts 2. add API "openat" when using littlefs 3. add clock/rwlock/file/socket OS adapter
This commit is contained in:
@ -2,56 +2,102 @@
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
# Set WAMR's build options
|
||||
if("${IDF_TARGET}" STREQUAL "esp32c3" OR "${IDF_TARGET}" STREQUAL "esp32c6")
|
||||
set(WAMR_BUILD_TARGET "RISCV32")
|
||||
else()
|
||||
set(WAMR_BUILD_TARGET "XTENSA")
|
||||
endif()
|
||||
|
||||
set(WAMR_BUILD_PLATFORM "esp-idf")
|
||||
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_INTERP)
|
||||
set (WAMR_BUILD_INTERP 1)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
|
||||
set (WAMR_BUILD_FAST_INTERP 1)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_AOT)
|
||||
set (WAMR_BUILD_AOT 1)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN)
|
||||
set (WAMR_BUILD_LIBC_BUILTIN 1)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_APP_FRAMEWORK)
|
||||
set (WAMR_BUILD_APP_FRAMEWORK 0)
|
||||
endif ()
|
||||
|
||||
if (NOT CMAKE_BUILD_EARLY_EXPANSION)
|
||||
if (WAMR_BUILD_TARGET STREQUAL "XTENSA")
|
||||
idf_build_set_property(COMPILE_DEFINITIONS "-DBUILD_TARGET_XTENSA=1" APPEND)
|
||||
endif ()
|
||||
if (WAMR_BUILD_INTERP)
|
||||
idf_build_set_property(COMPILE_DEFINITIONS "-DWASM_ENABLE_INTERP=1" APPEND)
|
||||
endif ()
|
||||
if (WAMR_BUILD_AOT)
|
||||
idf_build_set_property(COMPILE_DEFINITIONS "-DWASM_ENABLE_AOT=1" APPEND)
|
||||
endif ()
|
||||
|
||||
set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..)
|
||||
include(${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
||||
endif()
|
||||
if (CONFIG_IDF_TARGET_ARCH_RISCV)
|
||||
set (WAMR_BUILD_TARGET "RISCV32")
|
||||
elseif (CONFIG_IDF_TARGET_ARCH_XTENSA)
|
||||
set (WAMR_BUILD_TARGET "XTENSA")
|
||||
else ()
|
||||
message (FATAL_ERROR "Arch ${CONFIG_IDF_TARGET_ARCH} is not supported")
|
||||
endif ()
|
||||
|
||||
idf_component_register(SRCS ${WAMR_RUNTIME_LIB_SOURCE} ${PLATFORM_SHARED_SOURCE}
|
||||
INCLUDE_DIRS ${IWASM_DIR}/include ${UTILS_SHARED_DIR} ${PLATFORM_SHARED_DIR} ${PLATFORM_SHARED_DIR}/../include
|
||||
REQUIRES pthread lwip esp_timer
|
||||
)
|
||||
set (WAMR_BUILD_PLATFORM "esp-idf")
|
||||
|
||||
if (CONFIG_WAMR_BUILD_DEBUG)
|
||||
set (CMAKE_BUILD_TYPE Debug)
|
||||
else ()
|
||||
set (CMAKE_BUILD_TYPE Release)
|
||||
endif ()
|
||||
|
||||
if (CONFIG_WAMR_ENABLE_INTERP)
|
||||
set (WAMR_BUILD_INTERP 1)
|
||||
endif ()
|
||||
|
||||
if (CONFIG_WAMR_INTERP_FAST)
|
||||
set (WAMR_BUILD_FAST_INTERP 1)
|
||||
endif ()
|
||||
|
||||
if (CONFIG_WAMR_ENABLE_AOT)
|
||||
set (WAMR_BUILD_AOT 1)
|
||||
endif ()
|
||||
|
||||
if (CONFIG_WAMR_ENABLE_LIBC_BUILTIN)
|
||||
set (WAMR_BUILD_LIBC_BUILTIN 1)
|
||||
endif ()
|
||||
|
||||
if (CONFIG_WAMR_INTERP_LOADER_MINI)
|
||||
set (WAMR_BUILD_MINI_LOADER 1)
|
||||
endif ()
|
||||
|
||||
if (CONFIG_WAMR_ENABLE_MULTI_MODULE)
|
||||
set (WAMR_BUILD_MULTI_MODULE 1)
|
||||
endif ()
|
||||
|
||||
if (CONFIG_WAMR_ENABLE_SHARED_MEMORY)
|
||||
set (WAMR_BUILD_SHARED_MEMORY 1)
|
||||
endif ()
|
||||
|
||||
if (CONFIG_WAMR_ENABLE_MEMORY_PROFILING)
|
||||
set (WAMR_BUILD_MEMORY_PROFILING 1)
|
||||
endif ()
|
||||
|
||||
if (CONFIG_WAMR_ENABLE_PERF_PROFILING)
|
||||
set (WAMR_BUILD_PERF_PROFILING 1)
|
||||
endif ()
|
||||
|
||||
if (CONFIG_WAMR_ENABLE_REF_TYPES)
|
||||
set (WAMR_BUILD_REF_TYPES 1)
|
||||
endif ()
|
||||
|
||||
if (CONFIG_WAMR_ENABLE_LIBC_WASI)
|
||||
set (WAMR_BUILD_LIBC_WASI 1)
|
||||
endif ()
|
||||
|
||||
if (CONFIG_WAMR_ENABLE_LIB_PTHREAD)
|
||||
set (WAMR_BUILD_LIB_PTHREAD 1)
|
||||
endif ()
|
||||
|
||||
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..)
|
||||
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
||||
|
||||
list (APPEND srcs "${WAMR_RUNTIME_LIB_SOURCE}"
|
||||
"${PLATFORM_SHARED_SOURCE}")
|
||||
|
||||
set (include_dirs "${IWASM_DIR}/include"
|
||||
"${UTILS_SHARED_DIR}"
|
||||
"${PLATFORM_SHARED_DIR}"
|
||||
"${PLATFORM_SHARED_DIR}/../include"
|
||||
"${IWASM_COMMON_DIR}")
|
||||
endif ()
|
||||
|
||||
idf_component_register(SRCS ${srcs}
|
||||
INCLUDE_DIRS ${include_dirs}
|
||||
REQUIRES pthread lwip esp_timer
|
||||
KCONFIG ${CMAKE_CURRENT_LIST_DIR}/Kconfig)
|
||||
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
|
||||
|
||||
if (CONFIG_IDF_TARGET_ARCH_RISCV)
|
||||
target_compile_definitions(${COMPONENT_LIB} PUBLIC -DBUILD_TARGET_RISCV32_ILP32=1)
|
||||
elseif (CONFIG_IDF_TARGET_ARCH_XTENSA)
|
||||
target_compile_definitions(${COMPONENT_LIB} PUBLIC -DBUILD_TARGET_XTENSA=1)
|
||||
endif ()
|
||||
|
||||
if (CONFIG_WAMR_ENABLE_AOT)
|
||||
target_compile_definitions(${COMPONENT_LIB} PUBLIC -DWASM_ENABLE_AOT=1)
|
||||
endif ()
|
||||
|
||||
if (CONFIG_WAMR_ENABLE_INTERP)
|
||||
target_compile_definitions(${COMPONENT_LIB} PUBLIC -DWASM_ENABLE_INTERP=1)
|
||||
endif ()
|
||||
|
||||
77
build-scripts/esp-idf/wamr/Kconfig
Normal file
77
build-scripts/esp-idf/wamr/Kconfig
Normal file
@ -0,0 +1,77 @@
|
||||
menu "WASM Micro Runtime"
|
||||
choice WAMR_BUILD_TYPE
|
||||
prompt "Build type"
|
||||
default WAMR_BUILD_RELEASE
|
||||
|
||||
config WAMR_BUILD_RELEASE
|
||||
bool "Release"
|
||||
|
||||
config WAMR_BUILD_DEBUG
|
||||
bool "Debug"
|
||||
endchoice
|
||||
|
||||
config WAMR_ENABLE_AOT
|
||||
bool "AOT"
|
||||
default y
|
||||
|
||||
menuconfig WAMR_ENABLE_INTERP
|
||||
bool "Interpreter"
|
||||
default y
|
||||
|
||||
if WAMR_ENABLE_INTERP
|
||||
|
||||
choice WAMR_INTERP_MODE
|
||||
prompt "Interpreter mode"
|
||||
default WAMR_INTERP_FAST
|
||||
|
||||
config WAMR_INTERP_CLASSIC
|
||||
bool "Classic"
|
||||
|
||||
config WAMR_INTERP_FAST
|
||||
bool "Fast"
|
||||
endchoice
|
||||
|
||||
choice WAMR_INTERP_LOADER_MODE
|
||||
prompt "Loader mode"
|
||||
default WAMR_INTERP_LOADER_NORMAL
|
||||
|
||||
config WAMR_INTERP_LOADER_NORMAL
|
||||
bool "Normal"
|
||||
|
||||
config WAMR_INTERP_LOADER_MINI
|
||||
bool "Mini"
|
||||
endchoice
|
||||
endif
|
||||
|
||||
config WAMR_ENABLE_LIB_PTHREAD
|
||||
bool "Lib pthread"
|
||||
default y
|
||||
|
||||
config WAMR_ENABLE_LIBC_BUILTIN
|
||||
bool "Libc builtin"
|
||||
default y
|
||||
|
||||
config WAMR_ENABLE_LIBC_WASI
|
||||
bool "Libc WASI"
|
||||
default y
|
||||
|
||||
config WAMR_ENABLE_MEMORY_PROFILING
|
||||
bool "Memory profiling"
|
||||
default n
|
||||
|
||||
config WAMR_ENABLE_MULTI_MODULE
|
||||
bool "Multi module"
|
||||
default n
|
||||
|
||||
config WAMR_ENABLE_PERF_PROFILING
|
||||
bool "Performance profiling"
|
||||
default n
|
||||
|
||||
config WAMR_ENABLE_REF_TYPES
|
||||
bool "Reference types"
|
||||
default n
|
||||
|
||||
config WAMR_ENABLE_SHARED_MEMORY
|
||||
bool "Shared memory"
|
||||
default n
|
||||
endmenu
|
||||
Reference in New Issue
Block a user