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/mrubyin your RubyMotion project -
Copy
libmruby.afrombuild/iphone-sim/lib/libmruby.ato thevendor/mrubydirectory -
Copy everything inside
include/dir to youvendor/mrubydirectory 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
rakeand look at the console -
To run on actual devices, you need to copy for
build/iphone-armv7/lib/libmruby.aandbuild/iphone-armv7s/lib/libmruby.atovendor/mrubyas well