From 7b4e1795606b10007bfaa5a90216e8228555c59e Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Sun, 14 Jul 2019 16:34:16 +0000 Subject: [PATCH] defined MOO_EXPORT to EMSCRIPTEN_KEEPALIVE for EMSCRIPTEN --- moo/emcc.txt | 77 +++++++++++++++++++++++++++++++++++++++++++++++ moo/lib/moo-cmn.h | 7 ++++- 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 moo/emcc.txt diff --git a/moo/emcc.txt b/moo/emcc.txt new file mode 100644 index 0000000..42cb3f3 --- /dev/null +++ b/moo/emcc.txt @@ -0,0 +1,77 @@ +Temporary notes on how to build libmoo to web assembly with emscripten. + +#### How to Build + mkdir -p bld/emcc + cd blc/emcc + emconfigure ../../configure --prefix=${HOME}/xxx-emcc --disable-shared --enable-dynamic-module --disable-mod-x11 --disable-mod-con --disable-mod-sck CFLAGS="-Wall -O2 -g" + emmake make + ##emcc lib/.libs/libmoo.a -s WASM=1 -s EXPORT_ALL=1 -s LINKABLE=1 -o libmoo.js + #if you have defined MOO_EXPORT as EMSCRIPTEN_KEEPALIVE, the following will do + ##emcc lib/.libs/libmoo.a -s WASM=1 -s -s LINKABLE=1 -o libmoo.js + ###emcc lib/.libs/libmoo.a lib/.libs/libmoox.a -s WASM=1 -s -s LINKABLE=1 -o libmoo.js + emcc lib/.libs/libmoo.a lib/.libs/libmoox.a -s WASM=1 -s -s LINKABLE=1 -s EXTRA_EXPORTED_RUNTIME_METHODS="['ccall']" -o libmoo.js + +#### moo.worker.js + +self.importScripts('libmoo.js'); +self.__ready = false; + +Module.onRuntimeInitialized = function() +{ + self.__ready = true; + console.log ('runtime is ready now...'); +} + +const libmoo = { + open: Module.cwrap('moo_openstd', 'number', ['number', 'number', 'number']), + close: Module.cwrap('moo_close', '', ['number']) +}; + +self.onmessage = function (evt) { + var objData = evt.data; + + var cmd = objData.cmd; + if (cmd === "test-moo") + { + //var x = Module.ccall('moo_openstd', [0, null, null]); + //Module.ccall('moo_close', x); + + if (self.__ready) + { + var moo = libmoo.open(0, null, null); + self.postMessage ('XXXXXXXXXXXXXXXx - ' + moo); + libmoo.close (moo); + } + } +} + +#### moo.html + + + + + + + + + + + + + + + diff --git a/moo/lib/moo-cmn.h b/moo/lib/moo-cmn.h index f3b1d36..a0ce0f8 100644 --- a/moo/lib/moo-cmn.h +++ b/moo/lib/moo-cmn.h @@ -60,6 +60,7 @@ # undef MOO_SIZEOF_LONG # define MOO_SIZEOF_LONG MOO_SIZEOF_INT # endif +# include /* EMSCRIPTEN_KEEPALIVE */ #endif #if defined(__GNUC__) && defined(__arm__) && !defined(__ARM_ARCH) @@ -777,7 +778,11 @@ typedef struct moo_t moo_t; * MACROS THAT CHANGES THE BEHAVIORS OF THE C COMPILER/LINKER * =========================================================================*/ -#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500) +#if defined(EMSCRIPTEN) +# define MOO_IMPORT +# define MOO_EXPORT EMSCRIPTEN_KEEPALIVE +# define MOO_PRIVATE +#elif defined(__BORLANDC__) && (__BORLANDC__ < 0x500) # define MOO_IMPORT # define MOO_EXPORT # define MOO_PRIVATE