Skip to content

Commit c4aa1de

Browse files
authored
Add shared heap sample (#3806)
1 parent 1fd422a commit c4aa1de

File tree

11 files changed

+548
-2
lines changed

11 files changed

+548
-2
lines changed

.github/scripts/codeql_buildscript.sh

+30
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ if [[ $? != 0 ]]; then
126126
exit 1;
127127
fi
128128

129+
# build iwasm with multi-memory enabled
130+
cd ${WAMR_DIR}/product-mini/platforms/linux
131+
rm -rf build && mkdir build && cd build
132+
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_MULTI_MEMORY=1
133+
make -j
134+
if [[ $? != 0 ]]; then
135+
echo "Failed to build iwasm with multi-memory enabled!"
136+
exit 1;
137+
fi
138+
129139
# build iwasm with hardware boundary check disabled
130140
cd ${WAMR_DIR}/product-mini/platforms/linux
131141
rm -rf build && mkdir build && cd build
@@ -280,3 +290,23 @@ if [[ $? != 0 ]]; then
280290
echo "Failed to build iwasm with linux perf support enabled!"
281291
exit 1;
282292
fi
293+
294+
# build iwasm with shared heap enabled
295+
cd ${WAMR_DIR}/product-mini/platforms/linux
296+
rm -rf build && mkdir build && cd build
297+
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_SHARED_HEAP=1
298+
make -j
299+
if [[ $? != 0 ]]; then
300+
echo "Failed to build iwasm with shared heap enabled!"
301+
exit 1;
302+
fi
303+
304+
# build iwasm with dynamic aot debug enabled
305+
cd ${WAMR_DIR}/product-mini/platforms/linux
306+
rm -rf build && mkdir build && cd build
307+
cmake .. -DCMAKE_BUILD_TYPE=Debug -DWAMR_BUILD_DYNAMIC_AOT_DEBUG=1
308+
make -j
309+
if [[ $? != 0 ]];
310+
echo "Failed to build iwasm dynamic aot debug enabled!"
311+
exit 1;
312+
fi

.github/workflows/compilation_on_android_ubuntu.yml

+8
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,14 @@ jobs:
578578
./run.sh test1
579579
./run.sh test2
580580
581+
- name: Build Sample [shared-heap]
582+
run: |
583+
cd samples/shared-heap
584+
mkdir build && cd build
585+
cmake ..
586+
cmake --build . --config Debug --parallel 4
587+
./shared_heap_test
588+
581589
test:
582590
needs:
583591
[

.github/workflows/compilation_on_macos.yml

+8
Original file line numberDiff line numberDiff line change
@@ -386,3 +386,11 @@ jobs:
386386
./build.sh
387387
./run.sh test1
388388
./run.sh test2
389+
390+
- name: Build Sample [shared-heap]
391+
run: |
392+
cd samples/shared-heap
393+
mkdir build && cd build
394+
cmake ..
395+
cmake --build . --config Debug --parallel 4
396+
./shared_heap_test

.github/workflows/nightly_run.yml

+8
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,14 @@ jobs:
593593
exit $?
594594
working-directory: ./wamr-app-framework/samples/simple
595595

596+
- name: Build Sample [shared-heap]
597+
run: |
598+
cd samples/shared-heap
599+
mkdir build && cd build
600+
cmake ..
601+
cmake --build . --config Debug --parallel 4
602+
./shared_heap_test
603+
596604
test:
597605
needs:
598606
[

build-scripts/config_common.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ if (WAMR_BUILD_MODULE_INST_CONTEXT EQUAL 1)
498498
message (" Module instance context enabled")
499499
endif ()
500500
if (WAMR_BUILD_GC_HEAP_VERIFY EQUAL 1)
501-
add_definitions (-DWASM_ENABLE_GC_VERIFY=1)
501+
add_definitions (-DBH_ENABLE_GC_VERIFY=1)
502502
message (" GC heap verification enabled")
503503
endif ()
504504
if ("$ENV{COLLECT_CODE_COVERAGE}" STREQUAL "1" OR COLLECT_CODE_COVERAGE EQUAL 1)

core/iwasm/libraries/shared-heap/shared_heap_wrapper.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ get_lib_shared_heap_export_apis(NativeSymbol **p_shared_heap_apis)
5454
{
5555
*p_shared_heap_apis = native_symbols_shared_heap;
5656
return sizeof(native_symbols_shared_heap) / sizeof(NativeSymbol);
57-
}
57+
}

samples/shared-heap/CMakeLists.txt

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
cmake_minimum_required (VERSION 3.14)
5+
6+
include(CheckPIESupported)
7+
8+
if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows")
9+
project (shared_heap_test)
10+
else()
11+
project (shared_heap_test C ASM)
12+
endif()
13+
14+
################ runtime settings ################
15+
string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
16+
if (APPLE)
17+
add_definitions(-DBH_PLATFORM_DARWIN)
18+
endif ()
19+
20+
# Reset default linker flags
21+
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
22+
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
23+
24+
# WAMR features switch
25+
26+
# Set WAMR_BUILD_TARGET, currently values supported:
27+
# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
28+
# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
29+
30+
if (NOT DEFINED WAMR_BUILD_TARGET)
31+
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
32+
set (WAMR_BUILD_TARGET "AARCH64")
33+
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
34+
set (WAMR_BUILD_TARGET "RISCV64")
35+
elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
36+
# Build as X86_64 by default in 64-bit platform
37+
set (WAMR_BUILD_TARGET "X86_64")
38+
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
39+
# Build as X86_32 by default in 32-bit platform
40+
set (WAMR_BUILD_TARGET "X86_32")
41+
else ()
42+
message(SEND_ERROR "Unsupported build target platform!")
43+
endif ()
44+
endif ()
45+
46+
if (NOT CMAKE_BUILD_TYPE)
47+
set (CMAKE_BUILD_TYPE Debug)
48+
endif ()
49+
50+
set (WAMR_BUILD_INTERP 1)
51+
set (WAMR_BUILD_AOT 1)
52+
set (WAMR_BUILD_JIT 0)
53+
set (WAMR_BUILD_LIBC_BUILTIN 1)
54+
set (WAMR_BUILD_LIBC_WASI 0)
55+
set (WAMR_BUILD_SHARED_HEAP 1)
56+
set (WAMR_BUILD_GC_HEAP_VERIFY 1)
57+
58+
if (NOT MSVC)
59+
# linker flags
60+
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
61+
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
62+
endif ()
63+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
64+
if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
65+
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
66+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mindirect-branch-register")
67+
endif ()
68+
endif ()
69+
endif ()
70+
71+
# build out vmlib
72+
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
73+
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
74+
75+
add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
76+
77+
################ application related ################
78+
include_directories(${CMAKE_CURRENT_LIST_DIR}/src)
79+
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
80+
81+
add_executable (shared_heap_test src/main.c ${UNCOMMON_SHARED_SOURCE})
82+
83+
check_pie_supported()
84+
set_target_properties (shared_heap_test PROPERTIES POSITION_INDEPENDENT_CODE ON)
85+
86+
if (APPLE)
87+
target_link_libraries (shared_heap_test vmlib -lm -ldl -lpthread)
88+
else ()
89+
target_link_libraries (shared_heap_test vmlib -lm -ldl -lpthread -lrt)
90+
endif ()
91+
92+
add_subdirectory(wasm-apps)

0 commit comments

Comments
 (0)