Add wamr to esp-idf components registry (#3287)

This PR is for the main branch, but only the released branch will be pushed
into Espressif component registry.

See also similar fixes in branch release/1.3.x:
https://github.com/bytecodealliance/wasm-micro-runtime/pull/3264
https://github.com/bytecodealliance/wasm-micro-runtime/pull/3288
This commit is contained in:
dongheng 2024-04-08 12:34:08 +08:00 committed by GitHub
parent ef3babc658
commit dacb3c4105
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 39 additions and 10 deletions

View File

@ -3,6 +3,11 @@
cmake_minimum_required (VERSION 3.0) cmake_minimum_required (VERSION 3.0)
if(ESP_PLATFORM)
include (${COMPONENT_DIR}/build-scripts/esp-idf/wamr/CMakeLists.txt)
return()
endif()
project (iwasm) project (iwasm)
set (CMAKE_VERBOSE_MAKEFILE OFF) set (CMAKE_VERBOSE_MAKEFILE OFF)

View File

@ -55,7 +55,24 @@ os_mmap(void *hint, size_t size, int prot, int flags, os_file_handle file)
#else #else
uint32_t mem_caps = MALLOC_CAP_8BIT; uint32_t mem_caps = MALLOC_CAP_8BIT;
#endif #endif
return heap_caps_malloc(size, mem_caps); void *buf_origin =
heap_caps_malloc(size + 4 + sizeof(uintptr_t), mem_caps);
if (!buf_origin) {
return NULL;
}
// Memory allocation with MALLOC_CAP_SPIRAM or MALLOC_CAP_8BIT will
// return 4-byte aligned Reserve extra 4 byte to fixup alignment and
// size for the pointer to the originally allocated address
void *buf_fixed = buf_origin + sizeof(void *);
if ((uintptr_t)buf_fixed & (uintptr_t)0x7) {
buf_fixed = (void *)((uintptr_t)(buf_fixed + 4) & (~(uintptr_t)7));
}
uintptr_t *addr_field = buf_fixed - sizeof(uintptr_t);
*addr_field = (uintptr_t)buf_origin;
return buf_fixed;
} }
} }

8
idf_component.yml Normal file
View File

@ -0,0 +1,8 @@
version: "2.0.0"
description: WebAssembly Micro Runtime - A lightweight standalone WebAssembly (Wasm) runtime with small footprint, high performance and highly configurable features
url: https://bytecodealliance.org/
repository: https://github.com/bytecodealliance/wasm-micro-runtime.git
documentation: https://wamr.gitbook.io/
issues: https://github.com/bytecodealliance/wasm-micro-runtime/issues
dependencies:
idf: ">=4.4"

View File

@ -6,7 +6,4 @@ cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake) include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set (COMPONENTS ${IDF_TARGET} main freertos esptool_py wamr)
list(APPEND EXTRA_COMPONENT_DIRS "$ENV{WAMR_PATH}/build-scripts/esp-idf")
project(wamr-simple) project(wamr-simple)

View File

@ -2,5 +2,4 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
idf_component_register(SRCS "main.c" idf_component_register(SRCS "main.c"
INCLUDE_DIRS "." INCLUDE_DIRS ".")
REQUIRES wamr)

View File

@ -0,0 +1,7 @@
## IDF Component Manager Manifest File
dependencies:
wasm-micro-runtime:
version: ">=2.0"
override_path: "../../../.."
idf:
version: ">=4.4"

View File

@ -12,11 +12,7 @@
#include "esp_log.h" #include "esp_log.h"
#ifdef CONFIG_IDF_TARGET_ESP32S3
#define IWASM_MAIN_STACK_SIZE 5120 #define IWASM_MAIN_STACK_SIZE 5120
#else
#define IWASM_MAIN_STACK_SIZE 4096
#endif
#define LOG_TAG "wamr" #define LOG_TAG "wamr"