Friday, June 18, 2004

Compiling Perl pt.. 2

Well, I won the battle with compiling 64-bit perl, but I had to cheat. I ended up just compiling it over the network using a IA64 machine, and Visual Studio .NET + source on a mapped drive. It wouldn't set any speed records, but it got the job done. Flush with the success of that, I moved on to compile the extraneous modules we use. That's when the trouble started.

Most of our infrastructure at work doesn't use modules. Or if it does, its all Perl modules or something standard from libwin32 or Perl core. But we do use Win32::AdminMisc for three functions: GetDrives, GetDriveSpace, and GetDriveType. No problem I figure, the source is available and MakeMaker stuff really isn't hard to compile if you have a Config.pm that works with your compiler setup. But AdminMisc doesn't use MakeMaker, XS, or anything you would expect, and the code is a MESS. It uses various libraries not included in the source distribution, libraries that aren't available anywhere (AFAICT), has two different versions of the same files in some of the extra source neither of which compile even in 32-bit mode.

After an hour or so of failing to compile AdminMisc and all its associated crap, I decided maybe I could just write a clone module with just the three functions I needed. I mean, those functions are just thin wrappers around the Win32 API, I have the source to tons of Win32 modules in libwin32, how hard could it be?

After wasting a whole day on this adventure, I can say, a lot harder then I thought it would be. None of the modules in Win32 are written in the same way. I suppose that fits with TMTOWTDI, but it doesn't make it very easy to learn by comparing sources. There is some XS documentation out there, but it isn't very straight forward. Its all very fragile, and Macro-based with all the problems that you would expect from that sort of thing. The kind of problems where you get compiler errors saying 'Undeclared identifier: targ' pointing to a single Macro line. Well, of course it is undefined, I didn't declare a variable called that, have never heard of it, can't find any documentation one it, and don't have the slightest idea how to define it.

I don't doubt that XS is very powerful, and really makes making modules easy once you know how it works and the subtleties going on underneath the stack manipulation macros. But its not very easy to waltz up and write a simple module. And it doesn't help that I also have to deal with the whole GetDriveTypeA/W Unicode versus Ansi mess too.

I did, by the end of the day, get things compiling. Now I just have to get the test harness I wrote working. Right now the autoloading of constants isn't working right. But I'm pretty sure I can get it working.

No comments: