New in 1.15: Static libraries support (experimental)

621 views
Skip to first unread message

Laurent Sansonetti

unread,
Jul 5, 2012, 11:22:43 AM7/5/12
to rubym...@googlegroups.com
Hi guys,

As promised, I hacked a `rake static' task which produces a static library archive for the project's code and the RubyMotion runtime. It's in RubyMotion 1.15. The archive is universal (it contains i386 and armv{6,7} objects) and can be simply added to an Xcode project.

I will write an article that describes better the mechanism and what you can do with it, but first I wanted to release the change in an update and see what you guys think of it. Improvements will probably be needed. 

Usage:

1) Run `rake static' in your project.

2) Drag the ./build/#{AppName}-universal.a file to your Xcode project.

3) The code requires system libraries that are not linked by default: libc++.dylib, libc++abi.dylib, libstdc++.dylib and libicucore.dylib.

You can open the application target preferences, click on Build Phases, then Link Binary with Libraries item, then the '+' button, and add the libraries from there.

4) Back to your code, you now need to initialize the RubyMotion runtime + code, by calling the RubyMotionInit() function. You can for instance do this in the main() function. Edit main.m to look like this:

int main(int argc, char *argv[])
{
    @autoreleasepool {
        void RubyMotionInit(int, char **);
        RubyMotionInit(argc, argv);
        return UIApplicationMain(argc, argv, nil, @"AppDelegate");
    }
}

That should do it! If you hit the build button you should get the RubyMotion code executed when your app starts. If you change the Ruby files you only need to run `rake static' again, Xcode should figure out that the library changed and properly re-link the executable.

Let me know how it works and if you have any improvement ideas.

Enjoy.
Laurent

Christopher Pappas

unread,
Jul 5, 2012, 1:15:18 PM7/5/12
to rubym...@googlegroups.com
Amazing!  Cant wait to try this out.  

-Chris

Francis Chong

unread,
Jul 5, 2012, 2:30:45 PM7/5/12
to rubym...@googlegroups.com
this is super cool! will definitely try it out

malkomalko

unread,
Jul 5, 2012, 7:39:42 PM7/5/12
to rubym...@googlegroups.com
This basically means we can write parts of our app now in Rubymotion? super cool!

Mark Villacampa

unread,
Jul 6, 2012, 4:28:05 AM7/6/12
to rubym...@googlegroups.com
This is SO awsome, Laurent. Cant wait to try it!!! :)

Francis Chong

unread,
Jul 6, 2012, 4:49:26 AM7/6/12
to rubym...@googlegroups.com
I just compiled a static library and don't sure how to use it. Yeah will wait for the article. :)


On Thursday, July 5, 2012 11:22:43 PM UTC+8, Laurent Sansonetti wrote:

Laurent Sansonetti

unread,
Jul 6, 2012, 8:13:15 AM7/6/12
to rubym...@googlegroups.com
Yep, that's the goal. The classes you write in Ruby will be made available in the app. You can provide the implementation for a view controller in Ruby for instance.

One thing I would like to do is provide the ability to generate header files for the Ruby code, which would make it easier for the Objective-C codebase to call into it. 

Laurent

Websembly

unread,
Jul 8, 2012, 9:36:24 PM7/8/12
to rubym...@googlegroups.com
>>One thing I would like to do is provide the ability to generate header files for the Ruby code, which would make it easier for the Objective-C codebase to call into it. 
Now THAT would be awesome!!!

Matthew Nguyen

unread,
Jul 11, 2012, 9:45:48 AM7/11/12
to rubym...@googlegroups.com
Is it possible to use generated static library with RubyMotion project?
It could be useful to skip some unnecessary re-compilation.

Matthew Nguyen

Francis Chong

unread,
Jul 30, 2012, 11:26:00 AM7/30/12
to rubym...@googlegroups.com
I can include the RubyMotion static library to Objective-C project, but if I do that it run motion AppDelegate instead of Objective-C app delegate.

Are there anyway to keep the original app delegate code while still call the motion code? It is not very useful as a static library if I have to replace the app delegate.


On Thursday, July 5, 2012 11:22:43 PM UTC+8, Laurent Sansonetti wrote:
Reply all
Reply to author
Forward
0 new messages