diff --git a/core/iwasm/lib/app-libs/base/wasm_app.h b/core/iwasm/lib/app-libs/base/wasm_app.h index 3513001e..f633231c 100644 --- a/core/iwasm/lib/app-libs/base/wasm_app.h +++ b/core/iwasm/lib/app-libs/base/wasm_app.h @@ -38,7 +38,10 @@ #include "sensor.h" #include "connection.h" #include "timer_wasm_app.h" + +#if ENABLE_WGL != 0 #include "wgl.h" +#endif #ifdef __cplusplus extern "C" { diff --git a/core/iwasm/lib/native-interface/shared_utils.h b/core/iwasm/lib/native-interface/shared_utils.h index 70f561b4..d0727164 100644 --- a/core/iwasm/lib/native-interface/shared_utils.h +++ b/core/iwasm/lib/native-interface/shared_utils.h @@ -156,7 +156,9 @@ unpack_response(char * packet, int size, response_t * response); void free_req_resp_packet(char * packet); +#if WASM_ENABLE_GUI != 0 #include "wgl_shared_utils.h" +#endif #ifdef __cplusplus } diff --git a/core/iwasm/runtime/vmcore-wasm/wasm_interp.c b/core/iwasm/runtime/vmcore-wasm/wasm_interp.c index a7d00e9b..0bd29026 100644 --- a/core/iwasm/runtime/vmcore-wasm/wasm_interp.c +++ b/core/iwasm/runtime/vmcore-wasm/wasm_interp.c @@ -1795,7 +1795,13 @@ wasm_interp_call_func_bytecode(WASMThread *self, b = POP_F32(); a = POP_F32(); - PUSH_F32(wa_fmin(a, b)); + + if (isnan(a)) + PUSH_F32(a); + else if (isnan(b)) + PUSH_F32(b); + else + PUSH_F32(wa_fmin(a, b)); HANDLE_OP_END (); } @@ -1805,7 +1811,13 @@ wasm_interp_call_func_bytecode(WASMThread *self, b = POP_F32(); a = POP_F32(); - PUSH_F32(wa_fmax(a, b)); + + if (isnan(a)) + PUSH_F32(a); + else if (isnan(b)) + PUSH_F32(b); + else + PUSH_F32(wa_fmax(a, b)); HANDLE_OP_END (); } @@ -1870,7 +1882,13 @@ wasm_interp_call_func_bytecode(WASMThread *self, b = POP_F64(); a = POP_F64(); - PUSH_F64(wa_fmin(a, b)); + + if (isnan(a)) + PUSH_F64(a); + else if (isnan(b)) + PUSH_F64(b); + else + PUSH_F64(wa_fmin(a, b)); HANDLE_OP_END (); } @@ -1880,7 +1898,13 @@ wasm_interp_call_func_bytecode(WASMThread *self, b = POP_F64(); a = POP_F64(); - PUSH_F64(wa_fmax(a, b)); + + if (isnan(a)) + PUSH_F64(a); + else if (isnan(b)) + PUSH_F64(b); + else + PUSH_F64(wa_fmax(a, b)); HANDLE_OP_END (); } diff --git a/core/shared-lib/include/config.h b/core/shared-lib/include/config.h index a7c2a8b2..565db6c0 100644 --- a/core/shared-lib/include/config.h +++ b/core/shared-lib/include/config.h @@ -131,3 +131,6 @@ #define bh_printf printf #endif +#ifndef WASM_ENABLE_GUI +#define WASM_ENABLE_GUI 0 +#endif diff --git a/samples/gui/wasm-apps/lvgl-compatible/Makefile b/samples/gui/wasm-apps/lvgl-compatible/Makefile index 17946491..4cea928a 100644 --- a/samples/gui/wasm-apps/lvgl-compatible/Makefile +++ b/samples/gui/wasm-apps/lvgl-compatible/Makefile @@ -18,6 +18,7 @@ IWASM_DIR=../../../../core/iwasm CFLAGS += -O3 \ -Wno-int-conversion \ -DLV_CONF_INCLUDE_SIMPLE \ + -DENABLE_WGL=1 \ -I$(APP_DIR)/src/ \ -I$(IWASM_DIR)/lib/app-libs/base/ \ -I$(IWASM_DIR)/lib/native-interface/ \ diff --git a/samples/gui/wasm-apps/wgl/Makefile b/samples/gui/wasm-apps/wgl/Makefile index 88df1f25..4df65bf8 100644 --- a/samples/gui/wasm-apps/wgl/Makefile +++ b/samples/gui/wasm-apps/wgl/Makefile @@ -18,6 +18,7 @@ IWASM_DIR=../../../../core/iwasm CFLAGS += -O3 \ -Wno-int-conversion \ -DLV_CONF_INCLUDE_SIMPLE \ + -DENABLE_WGL=1 \ -I$(APP_DIR)/src/ \ -I$(IWASM_DIR)/lib/app-libs/base/ \ -I$(IWASM_DIR)/lib/native-interface/ \ diff --git a/samples/gui/wasm-runtime-wgl/linux-build/CMakeLists.txt b/samples/gui/wasm-runtime-wgl/linux-build/CMakeLists.txt index 5869052d..ce3e1cd0 100644 --- a/samples/gui/wasm-runtime-wgl/linux-build/CMakeLists.txt +++ b/samples/gui/wasm-runtime-wgl/linux-build/CMakeLists.txt @@ -82,6 +82,7 @@ add_definitions (-DWASM_ENABLE_BASE_LIB) add_definitions (-Dattr_container_malloc=bh_malloc) add_definitions (-Dattr_container_free=bh_free) add_definitions (-DLV_CONF_INCLUDE_SIMPLE) +add_definitions (-DWASM_ENABLE_GUI=1) add_library (vmlib ${WASM_PLATFORM_LIB_SOURCE} diff --git a/samples/gui/wasm-runtime-wgl/zephyr-build/CMakeLists.txt b/samples/gui/wasm-runtime-wgl/zephyr-build/CMakeLists.txt index 8794324e..c00eadee 100644 --- a/samples/gui/wasm-runtime-wgl/zephyr-build/CMakeLists.txt +++ b/samples/gui/wasm-runtime-wgl/zephyr-build/CMakeLists.txt @@ -24,7 +24,8 @@ zephyr_compile_definitions (-DNVALGRIND -D__ZEPHYR__ -DWASM_ENABLE_BASE_LIB -Dattr_container_malloc=bh_malloc - -Dattr_container_free=bh_free) + -Dattr_container_free=bh_free + -DWASM_ENABLE_GUI=1) set (IWASM_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/core/iwasm) set (APP_MGR_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/core/app-mgr) diff --git a/samples/simple/CMakeLists.txt b/samples/simple/CMakeLists.txt index e5c4e18b..34bc1b70 100644 --- a/samples/simple/CMakeLists.txt +++ b/samples/simple/CMakeLists.txt @@ -48,10 +48,11 @@ set(WASM_DIR ${WAMR_ROOT_DIR}/core/iwasm) set(APP_MGR_DIR ${WAMR_ROOT_DIR}/core/app-mgr) set(SHARED_DIR ${WAMR_ROOT_DIR}/core/shared-lib) -set (LV_DRIVERS_DIR ${WASM_DIR}/lib/3rdparty/lv_drivers) -set (LVGL_DIR ${WASM_DIR}/lib/3rdparty/lvgl) - -file(GLOB_RECURSE LV_DRIVERS_SOURCES "${LV_DRIVERS_DIR}/*.c" ) +if ("${ENABLE_GUI}" STREQUAL "YES") + set (LV_DRIVERS_DIR ${WASM_DIR}/lib/3rdparty/lv_drivers) + set (LVGL_DIR ${WASM_DIR}/lib/3rdparty/lvgl) + file(GLOB_RECURSE LV_DRIVERS_SOURCES "${LV_DRIVERS_DIR}/*.c" ) +endif() enable_language (ASM) @@ -61,7 +62,9 @@ include (${WASM_DIR}/runtime/vmcore-wasm/vmcore.cmake) include (${WASM_DIR}/lib/native/base/wasm_lib_base.cmake) include (${WASM_DIR}/lib/native/libc/wasm_libc.cmake) include (${WASM_DIR}/lib/native/extension/sensor/wasm_lib_sensor.cmake) -include (${WASM_DIR}/lib/native/extension/gui/wasm_lib_gui.cmake) +if ("${ENABLE_GUI}" STREQUAL "YES") + include (${WASM_DIR}/lib/native/extension/gui/wasm_lib_gui.cmake) +endif() include (${WASM_DIR}/lib/native/extension/connection/wasm_lib_conn.cmake) include (${WASM_DIR}/lib/native/extension/connection/${TARGET_PLATFORM}/connection_mgr.cmake) include (${WASM_DIR}/lib/native-interface/native_interface.cmake) @@ -83,6 +86,10 @@ add_definitions (-Dattr_container_malloc=bh_malloc) add_definitions (-Dattr_container_free=bh_free) add_definitions (-DLV_CONF_INCLUDE_SIMPLE) +if ("${ENABLE_GUI}" STREQUAL "YES") + add_definitions (-DWASM_ENABLE_GUI=1) +endif() + add_library (vmlib ${WASM_PLATFORM_LIB_SOURCE} ${WASM_UTILS_LIB_SOURCE} @@ -101,7 +108,12 @@ add_library (vmlib ${NATIVE_INTERFACE_SOURCE} ) +if ("${ENABLE_GUI}" STREQUAL "YES") add_executable (simple src/main.c src/iwasm_main.c src/ext_lib_export.c ${LV_DRIVERS_SOURCES}) + target_link_libraries (simple vmlib -lm -ldl -lpthread -lSDL2) +else () + add_executable (simple src/main.c src/iwasm_main.c src/ext_lib_export.c) + target_link_libraries (simple vmlib -lm -ldl -lpthread) +endif () -target_link_libraries (simple vmlib -lm -ldl -lpthread -lSDL2) diff --git a/samples/simple/README.md b/samples/simple/README.md index 2f8626c1..0372ff8b 100644 --- a/samples/simple/README.md +++ b/samples/simple/README.md @@ -28,6 +28,8 @@ simple/ - build.sh
The script to build all binaries. +- build_no_gui.sh
+ The script to build all binaries without gui library support. - CMakeLists.txt
CMake file used to build the simple application. - README.md
@@ -101,6 +103,9 @@ Build all binaries Execute the build.sh script then all binaries including wasm application files would be generated in 'out' directory. `./build.sh` +Or execute the build_no_gui.sh script to build all binaries without gui library support. +`./build_no_gui.sh` + Out directory structure ------------------------------ ``` diff --git a/samples/simple/build.sh b/samples/simple/build.sh index f803fff0..5289098f 100755 --- a/samples/simple/build.sh +++ b/samples/simple/build.sh @@ -32,7 +32,7 @@ echo "#####################build simple project" cd ${CURR_DIR} mkdir -p cmake_build cd cmake_build -cmake .. +cmake -DENABLE_GUI=YES .. make if [ $? != 0 ];then echo "BUILD_FAIL simple exit as $?\n" @@ -66,6 +66,7 @@ OUT_FILE=${i%.*}.wasm emcc -O3 -I${APP_LIBS}/base -I${APP_LIBS}/extension/sensor -I${NATIVE_LIBS} \ -I${APP_LIBS}/extension/connection \ -I${APP_LIBS}/extension/gui \ + -DENABLE_WGL=1 \ -s WASM=1 -s SIDE_MODULE=1 -s ASSERTIONS=1 -s STACK_OVERFLOW_CHECK=2 \ -s TOTAL_MEMORY=65536 -s TOTAL_STACK=4096 \ -s "EXPORTED_FUNCTIONS=['_on_init', '_on_destroy', '_on_request', '_on_response', \ diff --git a/samples/simple/build_no_gui.sh b/samples/simple/build_no_gui.sh new file mode 100755 index 00000000..0e959e4e --- /dev/null +++ b/samples/simple/build_no_gui.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +CURR_DIR=$PWD +WAMR_DIR=${PWD}/../.. +OUT_DIR=${PWD}/out +BUILD_DIR=${PWD}/build + +IWASM_ROOT=${PWD}/../../core/iwasm +APP_LIBS=${IWASM_ROOT}/lib/app-libs +NATIVE_LIBS=${IWASM_ROOT}/lib/native-interface +APP_LIB_SRC="${APP_LIBS}/base/*.c ${APP_LIBS}/extension/sensor/*.c ${APP_LIBS}/extension/connection/*.c ${NATIVE_LIBS}/*.c" +WASM_APPS=${PWD}/wasm-apps + +rm -rf ${OUT_DIR} +mkdir ${OUT_DIR} +mkdir ${OUT_DIR}/wasm-apps + +cd ${WAMR_DIR}/core/shared-lib/mem-alloc +if [ ! -d "tlsf" ]; then + git clone https://github.com/mattconte/tlsf +fi + +echo "#####################build simple project" +cd ${CURR_DIR} +mkdir -p cmake_build +cd cmake_build +cmake -DENABLE_GUI=NO .. +make +if [ $? != 0 ];then + echo "BUILD_FAIL simple exit as $?\n" + exit 2 +fi +cp -a simple ${OUT_DIR} +echo "#####################build simple project success" + +echo "#####################build host-tool" +cd ${WAMR_DIR}/test-tools/host-tool +mkdir -p bin +cd bin +cmake .. +make +if [ $? != 0 ];then + echo "BUILD_FAIL host tool exit as $?\n" + exit 2 +fi +cp host_tool ${OUT_DIR} +echo "#####################build host-tool success" + + +echo "#####################build wasm apps" + +cd ${WASM_APPS} + +for i in `ls *.c | grep -v gui` +do +APP_SRC="$i ${APP_LIB_SRC}" +OUT_FILE=${i%.*}.wasm +emcc -O3 -I${APP_LIBS}/base -I${APP_LIBS}/extension/sensor -I${NATIVE_LIBS} \ + -I${APP_LIBS}/extension/connection \ + -s WASM=1 -s SIDE_MODULE=1 -s ASSERTIONS=1 -s STACK_OVERFLOW_CHECK=2 \ + -s TOTAL_MEMORY=65536 -s TOTAL_STACK=4096 \ + -s "EXPORTED_FUNCTIONS=['_on_init', '_on_destroy', '_on_request', '_on_response', \ + '_on_sensor_event', '_on_timer_callback', '_on_connection_data']" \ + -o ${OUT_DIR}/wasm-apps/${OUT_FILE} ${APP_SRC} +if [ -f ${OUT_DIR}/wasm-apps/${OUT_FILE} ]; then + echo "build ${OUT_FILE} success" +else + echo "build ${OUT_FILE} fail" +fi +done +echo "#####################build wasm apps done" diff --git a/samples/simple/src/ext_lib_export.c b/samples/simple/src/ext_lib_export.c index 1ba108a0..4e7b13b6 100644 --- a/samples/simple/src/ext_lib_export.c +++ b/samples/simple/src/ext_lib_export.c @@ -1,12 +1,17 @@ #include "lib_export.h" #include "sensor_api.h" #include "connection_api.h" + +#if WASM_ENABLE_GUI != 0 #include "gui_api.h" +#endif static NativeSymbol extended_native_symbol_defs[] = { #include "runtime_sensor.inl" #include "connection.inl" +#if WASM_ENABLE_GUI != 0 #include "wamr_gui.inl" +#endif }; #include "ext_lib_export.h" diff --git a/samples/simple/src/iwasm_main.c b/samples/simple/src/iwasm_main.c index 24f9c95f..3eaf5f8e 100644 --- a/samples/simple/src/iwasm_main.c +++ b/samples/simple/src/iwasm_main.c @@ -33,8 +33,10 @@ #include "module_wasm_app.h" #include "wasm_export.h" +#if WASM_ENABLE_GUI != 0 #include "lv_drivers/display/monitor.h" #include "lv_drivers/indev/mouse.h" +#endif #define MAX 2048 @@ -430,6 +432,7 @@ static bool parse_args(int argc, char *argv[]) return true; } +#if WASM_ENABLE_GUI != 0 /** * Initialize the Hardware Abstraction Layer (HAL) for the Littlev graphics library */ @@ -461,6 +464,8 @@ static void hal_init(void) indev_drv.read_cb = mouse_read; /*This function will be called periodically (by the library) to get the mouse position and state*/ lv_indev_drv_register(&indev_drv); } +#endif + // Driver function int iwasm_main(int argc, char *argv[]) { @@ -484,8 +489,11 @@ int iwasm_main(int argc, char *argv[]) goto fail1; } +#if WASM_ENABLE_GUI != 0 wgl_init(); hal_init(); +#endif + init_sensor_framework(); // timer manager