Skip to content

Commit

Permalink
cleanup: better ESP32 support, make build options configurable (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
zshipko authored May 14, 2024
1 parent dbb3604 commit 5b5fe55
Show file tree
Hide file tree
Showing 10 changed files with 582 additions and 288 deletions.
44 changes: 37 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
cmake_minimum_required (VERSION 3.14)
project(extism-wamr)

enable_testing()

if (NOT CMAKE_BUILD_TYPE)
if (NOT DEFINED CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Release)
endif()

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED TRUE)

if(ESP_PLATFORM)
include (${COMPONENT_DIR}/build-scripts/esp-idf/extism-wamr/CMakeLists.txt)
return()
endif()


project(extism-wamr)
enable_testing()

# Configure WAMR

if(NOT DEFINED WAMR_BUILD_TARGET)
Expand All @@ -22,20 +28,44 @@ endif()

if(NOT DEFINED WAMR_BUILD_PLATFORM)
string(TOLOWER ${CMAKE_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
elseif(${WAMR_BUILD_PLATFORM} MATCHES "esp-idf")
string(TOLOWER ${CMAKE_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
set(ESP_PLATFORM 1)
endif()

set (CMAKE_C_FLAGS_RELEASE "-O3")
set (CMAKE_C_FLAGS_DEBUG "-g")

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_LIBC_BUILTIN)
set (WAMR_BUILD_LIBC_BUILTIN 1)
endif()

if (NOT DEFINED WAMR_BUILD_LIBC_WASI)
set (WAMR_BUILD_LIBC_WASI 1)
endif()

if (NOT DEFINED WAMR_BUILD_TAIL_CALL)
set (WAMR_BUILD_TAIL_CALL 1)
set (WAMR_BUILD_MULTI_MODULE 1)
set (WAMR_BUILD_FAST_INTERP 1)
endif()

if (NOT DEFINED WAMR_BUILD_GC)
set (WAMR_BUILD_GC 1)
set (WASM_ENABLE_BULK_MEMORY 1)
endif()

# Multi-module is required
set (WAMR_BUILD_MULTI_MODULE 1)

set (WAMR_ROOT_DIR wasm-micro-runtime)


include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})

Expand Down
25 changes: 25 additions & 0 deletions build-scripts/esp-idf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# extism-wamr as ESP-IDF component

You can build an ESP-IDF project with extism-wamr as a component:

- Make sure you have the ESP-IDF properly installed and setup
- In particular have the following paths set:
- `EXTISM_WAMR_PATH` to point to your wamr-sdk repository
- `IDF_PATH` to point to your ESP-IDF
- `source $IDF_PATH/export.sh`
- Create a new project, e.g.: `idf.py create-project wamr-hello`
- In the newly created project folder edit the `CMakeList.txt`:

```
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set (COMPONENTS ${IDF_TARGET} main freertos esptool_py extism-wamr)
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{EXTISM_WAMR_PATH}/build-scripts/esp-idf")
project(wamr-hello)
```
- Develop your project in it's `main` component folder.

122 changes: 122 additions & 0 deletions build-scripts/esp-idf/extism-wamr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Copyright (C) 2021 Intel Corporation and others. All rights reserved.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

# Set WAMR's build options

if (NOT CMAKE_BUILD_EARLY_EXPANSION)

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 ()

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 ()

if (CONFIG_WAMR_ENABLE_TAIL_CALL)
set (WAMR_BUILD_TAIL_CALL 1)
endif ()

if (CONFIG_WAMR_ENABLE_GC)
set (WAMR_BUILD_GC 1)
endif ()

set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../wasm-micro-runtime)
set (SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/../../../src)
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)

list (APPEND srcs "${WAMR_RUNTIME_LIB_SOURCE}"
"${PLATFORM_SHARED_SOURCE}"
"${SRC_DIR}/symbols.c"
"${SRC_DIR}/kernel.c"
"${SRC_DIR}/extism.c"

)

set (include_dirs "${IWASM_DIR}/include"
"${UTILS_SHARED_DIR}"
"${PLATFORM_SHARED_DIR}"
"${PLATFORM_SHARED_DIR}/../include"
"${IWASM_COMMON_DIR}"
"${SRC_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 ()
85 changes: 85 additions & 0 deletions build-scripts/esp-idf/extism-wamr/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
menu "Extism WAMR"
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 n

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 y

config WAMR_ENABLE_PERF_PROFILING
bool "Performance profiling"
default n

config WAMR_ENABLE_REF_TYPES
bool "Reference types"
default y

config WAMR_ENABLE_SHARED_MEMORY
bool "Shared memory"
default n

config WAMR_ENABLE_GC
bool "GC"
default n

config WAMR_ENABLE_TAIL_CALL
bool "Tail calls"
default n
endmenu
14 changes: 14 additions & 0 deletions idf_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "2.0.0"
description: Extism WAMR SDK
repository: https://github.com/extism/wamr-sdk
documentation: https://github.com/extism/wamr-sdk
issues: https://github.com/extism/wamr-sdk/issues
dependencies:
idf: ">=4.4"
targets:
- esp32
- esp32s3
- esp32c3
- esp32c6
# examples:
# - path: product-mini/platforms/esp-idf
Loading

0 comments on commit 5b5fe55

Please sign in to comment.