Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added build script.

  • Loading branch information...
commit 877da0cb9c8f1645729d14ab719b8f69d17590bc 1 parent c78f845
@max99x max99x authored
Showing with 163 additions and 0 deletions.
  1. +34 −0 config.h.patch
  2. +47 −0 entry_point.js
  3. +51 −0 makeruby
  4. +31 −0 map_filesystem.py
View
34 config.h.patch
@@ -0,0 +1,34 @@
+--- config.h 2011-09-13 00:33:28.062630721 +0300
++++ ../config.h 2011-09-13 00:39:52.652623181 +0300
+@@ -138,8 +138,6 @@
+ #define HAVE_DLOPEN 1
+ #define HAVE_SIGPROCMASK 1
+ #define HAVE_SIGACTION 1
+-#define HAVE__SETJMP 1
+-#define HAVE__LONGJMP 1
+ #define HAVE_SETSID 1
+ #define HAVE_TELLDIR 1
+ #define HAVE_SEEKDIR 1
+@@ -155,8 +153,6 @@
+ #define HAVE_SETGID 1
+ #define HAVE_SETENV 1
+ #define HAVE_UNSETENV 1
+-#define RUBY_SETJMP(env) _setjmp(env)
+-#define RUBY_LONGJMP(env,val) _longjmp(env,val)
+ #define RUBY_JMP_BUF jmp_buf
+ #define HAVE_STRUCT_TM_TM_ZONE 1
+ #define HAVE_TM_ZONE 1
+@@ -187,3 +183,13 @@
+ #define RUBY_ARCHLIB "/usr/local/lib/ruby/1.8/x86_64-linux"
+ #define RUBY_SITE_ARCHLIB "/usr/local/lib/ruby/site_ruby/1.8/x86_64-linux"
+ #define RUBY_VENDOR_ARCHLIB "/usr/local/lib/ruby/vendor_ruby/1.8/x86_64-linux"
++
++/* emscripten */
++#define RUBY_SETJMP(env) emscripten_setjmp(env)
++#define RUBY_LONGJMP(env,val) emscripten_longjmp(env,val)
++#include <setjmp.h>
++int emscripten_setjmp(jmp_buf env);
++void emscripten_longjmp(jmp_buf env, int ret);
++#define ANYARGS ...
++#include <unistd.h>
++/* /emscripten */
View
47 entry_point.js
@@ -0,0 +1,47 @@
+this['Ruby'] = {
+ // Initializes the Ruby runtime with optional standard I/O callbacks.
+ 'initialize': function(input, output, error) {
+ if (this.isInitialized) {
+ console.log('Ignoring repeated Ruby initialization.');
+ return;
+ }
+ FS.init(input, output, error);
+ run();
+
+ // Wheee, infinite stack!
+ var variable_in_this_stack_frame = allocate(4, 'i32', ALLOC_STACK);
+ _ruby_init_stack(variable_in_this_stack_frame);
+ _ruby_stack_check = function () { return false; };
+
+ _ruby_init();
+ var includeStr = Ruby.allocateString('.');
+ __ZL12push_includePKc(includeStr);
+ _free(includeStr);
+ this.isInitialized = true;
+ },
+ // Evaluates a Ruby expression and returns the result.
+ 'eval': function(command) {
+ if (!this.isInitialized) throw new Error('Ruby runtime not initialized.');
+ var commandPtr = this.allocateString(command);
+ try {
+ var result = _rb_eval_string(commandPtr);
+ } catch (e) {
+ // Null exceptions are side effects from the setjmp conversion and are
+ // used just to unwind the stack. We can ignore them.
+ if (e !== 0) throw e;
+ }
+ _free(commandPtr);
+ return result;
+ },
+ // Converts a Ruby value to a string representation (inspect method).
+ 'stringify': function(value) {
+ var ptr = allocate([_rb_inspect(value),0,0,0], ['i32',0,0,0], ALLOC_NORMAL);
+ var str = Pointer_stringify(_rb_string_value_ptr(ptr));
+ _free(ptr);
+ return str;
+ },
+ isInitialized: false,
+ allocateString: function(str) {
+ return allocate(intArrayFromString(str), 'i8', ALLOC_NORMAL);
+ }
+};
View
51 makeruby
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+EMSCRIPTEN_ROOT=/home/max/emscripten-workspace/emscripten
+EMMAKEN=$EMSCRIPTEN_ROOT/tools/emmakenxx.py
+LLVM_DIS=/home/max/emscripten-workspace/llvm-build/Release/bin/llvm-dis
+CLOSURE_JAR=/home/max/emscripten-workspace/closure/build/compiler.jar
+FLAGS=" -fno-operator-names -fpermissive"
+RUBY_LIB_PATH=lib
+RUN_CLOSURE=0
+
+set -e
+
+cd ruby-1.8.7
+
+# echo 'Compiling to LLVM...'
+# CFLAGS=$FLAGS RANLIB=$EMMAKEN AR=$EMMAKEN CXX=$EMMAKEN CC=$EMMAKEN ./configure --without-pthread
+# patch config.h < ../config.h.patch
+# make miniruby
+# $LLVM_DIS --show-annotations libruby-static.a
+#
+# echo 'Running Emscripten...'
+# $EMSCRIPTEN_ROOT/emscripten.py \
+# libruby-static.a.ll \
+# -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
+#
+# 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 /home/max/emscripten-workspace/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 /home/max/emscripten-workspace/closure/build/compiler.jar --compilation_level SIMPLE_OPTIMIZATIONS --js ../dist/ruby.opt.js --js_output_file ../dist/ruby.closure.js
+fi;
+
+echo 'Done.'
View
31 map_filesystem.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python2
+
+import os
+import sys
+
+MAX_SIZE_TO_INLINE = 32
+
+def main(root):
+ os.chdir(root)
+ commands = []
+ for (dirpath, dirnames, filenames) in os.walk('.'):
+ for folder in dirnames:
+ commands.append('FS.createFolder("%s", "%s", true, false);' %
+ (dirpath, folder))
+ for filename in filenames:
+ full_path = os.path.join(dirpath, filename)
+ if os.stat(full_path).st_size <= MAX_SIZE_TO_INLINE:
+ contents = ', '.join(str(ord(i)) for i in open(full_path, 'rb').read())
+ commands.append('FS.createDataFile("%s", "%s", [%s], true, false);' %
+ (dirpath, filename, contents))
+ else:
+ commands.append('FS.createLazyFile("%s", "%s", "%s", true, false);' %
+ (dirpath, filename, full_path))
+
+ print '\n'.join(commands)
+
+if __name__ == '__main__':
+ if len(sys.argv) != 2:
+ print 'Usage: %s root' % sys.argv[0]
+ else:
+ main(sys.argv[1])
Please sign in to comment.
Something went wrong with that request. Please try again.