mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-07-15 08:48:33 +00:00
create skeleton project for lua wasm comparison
This commit is contained in:
parent
ef3cc50508
commit
e6c39be4be
80
samples/wasm-lua-comparison/CMakeLists.txt
Normal file
80
samples/wasm-lua-comparison/CMakeLists.txt
Normal file
|
@ -0,0 +1,80 @@
|
|||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(comparison)
|
||||
|
||||
set(CMAKE_C_COMPILER_WORKS 1)
|
||||
set(CMAKE_CXX_COMPILER_WORKS 1)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
|
||||
################ runtime settings ################
|
||||
string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
|
||||
if (APPLE)
|
||||
add_definitions(-DBH_PLATFORM_DARWIN)
|
||||
endif ()
|
||||
|
||||
# Resetdefault linker flags
|
||||
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
|
||||
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
|
||||
|
||||
# WAMR features switch
|
||||
|
||||
# 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 MATCHES "^(arm64|aarch64)")
|
||||
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)
|
||||
set(WAMR_BUILD_FAST_INTERP 1)
|
||||
set(WAMR_BUILD_LIB_PTHREAD 1)
|
||||
|
||||
# compiling and linking 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")
|
||||
endif ()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
|
||||
|
||||
# build out vmlib
|
||||
set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
|
||||
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
||||
|
||||
add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
|
||||
################################################
|
||||
|
||||
|
||||
################ wasm application ################
|
||||
add_subdirectory(wasm-apps)
|
||||
################ wamr runtime ################
|
||||
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
|
||||
|
||||
include_directories(include)
|
||||
|
||||
set (RUNTIME_SOURCE_ALL
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/main.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lua.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/wasm.c
|
||||
${UNCOMMON_SHARED_SOURCE}
|
||||
)
|
||||
add_executable (comparison ${RUNTIME_SOURCE_ALL})
|
||||
target_link_libraries(comparison vmlib -lpthread -lm)
|
12
samples/wasm-lua-comparison/include/lua.h
Normal file
12
samples/wasm-lua-comparison/include/lua.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef WASM_H
|
||||
#define WASM_H
|
||||
|
||||
void init_lua();
|
||||
|
||||
void deInit_Lua();
|
||||
|
||||
void call_lua_function();
|
||||
|
||||
#endif
|
||||
|
||||
|
13
samples/wasm-lua-comparison/include/wasm.h
Normal file
13
samples/wasm-lua-comparison/include/wasm.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
#ifndef WASM_H
|
||||
#define WASM_H
|
||||
|
||||
#include "wasm_export.h"
|
||||
#include "bh_read_file.h"
|
||||
|
||||
void init_wasm();
|
||||
|
||||
void call_wasm_function();
|
||||
|
||||
void deInit_wasm();
|
||||
|
||||
#endif
|
22
samples/wasm-lua-comparison/src/lua.c
Normal file
22
samples/wasm-lua-comparison/src/lua.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include "lua.h"
|
||||
|
||||
void init_lua()
|
||||
{
|
||||
printf("%s\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
|
||||
void deInit_Lua()
|
||||
{
|
||||
printf("%s\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Note this function will need input
|
||||
*/
|
||||
void call_lua_function()
|
||||
{
|
||||
printf("%s\n", __FUNCTION__);
|
||||
}
|
24
samples/wasm-lua-comparison/src/main.c
Normal file
24
samples/wasm-lua-comparison/src/main.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#include "wasm_export.h"
|
||||
#include "bh_read_file.h"
|
||||
#include "pthread.h"
|
||||
#include "lua.h"
|
||||
#include "wasm.h"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
init_wasm();
|
||||
|
||||
init_lua();
|
||||
|
||||
call_lua_function();
|
||||
|
||||
call_wasm_function();
|
||||
|
||||
return 0;
|
||||
}
|
22
samples/wasm-lua-comparison/src/wasm.c
Normal file
22
samples/wasm-lua-comparison/src/wasm.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include "wasm.h"
|
||||
|
||||
void init_wasm()
|
||||
{
|
||||
printf("%s\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
|
||||
void deInit_wasm()
|
||||
{
|
||||
printf("%s\n", __FUNCTION__);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Note this function will need input
|
||||
*/
|
||||
void call_wasm_function()
|
||||
{
|
||||
printf("%s\n", __FUNCTION__);
|
||||
}
|
38
samples/wasm-lua-comparison/wasm-apps/CMakeLists.txt
Normal file
38
samples/wasm-lua-comparison/wasm-apps/CMakeLists.txt
Normal file
|
@ -0,0 +1,38 @@
|
|||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(wasm-apps)
|
||||
|
||||
set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
|
||||
|
||||
if (APPLE)
|
||||
set (HAVE_FLAG_SEARCH_PATHS_FIRST 0)
|
||||
set (CMAKE_C_LINK_FLAGS "")
|
||||
set (CMAKE_CXX_LINK_FLAGS "")
|
||||
endif ()
|
||||
set(CMAKE_SYSTEM_PROCESSOR wasm32)
|
||||
set (CMAKE_SYSROOT ${WAMR_ROOT_DIR}/wamr-sdk/app/libc-builtin-sysroot)
|
||||
|
||||
if (NOT DEFINED WASI_SDK_DIR)
|
||||
set (WASI_SDK_DIR "/opt/wasi-sdk")
|
||||
endif ()
|
||||
|
||||
set (CMAKE_C_FLAGS "-nostdlib -pthread -Qunused-arguments")
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -z stack-size=32768")
|
||||
set (CMAKE_C_COMPILER_TARGET "wasm32")
|
||||
set (CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang")
|
||||
|
||||
set (DEFINED_SYMBOLS
|
||||
"${WAMR_ROOT_DIR}/wamr-sdk/app/libc-builtin-sysroot/share/defined-symbols.txt")
|
||||
|
||||
set (CMAKE_EXE_LINKER_FLAGS
|
||||
"-Wl,--shared-memory,--max-memory=131072, \
|
||||
-Wl,--no-entry,--strip-all,--export=sum, \
|
||||
-Wl,--export=__heap_base,--export=__data_end \
|
||||
-Wl,--export=__wasm_call_ctors \
|
||||
-Wl,--allow-undefined-file=${DEFINED_SYMBOLS}"
|
||||
)
|
||||
|
||||
add_executable(test.wasm sum.c)
|
||||
target_link_libraries(test.wasm)
|
16
samples/wasm-lua-comparison/wasm-apps/sum.c
Normal file
16
samples/wasm-lua-comparison/wasm-apps/sum.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
int
|
||||
sum(int start, int length)
|
||||
{
|
||||
int sum = 0, i;
|
||||
|
||||
for (i = start; i < start + length; i++) {
|
||||
sum += i;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
Loading…
Reference in New Issue
Block a user