-
Notifications
You must be signed in to change notification settings - Fork 9
WASM: add webassembly-micro-runtime port #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
R4ken
wants to merge
1
commit into
master
Choose a base branch
from
jrak/wamr
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,7 @@ ports=( | |
| "lsb_vsx" | ||
| "heatshrink" | ||
| "smolrtsp" | ||
| "wamr" | ||
| ) | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [shellcheck (suggestion)] reported by reviewdog 🐶
Suggested change
|
||||||
|
|
||||||
| 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 | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 73380561a01f4863506e855c2c265cf03c5b6efb17bbb8c9bbafe80745fd00ef WAMR-2.4.2.tar.gz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #include "wasm_export.h" | ||
| #include "example.h" | ||
R4ken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include <string.h> | ||
R4ken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include <stdio.h> | ||
|
|
||
R4ken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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
|
||
| { | ||
| strncpy(msg, buffer, buf_len); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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