Port WAMR to ESP-IDF (#892)
This PR introduces an implementation of the WAMR platform APIs for ESP-IDF and enables support for Espressif microcontrollers, and adds the documentation around how to build WAMR for ESP-IDF. This PR is related to the following issues at WAMR: closes #883, #628, #449 and #668 as well as [#4735](https://github.com/espressif/esp-idf/issues/4735) at the esp-idf repo. It implements most functions required by [platform_api_vmcore.h](https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/core/shared/platform/include/platform_api_vmcore.h). The PR works in interpreter mode on Esp32c3 and Esp32. For the AOT mode, currently errors occur on both platforms with `Guru Meditation Error`. It seems that the AOT code isn't run with shared memory as os_mmap() allocates memory with malloc() API, it is to be fixed in the future.
This commit is contained in:
@ -3,53 +3,75 @@
|
||||
|
||||
# from ESP-IDF 4.0 examples/build_system/cmake/idf_as_lib
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(wamr_on_esp32c3)
|
||||
|
||||
project(wamr_esp_idf C)
|
||||
enable_language(ASM)
|
||||
|
||||
enable_language (ASM)
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif ()
|
||||
|
||||
if("${IDF_TARGET}" STREQUAL "")
|
||||
message(FATAL_ERROR "You need to set IDF_TARGET to your target string")
|
||||
endif()
|
||||
|
||||
# Include for ESP-IDF build system functions
|
||||
include($ENV{IDF_PATH}/tools/cmake/idf.cmake)
|
||||
# Create idf::esp32c3 and idf::freertos static libraries
|
||||
idf_build_process(${IDF_TARGET}
|
||||
# try and trim the build; additional components
|
||||
# will be included as needed based on dependency tree
|
||||
#
|
||||
# although esptool_py does not generate static library,
|
||||
# processing the component is needed for flashing related
|
||||
# targets and file generation
|
||||
COMPONENTS ${IDF_TARGET} freertos esptool_py
|
||||
SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig
|
||||
BUILD_DIR ${CMAKE_BINARY_DIR})
|
||||
|
||||
# Create idf::esp32 and idf::freertos static libraries
|
||||
idf_build_process(esp32
|
||||
# try and trim the build; additional components
|
||||
# will be included as needed based on dependency tree
|
||||
#
|
||||
# although esptool_py does not generate static library,
|
||||
# processing the component is needed for flashing related
|
||||
# targets and file generation
|
||||
COMPONENTS esp32 freertos esptool_py
|
||||
SDKCONFIG ${CMAKE_BINARY_DIR}/sdkconfig
|
||||
BUILD_DIR ${CMAKE_BINARY_DIR})
|
||||
|
||||
include_directories(build/config
|
||||
xtensa/include
|
||||
$ENV{IDF_PATH}/components/esp32/include
|
||||
$ENV{IDF_PATH}/components/esp_common/include
|
||||
$ENV{IDF_PATH}/components/esp_rom/include
|
||||
$ENV{IDF_PATH}/components/freertos/include
|
||||
$ENV{IDF_PATH}/components/heap/include
|
||||
$ENV{IDF_PATH}/components/soc/esp32/include
|
||||
$ENV{IDF_PATH}/components/xtensa/include
|
||||
$ENV{IDF_PATH}/components/xtensa/esp32/include)
|
||||
# Set WAMR's build options
|
||||
if("${IDF_TARGET}" STREQUAL "esp32c3")
|
||||
set(WAMR_BUILD_TARGET "RISCV32")
|
||||
else()
|
||||
set(WAMR_BUILD_TARGET "XTENSA")
|
||||
add_compile_options(-DWAMR_BUILD_TARGET_XTENSA=1)
|
||||
endif()
|
||||
|
||||
set(WAMR_BUILD_PLATFORM "esp-idf")
|
||||
set(WAMR_BUILD_TARGET "XTENSA")
|
||||
set(WAMR_BUILD_INTERP 1)
|
||||
set(WAMR_BUILD_FAST_INTERP 1)
|
||||
set(WAMR_BUILD_AOT 1)
|
||||
set(WAMR_BUILD_LIBC_BUILTIN 1)
|
||||
set(WAMR_BUILD_LIBC_WASI 0)
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_INTERP)
|
||||
set (WAMR_BUILD_INTERP 0)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_FAST_INTERP)
|
||||
set (WAMR_BUILD_FAST_INTERP 0)
|
||||
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 ()
|
||||
|
||||
|
||||
# Set the compile time variable so that the right binary is selected
|
||||
add_compile_options(-DWAMR_BUILD_INTERP=${WAMR_BUILD_INTERP})
|
||||
|
||||
set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
|
||||
|
||||
include(${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
||||
|
||||
# define WAMR as library and provide it the esp-idf srcs
|
||||
add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
|
||||
target_link_libraries(vmlib PUBLIC idf::pthread idf::${IDF_TARGET} idf::freertos)
|
||||
|
||||
# Define the final executable
|
||||
set(elf_file ${CMAKE_PROJECT_NAME}.elf)
|
||||
add_executable(${elf_file} main.c iwasm_main.c)
|
||||
|
||||
# Link the static libraries to the executable
|
||||
target_link_libraries(${elf_file} idf::esp32 idf::freertos idf::spi_flash vmlib)
|
||||
|
||||
add_executable(${elf_file} main.c test_wasm.h)
|
||||
target_link_libraries(${elf_file} idf::${IDF_TARGET} idf::freertos idf::spi_flash vmlib)
|
||||
idf_build_executable(${elf_file})
|
||||
|
||||
Reference in New Issue
Block a user