This post references MacRuby 0.5b2, used with Xcode 3.2 on Snopard (10.6.2).
At some point you’ll probably want to create a release build for your app. You’d like to compile it and embed the MacRuby framework so the app is self- contained. Cool beans.
Unfortunately, it’s not as easy as it seems. Yes, the MacRuby Xcode template contains both an “Embed” and a “Compile” target, and they seem to work fine.
;) The problem I ran into, though, was that whenever you would require
anything from the Ruby standard library (say, yaml
or stringio
), the app would forget about the embedded version of MR and look for
/Library/Frameworks/MacRuby.framework/…
.
I didn’t notice this at first since this folder exists on my dev machine (big surprise), but when I tested it on a clean machine (i.e. one where MacRuby isn’t installed), nothing would happen. Well, nothing except some lines in the system.log, that is:
Being a newb to the ancient arts of compiling shit self-written software I was scratching my head rather furiously. It took me several hours of digging around the Googles and macruby-devel to learn about install_name_tool
,
and how it’s used to adjust the path of a shared library inside a file.
And that’s what I did, then. I’ve created a new build target, “Embed and Compile”, which has two sub-targets:
- the reference to the default app build phase (which means “MyNewApp” is a direct dependency of the “Embed and Compile” target)
- a “Run Script” build phase named “Embed, Compile, Fix”
The script runs macruby_deploy
and afterwards tells install_name_tool
to do its dirty, dirty work. I found it’s not enough to have it adjust the executable only; for me it was necessary to fix all the *.rbo
files as well.
So, that’s it. The above works for me, it might work for you as well. If you have comments, suggestions or recommendations, please sound off below. I’m still learning all of this, and any input is appreciated. :)
Oh, and in case I sound ungrateful or anything: I am not. MacRuby 0.5b2 is exactly what is says it is: the second beta of a software’s pre-1.0 version. It’s already pretty damn impressive but not really done yet. I had a hunch what I was getting into, so it’s cool. ;)