A build_config.rb to cross-compile mruby for iOS applications.
# cd to your mruby src path
cd ~/Downloads/mruby-1.0.0
# Compile mrbuy with this build_config.rb
MRUBY_CONFIG=(PATH_TO_THIS_REPO)/build_config.rb ./minirake
# Navigate to built libraries
cd build
This should have generated build/iphone-sim
, build/iphone-armv7
and build/iphone-armv7s
directories.
Copy the required libmruby.a
from build/iphone-*/lib
paths to your projects and enjoy.
You only need build/iphone-sim/lib/libmruby.a
if you're using the iOS simulator, and don't forget
to copy the headers from include/
path as well
To use mruby in a RubyMotion project, do the following:
-
Build mruby as explained above
-
Create a new directory
vendor/mruby
in your RubyMotion project -
Copy
libmruby.a
frombuild/iphone-sim/lib/libmruby.a
to thevendor/mruby
directory -
Copy everything inside
include/
dir to youvendor/mruby
directory as well -
Add the following line to your RubyMotion Rakefile
app.vendor_project('vendor/mruby', :static)
-
Use mruby in your application. For example use this in your app_delegate.rb:
mrb = Pointer.new(:object) mrb[0] = mrb_open() mrb_load_string(mrb[0], "class TestClass; end") puts mrb_class_defined(mrb[0], "TestClass") # Should output 1 in the console
-
Run
rake
and look at the console -
To run on actual devices, you need to copy for
build/iphone-armv7/lib/libmruby.a
andbuild/iphone-armv7s/lib/libmruby.a
tovendor/mruby
as well