3

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
kch
  • 77,385
  • 46
  • 136
  • 148

2 Answers2

4

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]
kch
  • 77,385
  • 46
  • 136
  • 148
mipadi
  • 398,885
  • 90
  • 523
  • 479
  • No problem, I was about to update it with the relevant output myself. – mipadi Jun 29 '10 at 15:58
  • @zengr Post a new question with your problem, will try to help. – kch Jul 11 '10 at 18:52
  • @kch Thanks, the question is posted here: http://stackoverflow.com/questions/3197686/install-ruby-1-9-2-on-mac-osx-10-6-with-32bit-version – zengr Jul 12 '10 at 01:11
1

As for RVM, it says you can't have fat binaries, but that's not true as of this commit which incorporates my patch.

Using the latest rvm you can install ruby-1.9.2-head using the same configure flag as in the manual build:

$ rvm install ruby-1.9.2-head -C --with-arch=x86_64,i386

Proof that it's supposedly working:

$ rvm use 1.9.2-head
info: Using ruby 1.9.2 head

$ file `which ruby` | perl -pe 's|^.*/||'
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
kch
  • 77,385
  • 46
  • 136
  • 148
  • Just FYI, doesn't work work for 1.8.7-p352, simple comparison of configure.in files showed that multi-arch support part present in 1.9.2 is missing in 1.8.7. –  Oct 03 '11 at 16:14
  • This doesn't appear to work for ruby-2.0.0; it fails for me with `Error running '__rvm_make -j 1'`, tied to `ld: unknown option: -fstack-protector` in the log. – Sai Nov 05 '13 at 05:28