in reply to Re: Making Inline::C modules fit for CPAN
in thread Making Inline::C modules fit for CPAN

I'm wondering if it's a design defect of Inline::C that it needs to runtime compile the code

I don't really see it that way. It only needs to "runtime compile the code" the first time the code is run. Subsequent runnings of the code simply load what was compiled the first time ... no need to re-compile it. In that way it's no different to a perl extension - ie it needs to be compiled only once.

This is making a big assumption, that your target machine has a working C compiler

This statement implies to me that you're thinking Inline::C will work without a C compiler - which is not the case. (Sorry ... perhaps you meant something entirely different.)

Cheers,
Rob
  • Comment on Re^2: Making Inline::C modules fit for CPAN

Replies are listed 'Best First'.
Re^3: Making Inline::C modules fit for CPAN
by rinceWind (Monsignor) on Nov 16, 2006 at 09:34 UTC

    I think you've not appreciated my point, though I admit I probably didn't express it very well.

    A CPAN style distribution has a 4 phase install process: configure, build, test, install.

    perl Makefile.PL # Configure make # build make test # test make install # install

    or

    perl Build.PL # Configure ./Build # build ./Build test # test ./Build install # install

    For an XS or swig module, compilation of C code takes place in the build phase. This phase generates usable deliverables: perl code, binaries, man pages, scripts, etc. under the blib directory. The test harness mechanism works on these deliverables pre-installation, so you can run tests against your distribution before it gets installed.

    Please correct me if I'm wrong in any of this - this is based on my understanding of I::C and I could be talking rubbish here. An Inline::C module won't be compiled during the build phase, but the first time it is run. While this should (hopefully!) happen as a side effect of the test phase, these binaries won't be listed as deliverables, and won't be installed as part of the install phase. So, the binaries get built, the first time the module gets called after it has been installed.

    This won't happen as root, most of the time, so presumably the compile is redone for each user, the first time they run the application that uses the script. If this isn't the case, there could be permissions problems and all sorts of environmental wierdness happening.

    So far, I have been referring to the CPAN model for installing a distribution. When it comes to package managers, the idea (usually) is that there is no compile step done on the target machine. Said target machine could be Windows with a PPM install, Debian with an install via apt-get or whatever. The point is that package managers assume that no compile is needed on the target, and no compiler is necessary. This implies that distributions for such package managers may be platform specific and contain pre-built binaries.

    The important distinction here is that the build machine has a C compiler, indeed the full development tool set. But the target machine is not guaranteed to have any of this, it's a run-time environment.

    PAR takes this idea a stage further, and the target machine doesn't even need to have perl installed.

    Hopefully this has clarified my argument sufficiently.

    --

    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)

      Irrespective of how well (or how badly) you made your point, it is certainly true that I missed it :-)
      I can't fault most of what you have written here. My only doubt relates to:

      The point is that package managers assume that no compile is needed on the target, and no compiler is necessary

      With a properly built Inline::C binary package that's the case. All that the target needs is to have Inline installed - and it's quite possible to install Inline on a machine that doesn't have a C compiler. For the details of one way to construct such a binary package, see "How do I create a binary distribution using Inline?" at http://search.cpan.org/~ingy/Inline-0.44/Inline-FAQ.pod.

      Similarly, with Steffen's proposed module, I think it should be possible to create a binary that will work on a target machine that does not have a compiler. As long as the package contains the necesary so/dll, then XSLoader will load it and all should be sweet, so long as the target machine has Module::Inline::C installed. (That's if I understand Steffen's proposal correctly ... which is by no means guaranteed.)

      Basically, whether it's a straight out Inline::C module, or a Module::Inline::C module, it will be possible (albeit, perhaps kludgy) to build a package that doesn't need a C compiler on the target machine. On thinking further about it, I suspect that creating the binary package will be less of a kludge with Steffen's module than with Inline::C.

      Of course, having written all of this, it now occurs to me that perhaps you were simply wanting to make Steffen aware of the 'packaging' aspect ... to which I can only say "Good point!" :-)

      Cheers,
      Rob