[MacRuby-devel] Using built-in ruby libraries in packaged applications.

Laurent Sansonetti lsansonetti at apple.com
Mon Apr 20 13:32:10 PDT 2009


Hi Alex,

On Apr 19, 2009, at 9:53 PM, Alex Vollmer wrote:

> I have a bit of code that uses the Ruby base64 library and I would  
> like to package the MacRuby framework into my application. I've  
> added the "Embed MacRuby" target to my build and the MacRuby  
> framework shows up properly in my application's contents directory.  
> The problem is that when the program launches the call for requiring  
> the base64.rb file causes the runtime to bomb out saying it couldn't  
> find 'base64.rb'. After a bit of hacking I ended up adding this  
> stanza in the rb_main.rb file prior to the loop that requires all  
> the local files:
>
> $:.unshift(File.join(NSBundle.mainBundle.privateFrameworksPath,
>                     "MacRuby.framework",
>                     "Versions",
>                     "Current",
>                     "usr/lib/ruby/1.9.1"))
>
> This seems a little hacky to me. Is there a better way of doing this?

This is the right way to do it. The "Embed MacRuby" target configures  
the linking settings of your app but you still need to hack the load  
path in rb_main.rb to point it to the MacRuby stdlib.

Here is another way:

$:.map! { |x| x.sub(/^\/Library\/Frameworks/,  
NSBundle.mainBundle.privateFrameworksPath) }
$:.unshift NSBundle.mainBundle.resourcePath.fileSystemRepresentation

I wasn't able to perform this change automatically during the target  
build. Maybe we could ship a new rb_main.rb in the template that does  
this change based on a heuristic... if you have any idea let me know.

Laurent


More information about the MacRuby-devel mailing list