[MLton-user] Mac OS X on Intel

Matthew Fluet fluet@cs.cornell.edu
Sun, 23 Apr 2006 15:50:08 -0400 (EDT)


>> Oh, that's very nice.  Then I'd say give it a try and report your
>> experience.  You will probably have to tweak
>>    /usr/local/lib/mlton/platform
>> to have it report a PowerPC arch, otherwise MLton will complain of an
>> unknown os/arch pair.  If you are lucky, that will get you to the point
>> where
>>    /usr/local/bin/mlton
>> will actually do something interesting, rather than bailing.
>
> Without changing anything, compiling a hello world program with mlton
> -verbose 1 gives the following error message:
>
> /usr/bin/ld: warning
> /Users/joe/ptr/local/mlton-20051202/usr/local/lib/mlton/self/libmlton.a
> archive's cputype (18, architecture ppc) does not match cputype (7)
> for specified -arch flag: i386 (can't load from it)

That's expected, since libmlton.a in the Mac OS X package is a ppc binary.

What I didn't expect was that mlton wouldn't complain about darwin-x86 
being an unsupported os/arch pair.  But, I guess we don't explicitly check 
for the pair being supported, just each characteristic individually.

> I then added
>
> case "$arch" in
> # begin hack for intel mac os x
> i386)
>        HOST_ARCH=powerpc
> ;;
> # end hack for intel mac os x
> alpha*)
>
> to usr/local/lib/mlton/platform, but that didn't change the error from
> compiling hello world.

Right.  All this does is fake the host architecture being powerpc.  Now 
the powerpc mlton binary believes that it should target a powerpc.  Since 
the host and target architectures are the same, it simply invokes gcc (as 
a linker) with no special arguments.  But, since the real host machine is 
an x86, gcc expects to see x86 binaries.

What you want to do is to add to /usr/local/bin/mlton something like the 
following:

         -target-as-opt powerpc                                  \
                 '-arch ppc'                                     \
         -target-ld-opt powerpc                                  \
                 '-arch ppc'                                     \
         -target-cc-opt powerpc                                  \
                 '-arch ppc'                                     \

(I'm guessing on the -arch flag to gcc, based on the error message above.) 
That now tells gcc to also target ppc, so it will link with the libmlton.a 
binary.

Nonetheless, this isn't the "Right Way" to support MLton on darwin-x86.

> I'm afraid my hacking skills aren't up to the task of porting MLton to
> this new platform, but I'm keen to become a user!

I maintain that it should be relatively straightforward, but I don't know 
if any of the developers with porting experience has access to an Intel 
Mac.