spcomp (Emscripten)

From AlliedModders Wiki
Jump to: navigation, search

In sourcepawn/compiler, clone Emscripten to ./emscripten and copy ../../plugins/include to ./include.

Make sure you run the tests from https://github.com/kripken/emscripten/wiki/Tutorial.

You need to compile the LZMA encoder for compression to work:

cd ./emscripten/third_party/lzma.js
./doit.sh
cd ../../../
emscripten/emcc -O0 --closure 0 -DNDEBUG -fno-strict-aliasing -I . -I ../../public/ -I ../../public/sourcepawn/ \
-D_GNU_SOURCE -Wall -DLINUX -DHAVE_STDINT_H -DAMX_ANSIONLY -Dstricmp=strcasecmp -m32 -fno-exceptions -fno-rtti \
binreloc.c libpawnc.c lstring.c memfile.c pawncc.c sc1.c sc2.c sc3.c sc4.c sc5.c sc6.c sc7.c scexpand.c sci18n.c sclist.c \
scmemfil.c scstate.c sctracker.c scvars.c sp_file.c sp_symhash.c zlib/adler32.c zlib/compress.c zlib/crc32.c zlib/deflate.c \
zlib/gzio.c zlib/infback.c zlib/inffast.c zlib/inflate.c zlib/inftrees.c zlib/trees.c zlib/uncompr.c zlib/zutil.c \
--compression emscripten/third_party/lzma.js/lzma-native,emscripten/third_party/lzma.js/lzma-decoder.js,LZMA.decompress \
-o spcomp.html --preload-file include -Wno-format -Wno-parentheses -Wno-unused -Wno-sometimes-uninitialized -funroll-loops \
-ldl -lm -lgcc -s UNALIGNED_MEMORY=1

Enabling optimisations currently breaks emcc, leave them disabled.

UPDATE: Due to a small patch to spcomp, optimisation is now possible. You can also enable the closure compiler if you're writing your own frontend.

emscripten/emcc -O3 --closure 0 -DNDEBUG -fno-strict-aliasing -I . -I ../../public/ -I ../../public/sourcepawn/ \
-D_GNU_SOURCE -Wall -DLINUX -DHAVE_STDINT_H -DAMX_ANSIONLY -Dstricmp=strcasecmp -m32 -fno-exceptions -fno-rtti \
binreloc.c libpawnc.c lstring.c memfile.c pawncc.c sc1.c sc2.c sc3.c sc4.c sc5.c sc6.c sc7.c scexpand.c sci18n.c sclist.c \
scmemfil.c scstate.c sctracker.c scvars.c sp_file.c sp_symhash.c zlib/adler32.c zlib/compress.c zlib/crc32.c zlib/deflate.c \
zlib/gzio.c zlib/infback.c zlib/inffast.c zlib/inflate.c zlib/inftrees.c zlib/trees.c zlib/uncompr.c zlib/zutil.c \
--compression emscripten/third_party/lzma.js/lzma-native,emscripten/third_party/lzma.js/lzma-decoder.js,LZMA.decompress \
-o spcomp.html --preload-file include -Wno-format -Wno-parentheses -Wno-unused -Wno-sometimes-uninitialized -funroll-loops \
-ldl -lm -lgcc

spcomp won't be able to find the include folder automatically, make sure you invoke it with -iinclude.