forked from replit-archive/emscripted-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeruby
executable file
·74 lines (63 loc) · 2.3 KB
/
makeruby
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
################################################################################
# Config #
################################################################################
# What extra flags to pass to the C compiler.
FLAGS=" -fno-operator-names -fpermissive"
# Whether the build should include Emscripten's reloop optimizations (0/1).
RELOOP=0
# The amount of memory to preinitialize at runtime (tweak until v8 stops being
# incredibly slow).
PREINITIALIZED_MEMORY=3145728
# Where the Ruby library will reside, relative to the core JS file.
RUBY_LIB_PATH=lib
# Whether to run the Closure Compiler on the result (0/1).
RUN_CLOSURE=1
# Where the Closure Compiler JAR can be found. Unused if RUN_CLOSURE=0.
CLOSURE_JAR=/home/max/emscripten-workspace/closure/build/compiler.jar
################################################################################
# Script #
################################################################################
EMSCRIPTEN=`pwd`/emscripten
EMMAKEN=$EMSCRIPTEN/tools/emmakenxx.py
CPP=/lib/cpp
case `uname -s` in
Darwin)
CPP=/usr/bin/cpp
;;
esac
set -e
cd ruby-1.8.7
echo 'Compiling to LLVM...'
CFLAGS=$FLAGS RANLIB=$EMMAKEN AR=$EMMAKEN CXX=$EMMAKEN CPP=$CPP CC=$EMMAKEN ./configure --without-pthread
patch config.h < ../config.h.patch
make miniruby
echo 'Running Emscripten...'
$EMSCRIPTEN/emscripten.py \
libruby-static.a.bc \
-m \
-O \
-o ruby.js \
-s EXCEPTION_DEBUG=0 \
-s CORRECT_SIGNS=1 \
-s CORRECT_OVERFLOWS=1 \
-s INVOKE_RUN=0 \
-s SAFE_HEAP=0 \
-s ASSERTIONS=0 \
-s OPTIMIZE=1 \
-s FAST_MEMORY=$PREINITIALIZED_MEMORY \
-s RELOOP=$RELOOP
echo 'Touching up...'
mkdir -p ../dist
cp ruby.js ../dist
cp -r lib ../dist
../map_filesystem.py lib/ >> ../dist/ruby.js
sed -i "s~\", \"./~\", \"./$RUBY_LIB_PATH/~" ../dist/ruby.js
cat ../entry_point.js >> ../dist/ruby.js
echo 'Running eliminator...'
coffee $EMSCRIPTEN/tools/eliminator/eliminator.coffee < ../dist/ruby.js > ../dist/ruby.opt.js
if [ $RUN_CLOSURE -eq 1 ]; then
echo 'Running closure compiler...'
java -Xmx4g -jar $CLOSURE_JAR --compilation_level SIMPLE_OPTIMIZATIONS --js ../dist/ruby.opt.js --js_output_file ../dist/ruby.closure.js
fi;
echo 'Done.'