Giter Club home page Giter Club logo

webruby's Introduction

Introduction

This project brings mruby to the browser. It uses [emscripten] (https://github.com/kripken/emscripten) to compile the mruby source code into JavaScript and runs in the browser.

Build Status

Since emscripten SDK does not provide pre-built binaries for Linux, we cannot use Travis CI right now. We want to be nice and don't try to rebuild whole LLVM each time we are pushing new code :)

How to Install

Webruby now depends on emsdk to provide emscripten and LLVM infrustructure. To install webruby, following the following steps:

  1. Install emsdk following instructions at here
  2. Install latest incoming version of emscripten sdk(right now webruby still depends on code from incoming branch of emscripten, once this goes into a release version, we will lock the version for better stability)
  3. Activate latest incoming version
  4. Webruby should be able to pick up the correct version of emscripten from emsdk. If not, feel free to create an issue :)

Notes

Thanks to @scalone and @sadasant, webruby is already used in production: http://rubykaigi.org/2014/presentation/S-ThiagoScalone-DanielRodriguez

However, you might still want to give it a full test before using it in production :)

Demos

  • webruby irb - A nice-looking full-fledged webruby irb. Thanks to @joshnuss for his work!
  • Webruby tutorial - minimal example of webruby project, a full description is at here
  • mruby - This is only a minimal demo of web irb, if you want to try out mruby in a browser, I strongly suggest the demo above.
  • geometries - a WebGL example using webruby, mruby-js and three.js. NOTE: from a practical point of view, I agree that this can be easily implemented using JS. However, this demo shows how easy it is to interact with the JavaScript environment using Ruby.

License

This project is distributed under the MIT License. See LICENSE for further details.

webruby's People

Contributors

amutz avatar sadasant avatar xxuejie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webruby's Issues

ERROR root: compiler frontend failed to generate LLVM bitcode, halting

CC ~/.webruby/gems/mruby-js/src/mruby_js.c -> ~/github/gkostin1966/mruby-web-trello/build/mruby/emscripten/mrbgems/mruby-js/src/mruby_js.o
~/.webruby/gems/mruby-js/src/mruby_js.c:116:10: error: implicit declaration of function 'RSTR_LEN' is invalid in C99
[-Werror,-Wimplicit-function-declaration]
return RSTR_LEN(s);
^
~/.webruby/gems/mruby-js/src/mruby_js.c:126:10: error: implicit declaration of function 'RSTR_PTR' is invalid in C99
[-Werror,-Wimplicit-function-declaration]
return RSTR_PTR(s);
^
~/.webruby/gems/mruby-js/src/mruby_js.c:126:10: warning: incompatible integer to pointer conversion returning 'int' from a function with result type 'char *'
[-Wint-conversion]
return RSTR_PTR(s);
^~~~~~~~~~~
1 warning and 2 errors generated.
ERROR root: compiler frontend failed to generate LLVM bitcode, halting

Using webruby in a Worker

I've been trying to use Webruby in a Worker, almost everything seems to work, but I encounter an Uncaught RangeError: Maximum call stack size exceeded when I try to invoke a javascript function using mruby-js.

It's important to allow people to use webruby in a worker, because emscripten blocks and running complex ruby programs in the browser could make them show errors.

Do you have a clue on how to fix this? If you find some time, I'll be grateful to you.

Open Wiki

Hey, this projet looks pretty awesome!

I'd love to contribute; do you think you could start a GH wiki so I can add a "TODO" (or similar) so we can hash out rough ideas / roadmap?

`sample` method missing on arrays

Hi,

I just discovered this project (which is quite awesome, by the way) and decided to play around with it. One thing that puzzled me is that the sample method doesn't work, i.e. [1, 2, 3].sample. Is this something that's missing from mruby itself? I did some digging, but couldn't find anything about this in the mruby repo, either.

Unable to compile latest webruby

I've just installed llvm, etc. Here's what I get trying to do rake js (early bits omitted):

CC    build/emscripten/mrbgems/gem_init.c -> build/emscripten/mrbgems/gem_init.o
WARNING  root: -I or -L of an absolute path "-I/Users/vwoo/webruby/modules/mruby/include" encountered. If this is to a local system header/library, it may cause problems (local system files make sense for compiling natively on your system, but not necessarily to JavaScript)
clang: warning: argument unused during compilation: '-nostdinc++'
AR    build/emscripten/lib/libmruby.a
/usr/local/bin/llvm-ar: creating /Users/vwoo/webruby/modules/mruby/build/emscripten/lib/libmruby.a
/Users/vwoo/webruby/modules/mruby/build/host/bin/mrbc -Bapp_irep -o/Users/vwoo/webruby/build/rbcode.c /Users/vwoo/webruby/build/rbcode.rb
cat /Users/vwoo/webruby/driver/driver.c /Users/vwoo/webruby/build/rbcode.c > /Users/vwoo/webruby/build/app.c
/Users/vwoo/webruby/modules/emscripten/emcc -Wall -Werror-implicit-function-declaration -I/Users/vwoo/webruby/modules/mruby/include /Users/vwoo/webruby/build/app.c -o /Users/vwoo/webruby/build/app.o
WARNING  root: -I or -L of an absolute path "-I/Users/vwoo/webruby/modules/mruby/include" encountered. If this is to a local system header/library, it may cause problems (local system files make sense for compiling natively on your system, but not necessarily to JavaScript)
clang: warning: argument unused during compilation: '-nostdinc++'
ruby scripts/gen_post.rb 2 /Users/vwoo/webruby/build/js_api.js
Creating new post js file!
ruby scripts/gen_gems_config.rb /Users/vwoo/webruby/build_config.rb /Users/vwoo/webruby/build/js_api.js /Users/vwoo/webruby/build/gem_library.js /Users/vwoo/webruby/build/gem_append.js /Users/vwoo/webruby/build/gem_test_library.js /Users/vwoo/webruby/build/gem_test_append.js /Users/vwoo/webruby/build/functions
Creating new file: /Users/vwoo/webruby/build/gem_library.js!
Creating new file: /Users/vwoo/webruby/build/gem_append.js!
Creating new file: /Users/vwoo/webruby/build/gem_test_library.js!
Creating new file: /Users/vwoo/webruby/build/gem_test_append.js!
/Users/vwoo/webruby/modules/emscripten/emcc /Users/vwoo/webruby/build/app.o /Users/vwoo/webruby/modules/mruby/build/emscripten/lib/libmruby.a -o /Users/vwoo/webruby/build/webruby.js --js-library /Users/vwoo/webruby/build/gem_library.js --pre-js /Users/vwoo/webruby/build/gem_append.js -s EXPORTED_FUNCTIONS="['_mrb_open', '_mrb_close', '_webruby_internal_run', '_webruby_internal_run_bytecode', '_webruby_internal_run_source']" -O0

undefined:374
        throw 'Invalid token, cannot triage: ' + dump(item);
                                               ^
Invalid token, cannot triage: // {
//   "tokens": [
//     {
//       "text": "attributes"
//     },
//     {
//       "text": "#0"
//     },
//     {
//       "text": "="
//     },
//     {
//       "text": "{ nounwind\"less-precise-fpmad\"=\"false\"\"no-frame-pointer-elim\"=\"true\"\"no-frame-pointer-elim-non-leaf\"=\"true\"\"no-infs-fp-math\"=\"false\"\"no-nans-fp-math\"=\"false\"\"unsafe-fp-math\"=\"false\"\"use-soft-float\"=\"false\" }",
//       "tokens": [
//         {
//           "text": "nounwind"
//         },
//         {
//           "text": "\"less-precise-fpmad\""
//         },
//         {
//           "text": "="
//         },
//         {
//           "text": "\"false\""
//         },
//         {
//           "text": "\"no-frame-pointer-elim\""
//         },
//         {
//           "text": "="
//         },
//         {
//           "text": "\"true\""
//         },
//         {
//           "text": "\"no-frame-pointer-elim-non-leaf\""
//         },
//         {
//           "text": "="
//         },
//         {
//           "text": "\"true\""
//         },
//         {
//           "text": "\"no-infs-fp-math\""
//         },
//         {
//           "text": "="
//         },
//         {
//           "text": "\"false\""
//         },
//         {
//           "text": "\"no-nans-fp-math\""
//         },
//         {
//           "text": "="
//         },
//         {
//           "text": "\"false\""
//         },
//         {
//           "text": "\"unsafe-fp-math\""
//         },
//         {
//           "text": "="
//         },
//         {
//           "text": "\"false\""
//         },
//         {
//           "text": "\"use-soft-float\""
//         },
//         {
//           "text": "="
//         },
//         {
//           "text": "\"false\""
//         }
//       ],
//       "type": "{"
//     }
//   ],
//   "indent": 0,
//   "lineNum": 5622,
//   "__uid__": 163
// }
Traceback (most recent call last):
  File "/Users/vwoo/webruby/modules/emscripten/emscripten.py", line 809, in <module>
    _main(environ=os.environ)
  File "/Users/vwoo/webruby/modules/emscripten/emscripten.py", line 797, in _main
    temp_files.run_and_clean(lambda: main(
  File "/Users/vwoo/webruby/modules/emscripten/tools/tempfiles.py", line 38, in run_and_clean
    return func()
  File "/Users/vwoo/webruby/modules/emscripten/emscripten.py", line 805, in <lambda>
    DEBUG_CACHE=DEBUG_CACHE,
  File "/Users/vwoo/webruby/modules/emscripten/emscripten.py", line 691, in main
    jcache=jcache, temp_files=temp_files, DEBUG=DEBUG, DEBUG_CACHE=DEBUG_CACHE)
  File "/Users/vwoo/webruby/modules/emscripten/emscripten.py", line 179, in emscript
    assert '//FORWARDED_DATA:' in out, 'Did not receive forwarded data in pre output - process failed?'
AssertionError: Did not receive forwarded data in pre output - process failed?
Traceback (most recent call last):
  File "/Users/vwoo/webruby/modules/emscripten/emcc", line 1439, in <module>
    final = shared.Building.emscripten(final, append_ext=False, extra_args=extra_args)
  File "/Users/vwoo/webruby/modules/emscripten/tools/shared.py", line 1091, in emscripten
    assert os.path.exists(filename + '.o.js') and len(open(filename + '.o.js', 'r').read()) > 0, 'Emscripten failed to generate .js: ' + str(compiler_output)
AssertionError: Emscripten failed to generate .js:
rake aborted!
Command failed with status (1): [/Users/vwoo/webruby/modules/emscripten/emc...]
/Users/vwoo/webruby/rakelib/build.rake:18:in `block in <top (required)>'
/Users/vwoo/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in `eval'
/Users/vwoo/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => js => /Users/vwoo/webruby/build/webruby.js
(See full trace by running task with --trace)

Refactor webruby to use mrbgem properly

With PR 2924 of mruby(intentionally written this way to not trigger a reference and spamming everyone), we cannot use the hacky way to build mrbtest as it is right now.

Also, since emscripten is becoming more mature, we should refactor webruby to proper use mrbgem as a build system, including building of mrbtest, and webruby.js file, etc.

The parsing code cannot be stripped even LOADING_MODE = 0

There was a time when we use LOADING_MODE = 0 or 1, all the Ruby parsing code will be stripped out, resulting the final JS file be only around the half size.

But this is now not the case. I need to look into whether it is the driver code or emscripten that leads to this.

:gen_require source processor

Hi.

I am encountering a few errors with the :gen_require source processor. After setting it as the processor in the Rakefile config (changing it from :mrubymix) and running rake, I first get an error that was the result of executing a command in the webruby-0.2.4/lib/webruby/rake/files.rake file. I fixed this by simply adding an && to line 16 in between {MRBC} and ruby (fixes 'command not found' error 127) so that the line now reads:
sh "MRBC=#{Webruby.full_build_dir}/#{MRBC} && ruby #{SCRIPT_GEN_REQUIRE} #{File.expand_path(Webruby.entrypoint_file)} #{Webruby.full_build_dir}/rbcode.c"

However, after running rake again, after that above command is run, I have some issues. In the errors below, I know that "others_irep" is referring to the "others.rb" file I included in my project's "app" folder, but I am not sure how to properly fix that and other errors here:

MRBC=/_webruby/myproject/build/mruby/host/bin/mrbc && ruby /var/lib/gems/1.9.1/gems/webruby-0.2.4/scripts/gen_require.rb /_webruby/myproject/app/app.rb /_webruby/myproject/build/rbcode.c sh: 0: Illegal option -- Current option settings errexit on noglob on ignoreeof on interactive on monitor on noexec on stdin on xtrace on verbose on vi on emacs on noclobber on allexport on notify on nounset on nolog on debug on sh: 0: Illegal option -- Current option settings errexit on noglob on ignoreeof on interactive on monitor on noexec on stdin on xtrace on verbose on vi on emacs on noclobber on allexport on notify on nounset on nolog on debug on sh: 0: Illegal option -- Current option settings errexit on noglob on ignoreeof on interactive on monitor on noexec on stdin on xtrace on verbose on vi on emacs on noclobber on allexport on notify on nounset on nolog on debug on cat /var/lib/gems/1.9.1/gems/webruby-0.2.4/driver/driver.c build/rbcode.c > build/app.c /var/lib/gems/1.9.1/gems/webruby-0.2.4/modules/emscripten/emcc -I/var/lib/gems/1.9.1/gems/webruby-0.2.4/modules/mruby/include -DHAS_REQUIRE -Wall -Werror-implicit-function-declaration -Wno-warn-absolute-paths -O0 build/app.c -o build/app.o build/app.c:77:35: error: use of undeclared identifier 'others_irep' result = mrb_load_irep(mrb, others_irep); ^ build/app.c:92:22: error: use of undeclared identifier 'mrb_require_internal_irep'; did you mean 'mrb_require_internal'? mrb_load_irep(mrb, mrb_require_internal_irep); ^~~~~~~~~~~~~~~~~~~~~~~~~ mrb_require_internal build/app.c:66:1: note: 'mrb_require_internal' declared here mrb_require_internal(mrb_state\* mrb, mrb_value mod) ^ build/app.c:92:22: warning: incompatible pointer types passing 'mrb_value (mrb_state _, mrb_value)' to parameter of type 'const uint8_t *' (aka 'const unsigned char *') [-Wincompatible-pointer-types] mrb_load_irep(mrb, mrb_require_internal_irep); ^~~~~~~~~~~~~~~~~~~~~~~~~ /var/lib/gems/1.9.1/gems/webruby-0.2.4/modules/mruby/include/mruby/irep.h:44:51: note: passing argument to parameter here mrb_value mrb_load_irep(mrb_state_, const uint8_t*); ^ 1 warning and 2 errors generated. ERROR root: compiler frontend failed to generate LLVM bitcode, halting rake aborted! Command failed with status (1): [/var/lib/gems/1.9.1/gems/webruby-0.2.4/mod...] /var/lib/gems/1.9.1/gems/webruby-0.2.4/lib/webruby/rake/files.rake:35:in `block in ' Tasks: TOP => default => js => build/webruby.js => build/link.js => build/app.o

Thank you for any assistance (and wonderful project xxuejie)!

write a step-by-step parser

The current parser would take the source code and parse it as a whole.

This prevents us from creating web IRB that supports multi-line.

Need to create a gem with this API, maybe referencing this?

Failed to build gem because of system path include

Hi,

I'm trying to build mruby-redis but it depends on <hiredis/hiredis.h>, which is located at /usr/local/include/hiredis/hiredis.h. I've been told in order to make the emscripten compiler work for such dependencies I need to send the flag: -I/usr/local/include, how could I do this with webruby?

I tried building a custom webruby gem changing EMCC_CFLAGS in environment.rb to have the user/local/include path, but it doesn't work. I'm sure I'm missing something, can you give me a clue?

Problem with String#split when using mruby-onig-regexp

Hi,

I tried adding the mattn/mruby-onig-regexp mrbgem to my webruby build, and while most of it works in webruby, I'm not able to use String#split (which is redefined in that mrbgem to be regexp-aware). I always get the following error no matter what regexp I try to create:

TypeError: Property '_regcomp' of object [object Object] is not a function

Any help is appreciated.

thanks,
Ricardo

Feature: make this a gem

Now webruby can only compile files within app folder. It's much better if we can make it a gem and provide a CLI tool, just like RubyMotion.

  • Re-organize rakefiles
  • Template generator
  • Upload the gem

unable to build w/ updated emscripten and mruby

I was able to run rake to build mruby.js a week ago after following instructions on http://qiezi.me/2013/01/09/webruby-1-2-3-tutorial/, but I haven't been able to do it since the most recent commit that updated mruby and emscripten.

I get the following output when I run rake now: https://gist.github.com/choxi/c92b103763083dc767a4. I tried debugging it but I'm not sure what to look at in the error output.

Alternatively, I wonder if you could include the built mruby.js file in the git repo? I'm only trying to update it because the most recent version of mruby includes RegEx support.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.