Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
23743df
Merge pull request #283 from bytecodealliance/main
wenyongh Jul 6, 2021
7fd5e42
Implement wasm-c-api frame/trap APIs for interpreter mode
wenyongh Jul 6, 2021
08ced33
Merge pull request #284 from bytecodealliance/main
wenyongh Jul 6, 2021
60ff1ef
Implement wasm-c-api frame/trap APIs for AOT mode
wenyongh Jul 12, 2021
90e635a
Fix CI error when building wasm-c-api samples with AOT mode
wenyongh Jul 13, 2021
806b54b
Merge pull request #286 from bytecodealliance/main
wenyongh Jul 13, 2021
ab5c42a
Implement wasm_config related wasm-c-api APIs
wenyongh Jul 14, 2021
c5a528d
Merge pull request #290 from bytecodealliance/main
wenyongh Jul 15, 2021
1af82b7
Merge pull request #296 from bytecodealliance/main
wenyongh Jul 22, 2021
e3bada2
Merge pull request #297 from bytecodealliance/main
wenyongh Jul 22, 2021
bf41042
Fix some compile warnings, update document
wenyongh Jul 22, 2021
2e96743
Fix coding style issue of clock_gettime_wrapper
wenyongh Jul 22, 2021
75e44dc
Merge pull request #298 from bytecodealliance/main
wenyongh Jul 22, 2021
1db2554
Merge pull request #299 from bytecodealliance/main
wenyongh Jul 26, 2021
0577ed2
Enable mpu stack for latest zephyr to enable app manager
wenyongh Jul 27, 2021
3d43473
Merge pull request #300 from bytecodealliance/main
wenyongh Jul 27, 2021
474a72f
Merge pull request #301 from bytecodealliance/main
wenyongh Jul 28, 2021
f6d25ba
Implement more wasm-c-api APIs
wenyongh Jul 28, 2021
18a9a54
Update CI rules
wenyongh Jul 28, 2021
545ba8f
Fix wasm-c-api sample issues and update CIs
wenyongh Jul 28, 2021
2d4d4be
Fix typo
wenyongh Jul 28, 2021
a78593e
Merge pull request #302 from wenyongh/test_ci
wenyongh Jul 28, 2021
973da6e
Fix issues reported by klocwork
wenyongh Jul 28, 2021
e602b2c
Merge pull request #304 from bytecodealliance/main
wenyongh Jul 28, 2021
916f819
Merge pull request #307 from bytecodealliance/main
wenyongh Jul 29, 2021
5a8b915
Fix issues reported by gcc -fsanitize flag
wenyongh Jul 30, 2021
51ad755
Merge pull request #308 from bytecodealliance/main
wenyongh Jul 30, 2021
1d05538
Merge pull request #309 from bytecodealliance/main
wenyongh Aug 2, 2021
0ca30d7
Implement wasm_runtime_init_thread_env for Windows platform
wenyongh Aug 3, 2021
fb5f210
Merge pull request #310 from bytecodealliance/main
wenyongh Aug 3, 2021
2ee9272
Fix sample compile issues
wenyongh Aug 6, 2021
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
32 changes: 26 additions & 6 deletions samples/basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,48 @@ set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")

# WAMR features switch
set (WAMR_BUILD_TARGET "X86_64")
set(CMAKE_BUILD_TYPE Debug)

# Set WAMR_BUILD_TARGET, currently values supported:
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
if (NOT DEFINED WAMR_BUILD_TARGET)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set (WAMR_BUILD_TARGET "AARCH64")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
set (WAMR_BUILD_TARGET "RISCV64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Build as X86_64 by default in 64-bit platform
set (WAMR_BUILD_TARGET "X86_64")
else ()
# Build as X86_32 by default in 32-bit platform
set (WAMR_BUILD_TARGET "X86_32")
endif ()
endif ()

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

set (WAMR_BUILD_INTERP 1)
set (WAMR_BUILD_AOT 1)
set (WAMR_BUILD_JIT 0)
set (WAMR_BUILD_LIBC_BUILTIN 1)

if (NOT MSVC)
set (WAMR_BUILD_LIBC_WASI 1)
endif ()
set (WAMR_BUILD_FAST_INTERP 0)

if (NOT MSVC)
# linker flags
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie -fPIE")
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
endif ()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
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"))
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")
endif ()
endif ()
endif ()
endif ()

Expand Down
7 changes: 4 additions & 3 deletions samples/basic/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main(int argc, char *argv_main[])
static char global_heap_buf[512 * 1024];
char *buffer, error_buf[128];
int opt;
char * wasm_path;
char * wasm_path = NULL;

wasm_module_t module = NULL;
wasm_module_inst_t module_inst = NULL;
Expand Down Expand Up @@ -148,7 +148,8 @@ int main(int argc, char *argv_main[])
goto fail;
}

float ret_val = *(float*)argv;
float ret_val;
memcpy(&ret_val, argv, sizeof(float));
printf("Native finished calling wasm function generate_float(), returned a float value: %ff\n", ret_val );

// Next we will pass a buffer to the WASM function
Expand All @@ -157,7 +158,7 @@ int main(int argc, char *argv_main[])
// must allocate buffer from wasm instance memory space (never use pointer from host runtime)
wasm_buffer = wasm_runtime_module_malloc(module_inst, 100, (void**)&native_buffer);

*(float*)argv2 = ret_val; // the first argument
memcpy(argv2, &ret_val, sizeof(float)); // the first argument
argv2[1] = wasm_buffer; // the second argument is the wasm buffer address
argv2[2] = 100; // the third argument is the wasm buffer size
argv2[3] = 3; // the last argument is the digits after decimal point for converting float to string
Expand Down
24 changes: 22 additions & 2 deletions samples/multi-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,33 @@ set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")

# WAMR features switch
set(WAMR_BUILD_TARGET "X86_64")

# Set WAMR_BUILD_TARGET, currently values supported:
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
if (NOT DEFINED WAMR_BUILD_TARGET)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set (WAMR_BUILD_TARGET "AARCH64")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
set (WAMR_BUILD_TARGET "RISCV64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Build as X86_64 by default in 64-bit platform
set (WAMR_BUILD_TARGET "X86_64")
else ()
# Build as X86_32 by default in 32-bit platform
set (WAMR_BUILD_TARGET "X86_32")
endif ()
endif ()

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

set(WAMR_BUILD_INTERP 1)
set(WAMR_BUILD_AOT 0)
set(WAMR_BUILD_JIT 0)
set(WAMR_BUILD_LIBC_BUILTIN 1)
set(WAMR_BUILD_LIBC_WASI 0)
set(WAMR_BUILD_FAST_INTERP 0)
set(WAMR_BUILD_MULTI_MODULE 1)

# compiling and linking flags
Expand Down
23 changes: 22 additions & 1 deletion samples/multi-thread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,28 @@ set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")

# WAMR features switch
set(WAMR_BUILD_TARGET "X86_64")

# Set WAMR_BUILD_TARGET, currently values supported:
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
if (NOT DEFINED WAMR_BUILD_TARGET)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set (WAMR_BUILD_TARGET "AARCH64")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
set (WAMR_BUILD_TARGET "RISCV64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Build as X86_64 by default in 64-bit platform
set (WAMR_BUILD_TARGET "X86_64")
else ()
# Build as X86_32 by default in 32-bit platform
set (WAMR_BUILD_TARGET "X86_32")
endif ()
endif ()

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

set(WAMR_BUILD_INTERP 1)
set(WAMR_BUILD_AOT 1)
set(WAMR_BUILD_JIT 0)
Expand Down
26 changes: 21 additions & 5 deletions samples/ref-types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ else()
enable_language (ASM_MASM)
endif()

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()

################ runtime settings ################
string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
if (APPLE)
Expand All @@ -25,7 +21,27 @@ set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")

# WAMR features switch
set(WAMR_BUILD_TARGET "X86_64")

# Set WAMR_BUILD_TARGET, currently values supported:
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
if (NOT DEFINED WAMR_BUILD_TARGET)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set (WAMR_BUILD_TARGET "AARCH64")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
set (WAMR_BUILD_TARGET "RISCV64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Build as X86_64 by default in 64-bit platform
set (WAMR_BUILD_TARGET "X86_64")
else ()
# Build as X86_32 by default in 32-bit platform
set (WAMR_BUILD_TARGET "X86_32")
endif ()
endif ()

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

if(NOT DEFINED WAMR_BUILD_INTERP)
set(WAMR_BUILD_INTERP 1)
Expand Down
23 changes: 22 additions & 1 deletion samples/spawn-thread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,28 @@ set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")

# WAMR features switch
set(WAMR_BUILD_TARGET "X86_64")

# Set WAMR_BUILD_TARGET, currently values supported:
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
if (NOT DEFINED WAMR_BUILD_TARGET)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set (WAMR_BUILD_TARGET "AARCH64")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
set (WAMR_BUILD_TARGET "RISCV64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Build as X86_64 by default in 64-bit platform
set (WAMR_BUILD_TARGET "X86_64")
else ()
# Build as X86_32 by default in 32-bit platform
set (WAMR_BUILD_TARGET "X86_32")
endif ()
endif ()

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

set(WAMR_BUILD_INTERP 1)
set(WAMR_BUILD_AOT 1)
set(WAMR_BUILD_JIT 0)
Expand Down
8 changes: 8 additions & 0 deletions samples/spawn-thread/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ void *thread(void* arg)
wasm_function_inst_t func;
uint32 argv[2];

if (!wasm_runtime_init_thread_env()) {
printf("failed to initialize thread environment");
return NULL;
}

func = wasm_runtime_lookup_function(module_inst, "sum", NULL);
if (!func) {
printf("failed to lookup function sum");
wasm_runtime_destroy_thread_env();
return NULL;
}
argv[0] = thread_arg->start;
Expand All @@ -34,9 +40,11 @@ void *thread(void* arg)
/* call the WASM function */
if (!wasm_runtime_call_wasm(exec_env, func, 2, argv)) {
printf("%s\n", wasm_runtime_get_exception(module_inst));
wasm_runtime_destroy_thread_env();
return NULL;
}

wasm_runtime_destroy_thread_env();
return (void *)(uintptr_t)argv[0];
}

Expand Down
20 changes: 19 additions & 1 deletion samples/wasm-c-api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

################ runtime settings ################

string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
if (APPLE)
add_definitions(-DBH_PLATFORM_DARWIN)
Expand All @@ -24,7 +26,23 @@ set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")

# WAMR features switch
set(WAMR_BUILD_TARGET "X86_64")

# Set WAMR_BUILD_TARGET, currently values supported:
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
if (NOT DEFINED WAMR_BUILD_TARGET)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set (WAMR_BUILD_TARGET "AARCH64")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
set (WAMR_BUILD_TARGET "RISCV64")
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
# Build as X86_64 by default in 64-bit platform
set (WAMR_BUILD_TARGET "X86_64")
else ()
# Build as X86_32 by default in 32-bit platform
set (WAMR_BUILD_TARGET "X86_32")
endif ()
endif ()

if(NOT DEFINED WAMR_BUILD_INTERP)
set(WAMR_BUILD_INTERP 1)
Expand Down
39 changes: 34 additions & 5 deletions samples/workload/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,42 @@ for details, the script includes below steps:
[latest release](https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-12/wasi-sdk-12.0-linux.tar.gz)
to */opt/wasi-sdk*

``` bash
$ wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VER}/${WASI_SDK_FILE}
$ tar zxf ${WASI_SDK_FILE} -C /opt
$ ln -sf /opt/wasi-sdk-${WASI_SDK_VER}.0 /opt/wasi-sdk
```

- **wabt**. Install
[latest release](https://github.com/WebAssembly/wabt/releases/download/1.0.20/wabt-1.0.20-ubuntu.tar.gz)
to */opt/wabt* or */opt/wabt-1.0.20*
[latest release](https://github.com/WebAssembly/wabt/releases/download/1.0.23/wabt-1.0.23-ubuntu.tar.gz)
to */opt/wabt*

``` bash
$ wget https://github.com/WebAssembly/wabt/releases/download/${WABT_VER}/${WABT_FILE}
$ tar zxf ${WABT_FILE} -C /opt
$ ln -sf /opt/wabt-${WABT_VER} /opt/wabt
```

- **emsdk**. Refer to [the guide](https://emscripten.org/docs/getting_started/downloads.html). Don't forget to activate
emsdk and set up environment variables. Verify it with `echo ${EMSDK}`.
emsdk and set up environment variables. Verify it with `echo ${EMSDK}`. Please be sure to install and activate the building
of 2.0.12

``` bash
$ cd /opt
$ git clone https://github.com/emscripten-core/emsdk.git
$ cd emsdk
$ git pull
$ ./emsdk install 2.0.12
$ ./emsdk activate 2.0.12
$ echo "source /opt/emsdk/emsdk_env.sh" >> "${HOME}"/.bashrc
```

- **binaryen**. Install
[latest release](https://github.com/WebAssembly/binaryen/releases/download/version_97/binaryen-version_97-x86_64-linux.tar.gz)
to */opt/binaryen* or */opt/binaryen-version_97*
[latest release](https://github.com/WebAssembly/binaryen/releases/download/version_101/binaryen-version_101-x86_64-linux.tar.gz)
to */opt/binaryen*

``` bash
$ wget https://github.com/WebAssembly/binaryen/releases/download/${BINARYEN_VER}/${BINARYEN_FILE}
$ tar zxf ${BINARYEN_FILE} -C /opt
$ ln -sf /opt/binaryen-${BINARYEN_VER} /opt/binaryen
```
Loading