Re: How to know if a CPAN module uses XS
by syphilis (Archbishop) on Jun 20, 2012 at 00:09 UTC
|
I just scan the MANIFEST (in the source distro) for a '.xs' file. Presence of one means that compiling is reqired; absence means no compilation is required.
However, whilst this is a fairly reliable method, it's not foolproof. For example, PDL::NetCDF has no xs file yet requires compilation. (The 'perl Makefile.PL' step generates the xs file.) And I think there are some modules that, while providing an xs file, also cater for a pure-perl build.
Perhaps some of the other monks know of a smarter approach.
Cheers, Rob | [reply] |
|
Another heuristic is to look for use DynaLoader or use XSLoader in any of the modules.
XS code also often comes with a file called typemap which is used by the XS build system to map between Perl data structures and C data structures.
And ppport.h is often bundled. This is a C header file which, as I understand it, smooths over the differences between versions of the Perl API.
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
| [reply] [d/l] [select] |
|
| [reply] [d/l] [select] |
Re: How to know if a CPAN module uses XS
by toolic (Bishop) on Jun 20, 2012 at 00:35 UTC
|
A Super Search yielded the somewhat related Modules in CPAN that don't need to be compiled, but it does not give any more helpful advice than syphilis'.
http://search.cpan.org uses DLSIP notation. The "L" indicates whether compile is needed. However, it requires CPAN authors to "Register" a newly uploaded module, which is voluntary, and in my experience, unreliable. IIRC, the DSLIP designation is manually entered by the author, which means it is subject to typos.
| [reply] |
|
| [reply] |
|
| [reply] |
|
DSLIP designation is manually entered by the author, which means it is subject to typos. AFAIK (its been 10 years) its a checkbox and/or dropdown menu list with descriptions, so typos not possible :)
| [reply] |
|
While not as easy to type in incorrect information, it is still possible to check the wrong box (I do it probably once a week here at the Monastery as I'm voting) or select the wrong dropdown item, without noticing. The point is that it is voluntary information which means it is error-prone.
| [reply] |
|
Re: How to know if a CPAN module uses XS
by bulk88 (Priest) on Jun 20, 2012 at 01:44 UTC
|
WriteMakefile returns a MM object which has has_link_code and needs_linking. Somehow calling these are your safest bet. If I had to try and do it, I would copy EUMM's WriteMakefile into my script, switch packages, define a new WriteMakefile based off EUMM's but without the flush() at the end, switch packages back to main, , run the makefile.pl with a do(), intercept the returning MM obj in my WriteMakefile, and call needs_linking(). The most complex use of EUMM I've ever seen was in Perl TK, and I did something similar to what I described to you to intercept Tk::MMutil::TkExtMakefile. Note this is not a "static" way of determining whether it needs to be compile, so security issues might be a problem for you.
Another solution would be to generate the makefile, then do backticks on your make tool running in "list commands and do not execute" mode, then parse that looking for your local C compiler. | [reply] |
|
I think the first difficulty (not necessarily a show-stopper) I see with that approach is that it relies on WriteMakefile() being run. However, some Makefile.PL's may abort prior to that happening - eg because $] is too low, or because $^O is inappropriate, or because some pre-requisite could not be found.
Handle that, and you're probably on a winner. It may even be that if $] is too low or $^O is inappropriate, then you don't even need to know whether the module needs to be compiled ... and if the Makefile.PL aborts because a pre-requisite C library can't be found, then it should be safe to assume it's a module that needs compiling. But if the Makefile.PL aborts because a pre-requisite perl module could not be found, then all bets are off. (I've a notion that there are some modules that do that, though I can't provide an example.)
then do backticks on your make tool running in "list commands and do not execute" mode
And then there's Inline/Inline::C ... run make in "list commands and do not execute" mode when building Inline/Inline::C and you'll see no mention of any compiler. (But perhaps that's the right result anyway ... not sure about that one.)
And, of course, not every distro has a Makefile.PL - and there's presumably a need to handle them, too. (That's the beauty of having a choice of 2 build systems - instead of solving a problem once, you get the added joy of having to solve it twice :-)
Cheers, Rob
| [reply] |
|
| [reply] |