ActiveBlog

Milestone: PDK goes Universal
by

, October 9, 2006

I've recently been spending a lot of my time working on the upcoming PDK 7.0. There are still many things left to do before we are can reach a releasable state, but we are making progress. Most of my time...


I've recently been spending a lot of my time working on the upcoming PDK 7.0. There are still many things left to do before we are can reach a releasable state, but we are making progress. Most of my time so far has been spent on porting to OSX. It would have been very simple if not for this one very interesting Apple feature. With the whole switch to Intel and all, Apple has introduced (not really, they are a Mach-O feature from NeXT) Universal Binaries. Basically, it's a way to build an application that's capable of running on more than one platform. Intel vs. PowerPC in this case. When using Apple's XCode, generating binaries of that kind is very easy.

The first step on my roadmap was to build a version of the PDK where every single binary was a universal one. That was relatively easy to accomplish and simply required a little added build magic. It's been done, and it works just great. We will be able to ship a single version of PDK that will run/install on any Mac, good.

$> file perlapp
perlapp: Mach-O universal binary with 2 architectures
perlapp (for architecture ppc):    Mach-O executable ppc
perlapp (for architecture i386):   Mach-O executable i386

Alright, so what does this have to do with PDK? Well, the PDK has a very cool tool, PerlApp, that allows you to produce native binaries from Perl scripts. So, wouldn't it be neat if you could take
a Perl script on OSX PPC, use perlapp, and generate a Universal Binary out of it. Sounds like
a natural feature to support. And that turned out to be more work than I thought.

Turns out that generating universal binaries is only part of the problem, the easy part. The hard part is that PPC/Intel differ in Endianness. So, when
PerlApp generates the final executable that will contain your perl script (and all its dependencies), it generates something very similar to a zipfile to hold all these files in the generated executable. However, it turned out that for performance reasons, mainly, that code had multiple endianness issues
that needed to be addressed. So, after many debugging sessions, a couple of segfaults, and various code
changes, you now have:

$> bin/perlapp hello.pl
PerlApp 6.9.90 dev build 268783
Created 'hello'
$> file hello
hello: Mach-O universal binary with 2 architectures
hello (for architecture ppc):   Mach-O executable ppc
hello (for architecture i386):  Mach-O executable i386
$> ./hello
Hello World!
$> scp hello osx-ppc-10-4:
$> ssh osx-ppc-10-4 "./hello"
Hello World!

This is only one of the pieces required for PDK 7.0, but it's a milestone I am very happy to have reached. Now, time to work on the rest of the planned features for OSX!

Subscribe to ActiveState Blogs by Email

Share this post: