Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 75 lines (63 sloc) 2.359 kB
#!/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.'
Jump to Line
Something went wrong with that request. Please try again.