Moddable-OpenSource / moddable

Tools for developers to create truly open IoT products using standard JavaScript on low cost microcontrollers.
http://www.moddable.com
1.32k stars 236 forks source link

Fail to build with wasm #1034

Open meganetaaan opened 1 year ago

meganetaaan commented 1 year ago

Build environment: Linux (Ubuntu 20.04) and moddable v3.7.0 Target device: wasm

Description

The wasm build fails. There are two problems.

  1. Tool can't build (fixed as below)
  2. When building with -p wasm, I get an error about timer.

Steps to Reproduce

cd ${MODDABLE}/build/makefiles/wasm
make
# tools debug : xsc commodettoBitmap.js
make[1]: /home/sskw/.local/share/moddable/build/bin/lin/debug/xsc: コマンドが見つかりませんでした
make[1]: *** [tools.mk:296: /home/sskw/.local/share/moddable/build/tmp/wasm/debug/tools/modules/commodetto/Bitmap.xsb] エラー 127
make[1]: ディレクトリ '/home/sskw/.local/share/moddable/build/makefiles/wasm' から出ます
make: *** [makefile:29: debug] エラー 2

After fixing the failed command of makefile according to other lines $(BIN_DIR)/xsc -> $(XSC) the compile error dessapeared.

But when I try to build examples another error occurs.

build log sskw@sskw-XF:~/.local/share/moddable/examples/piu/balls$ mcconfig -m -d -p wasm # xsc screen.xsb # xsc time.xsb # xsc timer.xsb # xsc Resource.xsb # xsc main.xsb # xsc commodetto/Bitmap.xsb # xsc commodetto/Poco.xsb # xsc commodetto/parseBMP.xsb # xsc commodetto/parseRLE.xsb # xsc piu/All.xsb # xsc piu/Timeline.xsb # xsc piu/CombTransition.xsb # xsc piu/MC.xsb # xsc piu/WipeTransition.xsb # xsc mc/config.xsb # xsid screen.c.xsi # xsid modTime.c.xsi # xsid modTimer.c.xsi # xsid timer.c.xsi # xsid Resource.c.xsi # xsid modInstrumentation.c.xsi # xsid piuDie.c.xsi # xsid piuFont.c.xsi # xsid piuImage.c.xsi # xsid piuRegion.c.xsi # xsid piuTexture.c.xsi # xsid piuView.c.xsi # xsid commodettoBitmap.c.xsi # xsid commodettoPoco.c.xsi # xsid commodettoPocoBlit.c.xsi # xsid cfeBMF.c.xsi # xsid commodettoParseBMP.c.xsi # xsid commodettoParseRLE.c.xsi # xsid piuApplication.c.xsi # xsid piuBehavior.c.xsi # xsid piuColor.c.xsi # xsid piuColumn.c.xsi # xsid piuContainer.c.xsi # xsid piuContent.c.xsi # xsid piuLabel.c.xsi # xsid piuLayout.c.xsi # xsid piuLocals.c.xsi # xsid piuPort.c.xsi # xsid piuRectangle.c.xsi # xsid piuRow.c.xsi # xsid piuScroller.c.xsi # xsid piuSkin.c.xsi # xsid piuStyle.c.xsi # xsid piuText.c.xsi # xsid piuTimeline.c.xsi # xsid piuTransition.c.xsi # xsid screen.h.xsi # xsid modTimer.h.xsi # xsid modInstrumentation.h.xsi # xsid commodettoBitmap.h.xsi # xsid commodettoPoco.h.xsi # xsid commodettoPocoBlit.h.xsi # xsid piuAll.h.xsi # xsid piuMC.h.xsi # png2bmp balls-color.bmp balls-alpha.bmp # cc main.c # cp index.html # xsl modules # mcrez resources Total resource size: 9188 bytes # cc mc.resources.c ### 524 instances, 967 keys, 92 colors, 0 holes # cc mc.xs.c # cc screen.c.o # cc modTime.c.o # cc modTimer.c.o # cc timer.c.o # cc Resource.c.o # cc modInstrumentation.c.o # cc piuDie.c.o # cc piuFont.c.o # cc piuImage.c.o # cc piuRegion.c.o # cc piuTexture.c.o # cc piuView.c.o # cc commodettoBitmap.c.o # cc commodettoPoco.c.o # cc commodettoPocoBlit.c.o # cc cfeBMF.c.o # cc commodettoParseBMP.c.o # cc commodettoParseRLE.c.o # cc piuApplication.c.o # cc piuBehavior.c.o # cc piuColor.c.o # cc piuColumn.c.o # cc piuContainer.c.o # cc piuContent.c.o # cc piuLabel.c.o /home/sskw/.local/share/moddable/modules/commodetto/commodettoParseBMP.c:74:6: warning: misleading indentation; statement is not part of the previous 'if' [-Wmisleading-indentation] return; ^ /home/sskw/.local/share/moddable/modules/commodetto/commodettoParseBMP.c:72:5: note: previous statement is here if ((gray != c_read8(bytes + palette + 0)) || (gray != c_read8(bytes + palette + 1)) || (gray != c_read8(bytes + palette + 2))) ^ # cc piuLayout.c.o 1 warning generated. # cc piuLocals.c.o # cc piuPort.c.o # cc piuRectangle.c.o # cc piuRow.c.o # cc piuScroller.c.o # cc piuSkin.c.o # cc piuStyle.c.o # cc piuText.c.o # cc piuTimeline.c.o # cc piuTransition.c.o # cc mc.js wasm-ld: error: duplicate symbol: xs_timer_set >>> defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/modTimer.c.o >>> defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/timer.c.o wasm-ld: error: duplicate symbol: xs_timer_repeat >>> defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/modTimer.c.o >>> defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/timer.c.o wasm-ld: error: duplicate symbol: xs_timer_schedule >>> defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/modTimer.c.o >>> defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/timer.c.o wasm-ld: error: duplicate symbol: xs_timer_clear >>> defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/modTimer.c.o >>> defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/timer.c.o wasm-ld: error: duplicate symbol: xs_timer_delay >>> defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/modTimer.c.o >>> defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/timer.c.o emcc: error: '/home/sskw/.local/share/wasm/emsdk/upstream/bin/wasm-ld -o /home/sskw/.local/share/moddable/build/bin/wasm/debug/balls/mc.wasm /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/wasm_xs.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsAll.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsAPI.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsArguments.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsArray.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsAtomics.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsBigInt.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsBoolean.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsCode.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsCommon.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsDataView.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsDate.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsDebug.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsError.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsFunction.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsGenerator.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsGlobal.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsJSON.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsLexical.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsMapSet.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsMarshall.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsMath.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsMemory.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsModule.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsNumber.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsObject.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsPlatforms.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsPromise.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsProperty.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsProxy.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsRegExp.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsRun.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsScope.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsScript.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsSourceMap.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsString.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsSymbol.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsSyntaxical.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsTree.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsType.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsdtoa.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsmc.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/lib/xsre.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/mc.xs.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/mc.resources.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/screen.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/modTime.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/modTimer.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/timer.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/Resource.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/modInstrumentation.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuDie.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuFont.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuImage.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuRegion.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuTexture.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuView.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/commodettoBitmap.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/commodettoPoco.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/commodettoPocoBlit.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/cfeBMF.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/commodettoParseBMP.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/commodettoParseRLE.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuApplication.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuBehavior.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuColor.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuColumn.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuContainer.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuContent.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuLabel.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuLayout.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuLocals.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuPort.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuRectangle.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuRow.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuScroller.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuSkin.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuStyle.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuText.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuTimeline.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/piuTransition.c.o /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/mc.main.c.o -L/home/sskw/.local/share/wasm/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -lGL -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --allow-undefined-file=/tmp/tmprfg77hgt.undefined --strip-debug --export-if-defined=fxMainIdle --export-if-defined=fxMainLaunch --export-if-defined=fxMainQuit --export-if-defined=fxMainTouch --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=fflush --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=stackSave --export=stackRestore --export=stackAlloc --export=__wasm_call_ctors --export=__errno_location --export=__get_temp_ret --export=__set_temp_ret --export=malloc --export=free --export=saveSetjmp --export=setThrew --export-table -z stack-size=65536 --initial-memory=16777216 --no-entry --max-memory=2147483648 --stack-first' failed (returned 1) make: *** [/home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/makefile:341: /home/sskw/.local/share/moddable/build/bin/wasm/debug/balls/mc.js] エラー 1
meganetaaan commented 1 year ago

The post above was ambiguous. The "another error" is this part.

wasm-ld: error: duplicate symbol: xs_timer_repeat

defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/modTimer.c.o
defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/timer.c.o

wasm-ld: error: duplicate symbol: xs_timer_schedule

defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/modTimer.c.o
defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/timer.c.o

wasm-ld: error: duplicate symbol: xs_timer_clear

defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/modTimer.c.o
defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/timer.c.o

wasm-ld: error: duplicate symbol: xs_timer_delay

defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/modTimer.c.o
defined in /home/sskw/.local/share/moddable/build/tmp/wasm/debug/balls/timer.c.o
emcc: error: '/home/sskw/.local/share/wasm/emsdk/upstream/bin/wasm-ld -o /home/sskw/.local/share/moddable/build/bin/wasm/debug/balls/mc.wasm
...

I checked the current implementations of timer module. Other platforms follow the latest interface of the Timer class, but it seems that the wasm timer implementation does not follow it?

phoddie commented 1 year ago

Thanks for the additional details. It looks like something got out of sync in the building of timer for wasm. While other platforms use both modTimer.c and a platform specific timer.c, the wasm port merges those into its timer.c. That's not incorrect, but the inconsistency seems to have created a build mixup. I think this is the commit that introduced the problem, specifically with simulators/manifest.json. Unfortunately, my wasm tooling is not set-up, so I can't easily try. Maybe you can?

meganetaaan commented 1 year ago

After reverting the commit Moddable successfully builds the wasm target!

https://twitter.com/meganetaaan/status/1640393426243035136

I believe our next step should be to make build/simulators/manifest.json compatible with both 'wasm' and other simulator platforms.

phoddie commented 1 year ago

After reverting the commit Moddable successfully builds the wasm target!

That makes sense. Thank you for confirming.