compiling ruby for the iphone
Courtenay : August 24th, 2007
Here’s how far we’ve come.
You can install the binary ruby from Installer.app, however, it doesn’t run anything useful, and segfaults, errors out, or otherwise refuses to operate.
# ruby setup.rb
setup.rb:1585: [BUG] terminated node (0x15c444)
So, the process is, install the ARM binutils (gcc and friends) with macports. This GCC is ghetto, and doesn’t support everything that regular Darwin GCC does.
sudo port install arm-apple-darwin-binutils
Download ruby, untar it, and apply this patch:
— configure.in.old 2007-08-23 23:22:08.000000000 -0700
+++ configure.in 2007-08-23 23:40:18.000000000 -0700
@@ -530,7 +530,7 @@
truncate chsize times utimes fcntl lockf lstat symlink link\
readlink setitimer setruid seteuid setreuid setresuid\
setproctitle setrgid setegid setregid setresgid issetugid pause\
- lchown lchmod getpgrp setpgrp getpgid setpgid initgroups\
+ lchown lchmod getpgrp getpgid setpgid initgroups\
getgroups setgroups getpriority getrlimit setrlimit sysconf\
dlopen sigprocmask\
sigaction _setjmp setsid telldir seekdir fchmod mktime timegm\
@@ -630,7 +630,7 @@
fi
AC_FUNC_GETPGRP
-AC_FUNC_SETPGRP
+# AC_FUNC_SETPGRP
AC_C_BIGENDIAN
AC_C_CONST
@@ -1047,7 +1047,7 @@
rhapsody*) : ${LDSHARED=’cc -dynamic -bundle -undefined suppress’}
: ${LDFLAGS=”“}
rb_cv_dlopen=yes ;;
- darwin*) : ${LDSHARED=’cc -dynamic -bundle -undefined suppress -flat_namespace’}
+ darwin*) : ${LDSHARED=’$(CC) -dynamic -bundle -flat_namespace’}
: ${LDFLAGS=”“}
: ${LIBPATHENV=DYLD_LIBRARY_PATH}
rb_cv_dlopen=yes ;;
@@ -1379,7 +1379,7 @@
;;
darwin*)
LIBRUBY_SO=’lib$(RUBY_SO_NAME).$(MAJOR).$(MINOR).$(TEENY).dylib’
- LIBRUBY_LDSHARED=’cc -dynamiclib -undefined suppress -flat_namespace’
+ LIBRUBY_LDSHARED=’$(CC) -dynamiclib -undefined suppress -flat_namespace’
LIBRUBY_DLDFLAGS=’-install_name $(libdir)/lib$(RUBY_SO_NAME).dylib -current_version $(MAJOR).$(MINOR).$(TEENY) -compatibility_version $(MAJOR).$(MINOR)’
LIBRUBY_ALIASES=’lib$(RUBY_SO_NAME).$(MAJOR).$(MINOR).dylib lib$(RUBY_SO_NAME).dylib’
;;
@@ -1430,7 +1430,7 @@
CFLAGS=”$CFLAGS -pipe -no-precomp -fno-common”
;;
darwin*)
- CFLAGS=”$CFLAGS -pipe -fno-common”
+ CFLAGS=”$CFLAGS -fno-common”
;;
os2-emx)
CFLAGS=”$CFLAGS -DOS2 -Zmts”
Edit mkconfig.rb and comment-out the line near the end that begins, Fileutils.touch
Edit ext/Setup and uncomment the first line. Also uncomment socket, digest, digest/md5, etc, fcntl, stringio, syck and zlib.
$ autoconf
$ CC=arm-apple-darwin-cc CPP=llvm-cpp ./configure –host=arm-apple-darwin –disable-ipv6 –prefix=/tmp
Edit ext/getaddrinfo.c and comment out “gai_strerror” from about line 207. Edit ext/socket/addrinfo.h and comment out the code related to “extern char *gair_strerror”
$ make
$ make install
Hopefully it all compiles for you and you can scp ruby from /tmp/lib and /tmp/bin into your iphone. I just can’t get it to work. Basically, the symbols from those ext/ libraries aren’t available during the final part of “make”.
5 Responses to “compiling ruby for the iphone”
Sorry, comments are closed for this article.
August 24th, 2007 at 02:29 AM
I don't have an iPhone yet (not launched in UK), but you rock :-)
August 27th, 2007 at 08:32 AM
That's great to see! We don't want to be left behind by developers of other scripting languages who already have their entire web framework running on the iPhone!
http://www.flickr.com/photos/jacobian/1160698795/
August 28th, 2007 at 04:51 PM
Are you ware of http://evan.tiggerpalace.com/?p=30?
August 29th, 2007 at 09:09 AM
Coming full circle (Courtenay paid me a visit), I did not try anything more spectacular than my post indicated: a simple while loop to get a smidgeon of sense about the performance of Ruby on the iPhone.
Courtenay's definitely tried to carry this ball a lot farther than I have with his instructions above.
September 16th, 2007 at 10:48 AM
I have been working on this issue for the last few days, it looks like a bug in nightwatch's assembler. You can see the bug entry for it at:
http://code.google.com/p/iphone-dev/issues/detail?id=44
Nice workaround using the other compiler, I will take a crack at that route and fixing the errors you encountered.