Win32 cross-compiling so far...

Stephen Weeks MLton@sourcelight.com
Mon, 10 Sep 2001 16:48:04 -0700


> You can see the output in the attached file...
> Apparently it is trying to execute a file during
> compilation which has been crosscompiled for Win32.

During compilation, MLton creates, compiles, and executes a small C file to
find out the values of constants that are defined by _prim declarations in the
basis library.  See, e.g., "val access ..." in basis-library/posix/primitive.sml.

	val acces = _prim "Posix_Error_acces": syserror;

If access is used in the program, the C program that MLton generates will
contain a line like 

	fprintf(f, "%d\n", Posix_error_access);

If you want to look, the code that does the C generation and execution is in
core-ml/lookup-constant.fun.

This approach is obviously wrong when cross-compiling, since the target machine
is not the same as where the compiler is running.  Fortunately in this case we
got a reasonable error message because the cross-compiled executable didn't run.
Even worse would have been if the executable ran, but gave us the wrong
constants.

The fix is that MLton needs to use the header files for the target machine to
get the right constants, but to generate an executable for the source machine.
In main/compile.sml, the call to LookupConstant.build passes along the docc
function which it is getting from main/main.sml.  That probably just needs to be
tweaked a bit for cross-compiling.

Hopefully this gives you enough of a hint as to what to fix?

> I hope that you are interested in having the port in
> the official version and that you can modify the Makefiles
> appropriately for the various platform installations.
> I believe that all my changes are safely contained within
> #if defined(_WIN32) macros - so that the same distribution
> should work as a native Linux compiler too.

Absolutely.  Once you get something stable I'll bring your changes into the
official version.

> And on behalf of my computer I'm also starting to feel
> outdated. I have to activate at least 512MB swapspace
> on a machine with 512MB RAM to compile MLton, and then
> it's taking a whole night to compile. Sigh...
> I need more memory - again :)

Hmm.  MLton can self compile without problems using 450M RAM.  Further, it will
only request 85% of total RAM.  It must be other stuff running on your machine.