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
2 changes: 2 additions & 0 deletions wamr/native_libs_example/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DisableFormat: true
SortIncludes: Never
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"
Comment thread
R4ken marked this conversation as resolved.
#include <string.h>
Comment thread
R4ken marked this conversation as resolved.
#include <stdio.h>

Comment thread
R4ken marked this conversation as resolved.
int foo1(wasm_exec_env_t exec_env, int a, int b)
{
return a * b + 3;
}
Comment thread
R4ken marked this conversation as resolved.

void foo2(wasm_exec_env_t exec_env, unsigned char *msg, uint8_t *buffer, int buf_len)
{
strncpy(msg, buffer, buf_len);
}
Comment thread
oI0ck marked this conversation as resolved.
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);
105 changes: 105 additions & 0 deletions wamr/patches/CMakeLists.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
diff --git a/product-mini/platforms/linux/CMakeLists.txt b/product-mini/platforms/linux/CMakeLists.txt
index cef8329d..af5c2f89 100644
--- a/product-mini/platforms/linux/CMakeLists.txt
+++ b/product-mini/platforms/linux/CMakeLists.txt
@@ -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 @@ if (NOT CMAKE_BUILD_TYPE)
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 @@ if (NOT DEFINED WAMR_BUILD_LIB_PTHREAD)
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 @@ if (WAMR_BUILD_DEBUG_INTERP EQUAL 1)
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 @@ check_pie_supported()

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

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 @@ set_target_properties (vmlib PROPERTIES
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