Browse Source

Merge pull request #2141 from svaarala/use-external-emcc

Use external emcc for Makefile targets
pull/2142/head
Sami Vaarala 5 years ago
committed by GitHub
parent
commit
89741165a9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .gitignore
  2. 47
      Makefile
  3. 44
      doc/emscripten-status.rst
  4. 7
      docker/duktape-base-ubuntu-18.04/Dockerfile

1
.gitignore

@ -42,7 +42,6 @@
/UglifyJS2/ /UglifyJS2/
/closure-compiler/ /closure-compiler/
/linenoise/ /linenoise/
/emscripten/
/underscore/ /underscore/
/lodash/ /lodash/
/lz-string/ /lz-string/

47
Makefile

@ -196,15 +196,13 @@ else
CCLIBS = -lm CCLIBS = -lm
endif endif
# Emscripten options: # Rely on an external, configured 'emcc' command. See docker/ for Docker
# - --memory-init-file 0 to avoid a separate memory init file (this is # images for an example of building a working 'emcc' environment. See
# not mandatory but keeps the result in a single file) # doc/emscripten-status.rst for the Emscripten options used.
# - -DEMSCRIPTEN needed by Duktape for feature detection
# https://github.com/kripken/emscripten/wiki/Optimizing-Code
# http://mozakai.blogspot.fi/2013/08/outlining-workaround-for-jits-and-big.html
# #
# Reducing the TOTAL_MEMORY and TOTAL_STACK values is useful if you run # Reducing the TOTAL_MEMORY and TOTAL_STACK values is useful if you run
# Duktape cmdline with resource limits (i.e. "duk -r test.js"). # Duktape cmdline with resource limits (i.e. "duk -r test.js").
EMCC = emcc
#EMCCOPTS = -s TOTAL_MEMORY=2097152 -s TOTAL_STACK=524288 --memory-init-file 0 #EMCCOPTS = -s TOTAL_MEMORY=2097152 -s TOTAL_STACK=524288 --memory-init-file 0
EMCCOPTS = -O2 -std=c99 -Wall --memory-init-file 0 -s WASM=0 -s POLYFILL_OLD_MATH_FUNCTIONS EMCCOPTS = -O2 -std=c99 -Wall --memory-init-file 0 -s WASM=0 -s POLYFILL_OLD_MATH_FUNCTIONS
EMCCOPTS_DUKVM = -O2 -std=c99 -Wall --memory-init-file 0 -DEMSCRIPTEN -s WASM=0 EMCCOPTS_DUKVM = -O2 -std=c99 -Wall --memory-init-file 0 -DEMSCRIPTEN -s WASM=0
@ -289,7 +287,6 @@ cleanall: clean
@rm -rf lodash @rm -rf lodash
@rm -rf cbor-js @rm -rf cbor-js
@rm -f d067d2f0ca30.tar.bz2 @rm -f d067d2f0ca30.tar.bz2
@rm -rf emscripten
@rm -rf JS-Interpreter @rm -rf JS-Interpreter
@rm -f compiler-latest.zip @rm -f compiler-latest.zip
@rm -f compiler.jar @rm -f compiler.jar
@ -574,8 +571,8 @@ dukd-low-norefc: linenoise prep/duklow-debug-norefc
emduk: emduk.js emduk: emduk.js
cat util/emduk_wrapper.sh | sed "s|WORKDIR|$(shell pwd)|" > $@ cat util/emduk_wrapper.sh | sed "s|WORKDIR|$(shell pwd)|" > $@
chmod ugo+x $@ chmod ugo+x $@
emduk.js: emscripten prep/emduk emduk.js: prep/emduk
emscripten/emcc $(EMCCOPTS) -Iprep/emduk -Iexamples/cmdline -Iextras/print-alert \ $(EMCC) $(EMCCOPTS) -Iprep/emduk -Iexamples/cmdline -Iextras/print-alert \
$(EMDUKOPTS) \ $(EMDUKOPTS) \
prep/emduk/duktape.c examples/cmdline/duk_cmdline.c extras/print-alert/duk_print_alert.c \ prep/emduk/duktape.c examples/cmdline/duk_cmdline.c extras/print-alert/duk_print_alert.c \
-o /tmp/duk-emduk.js -o /tmp/duk-emduk.js
@ -584,8 +581,8 @@ emduk.js: emscripten prep/emduk
# This is a prototype of running Duktape in a web environment with Emscripten, # This is a prototype of running Duktape in a web environment with Emscripten,
# and providing an eval() facility from both sides. This is a placeholder now # and providing an eval() facility from both sides. This is a placeholder now
# and doesn't do anything useful yet. # and doesn't do anything useful yet.
dukweb.js: emscripten prep/dukweb dukweb.js: prep/dukweb
emscripten/emcc $(EMCCOPTS_DUKVM) $(EMCCOPTS_DUKWEB_EXPORT) \ $(EMCC) $(EMCCOPTS_DUKVM) $(EMCCOPTS_DUKWEB_EXPORT) \
-Iprep/dukweb prep/dukweb/duktape.c dukweb/dukweb.c -o dukweb.js -Iprep/dukweb prep/dukweb/duktape.c dukweb/dukweb.c -o dukweb.js
cat dukweb/dukweb_extra.js >> dukweb.js cat dukweb/dukweb_extra.js >> dukweb.js
@wc dukweb.js @wc dukweb.js
@ -725,20 +722,20 @@ test262cat: test262-es5-tests
@echo "NOTE: this Makefile target will print a 'No rule...' error, ignore it" >&2 @echo "NOTE: this Makefile target will print a 'No rule...' error, ignore it" >&2
-@cd $<; $(PYTHON) tools/packaging/test262.py --command "../duk {{path}}" --cat $(filter-out $@,$(MAKECMDGOALS)) -@cd $<; $(PYTHON) tools/packaging/test262.py --command "../duk {{path}}" --cat $(filter-out $@,$(MAKECMDGOALS))
.PHONY: emscriptentest .PHONY: emscriptentest
emscriptentest: emscripten duk emscriptentest: duk
@echo "### emscriptentest" @echo "### emscriptentest"
@rm -f /tmp/duk-emcc-test* @rm -f /tmp/duk-emcc-test*
emscripten/emcc $(EMCCOPTS) tests/emscripten/helloworld.c -o /tmp/duk-emcc-test.js $(EMCC) $(EMCCOPTS) tests/emscripten/helloworld.c -o /tmp/duk-emcc-test.js
cat /tmp/duk-emcc-test.js | $(PYTHON) util/fix_emscripten.py > /tmp/duk-emcc-test-fixed.js cat /tmp/duk-emcc-test.js | $(PYTHON) util/fix_emscripten.py > /tmp/duk-emcc-test-fixed.js
@ls -l /tmp/duk-emcc-test* @ls -l /tmp/duk-emcc-test*
#./duk /tmp/duk-emcc-test-fixed.js #./duk /tmp/duk-emcc-test-fixed.js
./duk /tmp/duk-emcc-test.js | tee /tmp/duk-emcc-test.out ./duk /tmp/duk-emcc-test.js | tee /tmp/duk-emcc-test.out
if [ `md5sum /tmp/duk-emcc-test.out | cut -f 1 -d ' '` != "59ca0efa9f5633cb0371bbc0355478d8" ]; then false; fi if [ `md5sum /tmp/duk-emcc-test.out | cut -f 1 -d ' '` != "59ca0efa9f5633cb0371bbc0355478d8" ]; then false; fi
.PHONY: emscriptenmandeltest .PHONY: emscriptenmandeltest
emscriptenmandeltest: emscripten duk emscriptenmandeltest: duk
@echo "### emscriptenmandeltest" @echo "### emscriptenmandeltest"
@rm -f /tmp/duk-emcc-test* @rm -f /tmp/duk-emcc-test*
emscripten/emcc $(EMCCOPTS) tests/emscripten/mandelbrot.c -o /tmp/duk-emcc-test.js $(EMCC) $(EMCCOPTS) tests/emscripten/mandelbrot.c -o /tmp/duk-emcc-test.js
cat /tmp/duk-emcc-test.js | $(PYTHON) util/fix_emscripten.py > /tmp/duk-emcc-test-fixed.js cat /tmp/duk-emcc-test.js | $(PYTHON) util/fix_emscripten.py > /tmp/duk-emcc-test-fixed.js
@ls -l /tmp/duk-emcc-test* @ls -l /tmp/duk-emcc-test*
#./duk /tmp/duk-emcc-test-fixed.js #./duk /tmp/duk-emcc-test-fixed.js
@ -747,10 +744,10 @@ emscriptenmandeltest: emscripten duk
# Compile Duktape and hello.c using Emscripten and execute the result with # Compile Duktape and hello.c using Emscripten and execute the result with
# Duktape. # Duktape.
.PHONY: emscripteninceptiontest .PHONY: emscripteninceptiontest
emscripteninceptiontest: emscripten prep/nondebug duk emscripteninceptiontest: prep/nondebug duk
@echo "### emscripteninceptiontest" @echo "### emscripteninceptiontest"
@rm -f /tmp/duk-emcc-test* @rm -f /tmp/duk-emcc-test*
emscripten/emcc $(EMCCOPTS) -Iprep/nondebug prep/nondebug/duktape.c examples/hello/hello.c -o /tmp/duk-emcc-test.js $(EMCC) $(EMCCOPTS) -Iprep/nondebug prep/nondebug/duktape.c examples/hello/hello.c -o /tmp/duk-emcc-test.js
cat /tmp/duk-emcc-test.js | $(PYTHON) util/fix_emscripten.py > /tmp/duk-emcc-test-fixed.js cat /tmp/duk-emcc-test.js | $(PYTHON) util/fix_emscripten.py > /tmp/duk-emcc-test-fixed.js
@ls -l /tmp/duk-emcc-test* @ls -l /tmp/duk-emcc-test*
#./duk /tmp/duk-emcc-test-fixed.js #./duk /tmp/duk-emcc-test-fixed.js
@ -758,10 +755,10 @@ emscripteninceptiontest: emscripten prep/nondebug duk
if [ `md5sum /tmp/duk-emcc-test.out | cut -f 1 -d ' '` != "8521f9d969cdc0a2fa26661a151cef04" ]; then false; fi if [ `md5sum /tmp/duk-emcc-test.out | cut -f 1 -d ' '` != "8521f9d969cdc0a2fa26661a151cef04" ]; then false; fi
# Compile Duktape with Emscripten and execute it with NodeJS. # Compile Duktape with Emscripten and execute it with NodeJS.
.PHONY: emscriptenduktest .PHONY: emscriptenduktest
emscriptenduktest: emscripten prep/emduk emscriptenduktest: prep/emduk
@echo "### emscriptenduktest" @echo "### emscriptenduktest"
@rm -f /tmp/duk-emcc-duktest.js @rm -f /tmp/duk-emcc-duktest.js
emscripten/emcc $(EMCCOPTS_DUKVM) -Iprep/emduk prep/emduk/duktape.c examples/eval/eval.c -o /tmp/duk-emcc-duktest.js $(EMCC) $(EMCCOPTS_DUKVM) -Iprep/emduk prep/emduk/duktape.c examples/eval/eval.c -o /tmp/duk-emcc-duktest.js
"$(NODE)" /tmp/duk-emcc-duktest.js \ "$(NODE)" /tmp/duk-emcc-duktest.js \
'print("Hello from Duktape running inside Emscripten/NodeJS");' \ 'print("Hello from Duktape running inside Emscripten/NodeJS");' \
'for(i=0;i++<100;)print((i%3?"":"Fizz")+(i%5?"":"Buzz")||i)' | tee /tmp/duk-emcc-duktest-1.out 'for(i=0;i++<100;)print((i%3?"":"Fizz")+(i%5?"":"Buzz")||i)' | tee /tmp/duk-emcc-duktest-1.out
@ -775,10 +772,10 @@ LUASRC= lapi.c lauxlib.c lbaselib.c lbitlib.c lcode.c lcorolib.c lctype.c \
lua.c lundump.c lvm.c lzio.c lua.c lundump.c lvm.c lzio.c
# Compile Lua 5.2.3 with Emscripten and run it with Duktape. # Compile Lua 5.2.3 with Emscripten and run it with Duktape.
.PHONY: emscriptenluatest .PHONY: emscriptenluatest
emscriptenluatest: emscripten duk lua-5.2.3 emscriptenluatest: duk lua-5.2.3
@echo "### emscriptenluatest" @echo "### emscriptenluatest"
@rm -f /tmp/duk-emcc-luatest* @rm -f /tmp/duk-emcc-luatest*
emscripten/emcc $(EMCCOPTS) -Ilua-5.2.3/src/ $(patsubst %,lua-5.2.3/src/%,$(LUASRC)) -o /tmp/duk-emcc-luatest.js $(EMCC) $(EMCCOPTS) -Ilua-5.2.3/src/ $(patsubst %,lua-5.2.3/src/%,$(LUASRC)) -o /tmp/duk-emcc-luatest.js
cat /tmp/duk-emcc-luatest.js | $(PYTHON) util/fix_emscripten.py > /tmp/duk-emcc-luatest-fixed.js cat /tmp/duk-emcc-luatest.js | $(PYTHON) util/fix_emscripten.py > /tmp/duk-emcc-luatest-fixed.js
@ls -l /tmp/duk-emcc-luatest* @ls -l /tmp/duk-emcc-luatest*
#./duk /tmp/duk-emcc-luatest-fixed.js #./duk /tmp/duk-emcc-luatest-fixed.js
@ -876,14 +873,6 @@ es5-tests.zip:
test262-es5-tests: es5-tests.zip test262-es5-tests: es5-tests.zip
unzip -q $< unzip -q $<
touch $@ touch $@
emscripten:
# https://github.com/kripken/emscripten
# Master is OK because not a critical dependency
# Setup is complicated because needs matching fastcomp which
# you must provide yourself and add to ~/.emscripten:
# http://kripken.github.io/emscripten-site/docs/building_from_source/building_fastcomp_manually_from_source.html
$(GIT) clone --depth 1 https://github.com/kripken/emscripten.git
cd emscripten; ./emconfigure
jquery-1.11.2.js: jquery-1.11.2.js:
$(WGET) http://code.jquery.com/jquery-1.11.2.js -O $@ $(WGET) http://code.jquery.com/jquery-1.11.2.js -O $@
lua-5.2.3.tar.gz: lua-5.2.3.tar.gz:

44
doc/emscripten-status.rst

@ -7,7 +7,7 @@ Hello world test
Quick hello world test:: Quick hello world test::
$ ./emcc --memory-init-file 0 \ $ emcc --memory-init-file 0 \
-s WASM=0 -s POLYFILL_OLD_MATH_FUNCTIONS=1 \ -s WASM=0 -s POLYFILL_OLD_MATH_FUNCTIONS=1 \
tests/hello_world.cpp -o /tmp/test.js tests/hello_world.cpp -o /tmp/test.js
$ duk /tmp/test.js $ duk /tmp/test.js
@ -45,42 +45,14 @@ Changes in Duktape versions:
$ python $DUKTAPE/util/fix_emscripten.py < /tmp/test.js > /tmp/test-fixed.js $ python $DUKTAPE/util/fix_emscripten.py < /tmp/test.js > /tmp/test-fixed.js
Setting up fastcomp for Duktape Setting up emcc for Duktape
=============================== ===========================
To build dukweb.js and to use Makefile targets like ``emscriptentest`` you See docker/ for Docker image files which set up a working ``emcc``.
need Emscripten "fastcomp". Example steps to setup emscripten:
* Compile fastcomp manually: See also
========
- https://kripken.github.io/emscripten-site/docs/building_from_source/building_fastcomp_manually_from_source.html * https://github.com/kripken/emscripten/wiki/Optimizing-Code
- The ``LLVM_ROOT`` path in the documentation seems to be outdated, * http://mozakai.blogspot.fi/2013/08/outlining-workaround-for-jits-and-big.html
``.../build/bin`` should apparently be ``.../build/Release/bin``
* Checkout emscripten::
$ cd (duktape)
$ make emscripten # duktape checkouts emscripten master
* Create a ``~/.emscripten`` file which uses your manually compiled fastcomp.
You can create a default configuration as follows::
$ cd (duktape)/emscripten
$ ./emcc # creates ~/.emscripten if it doesn't exist
Then change Emscripten to use the manually compiled fastcomp by changing
the LLVM_ROOT line in ``~/.emscripten`` to point to your fastcomp build::
LLVM_ROOT = '/home/user/myfastcomp/emscripten-fastcomp/build/Release/bin'
You should now be able to build dukweb.js and run Emscripten Makefile
targets::
$ make emscripteninceptiontest
[...]
emscripten/emcc -O2 -std=c99 -Wall --memory-init-file 0 -Idist/src dist/src/duktape.c dist/examples/hello/hello.c -o /tmp/duk-emcc-test.js
[...]
./duk /tmp/duk-emcc-test-fixed.js
Hello world!
2+3=5

7
docker/duktape-base-ubuntu-18.04/Dockerfile

@ -85,10 +85,15 @@ RUN echo "=== Prepare duktape-prep repo ===" && \
cd duktape-prep && \ cd duktape-prep && \
make runtestsdeps linenoise UglifyJS2 && \ make runtestsdeps linenoise UglifyJS2 && \
make duktape-releases lz-string jquery-1.11.2.js && \ make duktape-releases lz-string jquery-1.11.2.js && \
make emscripten && emscripten/emcc -s WASM=0 -o /tmp/test_mandel2.js misc/test_mandel2.c && ls -l /tmp/test_mandel2.js && rm /tmp/test_mandel2.* && \
make luajs underscore lodash bluebird.js closure-compiler && \ make luajs underscore lodash bluebird.js closure-compiler && \
make clean make clean
# Initialize Emscripten cached bytecode files.
RUN echo "=== Prepare Emscripten cached bytecode files ===" && \
cp -r duktape-prep /tmp/duktape-emcc-init && \
bash -c '. emsdk-portable/emsdk_env.sh && cd /tmp/duktape-emcc-init && make emscriptenluatest dukweb.js' && \
rm -rf /tmp/duktape-emcc-init /tmp/duk-emcc*
# Dump some versions. # Dump some versions.
RUN echo "=== Versions ===" && \ RUN echo "=== Versions ===" && \
echo "GCC:" && gcc -v && \ echo "GCC:" && gcc -v && \

Loading…
Cancel
Save