Search code examples
rubymacosbuildrvmuniversal-binary

How to manually build a universal ruby on Mac OS X? How about with rvm?


I got the ruby sources from the official git mirror, then checked out the ruby_1_9_2 branch.

git clone http://github.com/ruby/ruby.git
git checkout ruby_1_9_2

So, for now, I want to compile 1.9.2-head. But as you'll see later I'm hoping for a solution that works for 1.8 too.

The standard way to compile this is:

autoconf
./configure
make
make install

That works, but it yields me a x86_64-only build:

$ ruby -v
ruby 1.9.2dev (2010-06-14 revision 28321) [x86_64-darwin10.3.0]

I don't care about PPC, obviously, since I'm on 10.6, but I want to have both i386 and x86_64, because some things need to be done in 32-bit.

So, what I want to know:

  1. the magic chants to build a fat binary with both i386 and x86_64 archs.
  2. I would also be interested in doing the same with my RVM ruby versions.

Probably unecessary system information:

$ system_profiler -detailLevel mini SPSoftwareDataType | ack '^ {6}' | head -3
      System Version: Mac OS X 10.6.4 (10F569)
      Kernel Version: Darwin 10.4.0
      64-bit Kernel and Extensions: No

$ uname -a
Darwin meaningless.local 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386

Solution

  • Use the --with-arch option to ./configure:

    $ ./configure --with-arch=x86_64,i386
    

    --with-arch takes a comma-separated list of architectures for which Ruby should be built.


    added by kch:

    Output after a successful build:

    $ file ruby
    ruby: Mach-O universal binary with 2 architectures
    ruby (for architecture x86_64): Mach-O 64-bit executable x86_64
    ruby (for architecture i386):   Mach-O executable i386
    
    $ arch -i386 ./ruby -v
    ruby 1.9.2dev (2010-06-29 revision 28468) [universal.i386-darwin10.4.0]
    
    $ arch -x86_64 ./ruby -v
    ruby 1.9.2dev (2010-06-29 revision 28468) [universal.x86_64-darwin10.4.0]
    
    $ ./ruby -v
    ruby 1.9.2dev (2010-06-29 revision 28468) [universal.x86_64-darwin10.4.0]