Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ ports=(
"lsb_vsx"
"heatshrink"
"smolrtsp"
"wamr"
)


Expand Down
76 changes: 76 additions & 0 deletions wamr/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash

set -e

version="${PORTS_WAMR_VERSION:-2.4.2}"
archive_filename="WAMR-${version}.tar.gz"
PREFIX_PORT_SRC="${PREFIX_PORT_BUILD}/${version}"
PRODUCT_MINI_DIR=${PREFIX_PORT_SRC}/product-mini/platforms/phoenix/build
PLATFORMS_BUILD_PATH="${PREFIX_PORT_SRC}/core/shared/platform"
DEBUG=0

if [ $DEBUG = 1 ]; then
DEBUG_FLAG="-DCMAKE_BUILD_TYPE=Debug"
fi

if ! [[ "${TARGET_FAMILY}" =~ "armv7m" || "${TARGET_FAMILY}" =~ "armv8m" ]]; then
TLS_FLAG="-DTARGET_HAS_TLS=1"
fi

if [[ "${TARGET_FAMILY}" =~ "arm" ]]; then
TARGET_FLAG="-DWAMR_BUILD_TARGET=THUMB"
INVOKE_GENERAL_FLAG="-DWAMR_BUILD_INVOKE_NATIVE_GENERAL=1"
elif [[ "${TARGET_FAMILY}" =~ "aarch" ]]; then
TARGET_FLAG="-DWAMR_BUILD_TARGET=AARCH64"
elif [[ "${TARGET_FAMILY}" =~ "riscv" ]]; then
TARGET_FLAG="-DWAMR_BUILD_TARGET=RISCV64"
fi

b_port_download "https://github.com/bytecodealliance/wasm-micro-runtime/archive/refs/tags/" "${archive_filename}"

if [ ! -d "${PREFIX_PORT_SRC}" ]; then
echo "Extracting sources from ${archive_filename}"
mkdir -p "${PREFIX_PORT_SRC}"
tar -axf "${PREFIX_PORT}/${archive_filename}" --strip-components 1 -C "${PREFIX_PORT_SRC}"
fi

b_port_apply_patches "${PREFIX_PORT_SRC}" "${version}"

mkdir -p "${PLATFORMS_BUILD_PATH}/phoenix"
cp "${PLATFORMS_BUILD_PATH}/linux/platform_internal.h" "${PLATFORMS_BUILD_PATH}/phoenix/platform_internal.h"
cp "${PLATFORMS_BUILD_PATH}/linux/platform_init.c" "${PLATFORMS_BUILD_PATH}/phoenix/platform_init.c"
cp "${PLATFORMS_BUILD_PATH}/linux/shared_platform.cmake" "${PLATFORMS_BUILD_PATH}/phoenix/shared_platform.cmake"

mkdir -p "${PREFIX_PORT_SRC}/product-mini/platforms/phoenix"
cp "${PREFIX_PORT_SRC}/product-mini/platforms/posix/main.c" "${PREFIX_PORT_SRC}/product-mini/platforms/phoenix/"
cp "${PREFIX_PORT_SRC}/product-mini/platforms/linux/CMakeLists.txt" "${PREFIX_PORT_SRC}/product-mini/platforms/phoenix/"
rm -rf "${PREFIX_PORT_SRC}/product-mini/platforms/phoenix/native_libs"
cp -r "${PREFIX_PROJECT}/${WAMR_NATIVE_LIBS_DIR:-phoenix-rtos-ports/wamr/platform_files/native_libs}" "${PREFIX_PORT_SRC}/product-mini/platforms/phoenix/native_libs"

WAMR_FLAGS="-DWAMR_BUILD_PLATFORM=phoenix $TARGET_FLAG \
-DWAMR_BUILD_AOT=0 \
-DWAMR_DISABLE_HW_BOUND_CHECK=1 ${INVOKE_GENERAL_FLAG} -DWAMR_BUILD_MULTI_MODULE=1 \
-DWAMR_BUILD_SHRUNK_MEMORY=1 -DWAMR_BUILD_EXTENDED_CONST_EXPR=1 -DWAMR_BUILD_TAIL_CALL=1 \
${DEBUG_FLAG} ${TLS_FLAG}"

if [[ ${WAMR_LOW_MEMORY} = 1 ]]; then
echo "Compiling in low memory mode"
WAMR_FLAGS="${WAMR_FLAGS} -DWAMR_BUILD_LIBC_WASI=0 -DWAMR_APP_THREAD_STACK_SIZE_MAX=131072 \
-DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_SIMD=0 -DWAMR_BUILD_LIB_WASI_THREADS=0"
else
WAMR_FLAGS="${WAMR_FLAGS} -DWAMR_BUILD_LIB_WASI_THREADS=1 -DWAMR_BUILD_BULK_MEMORY=1 \
-DWAMR_BUILD_LIB_SIMDE=1 -DWAMR_BUILD_SIMD=1"
fi

mkdir -p "${PRODUCT_MINI_DIR}"
(cd "${PRODUCT_MINI_DIR}" && cmake ${WAMR_FLAGS} .. && make)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [shellcheck] reported by reviewdog 🐶
Double quote to prevent globbing and word splitting. SC2086

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double quotes preserve indentation between flags which breaks passing them to cmake

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shellcheck (suggestion)] reported by reviewdog 🐶

Suggested change
(cd "${PRODUCT_MINI_DIR}" && cmake ${WAMR_FLAGS} .. && make)
(cd "${PRODUCT_MINI_DIR}" && cmake "${WAMR_FLAGS}" .. && make)


mkdir -p "${PREFIX_ROOTFS}"usr/bin

if [ ${DEBUG} = 0 ]; then
$STRIP -o "${PRODUCT_MINI_DIR}/iwasm" "${PRODUCT_MINI_DIR}/iwasm-${version}"
b_install "${PRODUCT_MINI_DIR}/iwasm" /usr/bin/
else
mv "${PRODUCT_MINI_DIR}/iwasm-${version}" "${PREFIX_ROOTFS}usr/bin/iwasm"
fi

1 change: 1 addition & 0 deletions wamr/checksums/WAMR-2.4.2.tar.gz.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
73380561a01f4863506e855c2c265cf03c5b6efb17bbb8c9bbafe80745fd00ef WAMR-2.4.2.tar.gz
14 changes: 14 additions & 0 deletions wamr/native_libs_example/example/example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "wasm_export.h"
#include "example.h"
#include <string.h>
#include <stdio.h>

int foo1(wasm_exec_env_t exec_env, int a, int b)
{
return a * b + 3;
}

void foo2(wasm_exec_env_t exec_env, unsigned char *msg, uint8_t *buffer, int buf_len)

Check warning on line 11 in wamr/native_libs_example/example/example.c

View workflow job for this annotation

GitHub Actions / call-lint / clang-format-pr

[clang-format-pr] reported by reviewdog 🐶 suggested fix Raw Output: wamr/native_libs_example/example/example.c:10:- wamr/native_libs_example/example/example.c:11:-void foo2(wasm_exec_env_t exec_env, unsigned char *msg, uint8_t *buffer, int buf_len) wamr/native_libs_example/example/example.c:12:-{ wamr/native_libs_example/example/example.c:13:- strncpy(msg, buffer, buf_len); wamr/native_libs_example/example/example.c:14:-}
{
strncpy(msg, buffer, buf_len);
}
4 changes: 4 additions & 0 deletions wamr/native_libs_example/example/example.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "wasm_export.h"

int foo1(wasm_exec_env_t exec_env, int a, int b);
void foo2(wasm_exec_env_t exec_env, unsigned char *msg, uint8_t *buffer, int buf_len);
16 changes: 16 additions & 0 deletions wamr/native_libs_example/native_libs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stddef.h>
#include "wasm_export.h"
#include "example/example.h"

NativeSymbol native_symbols[] = {
{ "foo1", // the name of WASM function name
foo1, // the native function pointer
"(ii)i", // the function prototype signature
NULL },
{ "foo2", // the name of WASM function name
foo2, // the native function pointer
"($*~)", // the function prototype signature
NULL }
};

int n_native_symbols = sizeof(native_symbols) / sizeof(NativeSymbol);
103 changes: 103 additions & 0 deletions wamr/patches/2.4.2/CMakeLists.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
--- a/product-mini/platforms/linux/CMakeLists.txt 2025-09-15 11:11:18.000000000 +0200
+++ b/product-mini/platforms/linux/CMakeLists.txt 2025-09-25 15:53:48.579867600 +0200
@@ -3,15 +3,17 @@

cmake_minimum_required (VERSION 3.14)

+SET(CMAKE_FIND_ROOT_PATH $ENV{PHOENIX_SYSROOT})
+
include(CheckPIESupported)

-project (iwasm)
+project (iwasm C)

option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)

set (CMAKE_VERBOSE_MAKEFILE OFF)

-set (WAMR_BUILD_PLATFORM "linux")
+set (WAMR_BUILD_PLATFORM "phoenix")

# Reset default linker flags
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
@@ -49,14 +51,19 @@
set(CMAKE_BUILD_TYPE Release)
endif ()

+if (DEFINED TARGET_HAS_TLS)
+ set(TARGET_HAS_TLS 1)
+ message(STATUS "Target supports thread local storage")
+endif ()
+
if (NOT DEFINED WAMR_BUILD_INTERP)
# Enable Interpreter by default
set (WAMR_BUILD_INTERP 1)
endif ()

if (NOT DEFINED WAMR_BUILD_AOT)
- # Enable AOT by default.
- set (WAMR_BUILD_AOT 1)
+ # Disable AOT by default.
+ set (WAMR_BUILD_AOT 0)
endif ()

if (NOT DEFINED WAMR_BUILD_JIT)
@@ -95,8 +102,8 @@
endif ()

if (NOT DEFINED WAMR_BUILD_LIB_WASI_THREADS)
- # Disable wasi threads library by default
- set (WAMR_BUILD_LIB_WASI_THREADS 0)
+ # Enable wasi threads library by default
+ set (WAMR_BUILD_LIB_WASI_THREADS 1)
endif()

if (NOT DEFINED WAMR_BUILD_MINI_LOADER)
@@ -125,12 +132,6 @@
set (WAMR_BUILD_SIMD 0)
endif ()

-# if enable wasi-nn, both wasi-nn-backends and iwasm
-# need to use same WAMR (dynamic) libraries
-if (WAMR_BUILD_WASI_NN EQUAL 1)
- set (BUILD_SHARED_LIBS ON)
-endif ()
-
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)

include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
@@ -139,10 +140,10 @@

set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")

-set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow")
+set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow -Os")
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion")

-set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused")
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused -Os")

if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
@@ -162,7 +163,11 @@

include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)

-add_executable (iwasm main.c ${UNCOMMON_SHARED_SOURCE})
+file(GLOB_RECURSE NATIVE_LIBRARIES_SOURCE
+ "${CMAKE_CURRENT_SOURCE_DIR}/native_libs/*.c"
+)
+
+add_executable (iwasm main.c ${UNCOMMON_SHARED_SOURCE} ${NATIVE_LIBRARIES_SOURCE})

set_version_info (iwasm)

@@ -192,7 +197,7 @@
POSITION_INDEPENDENT_CODE ON
)

-target_link_libraries (vmlib ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
+target_link_libraries (vmlib ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -lpthread) # Removed -ldl because we don't support dynamic linking

install (TARGETS vmlib
EXPORT iwasmTargets
Loading
Loading