Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What tools can help build an XS project?

I've recently started learning XS using perlxstut and the tutorial suggests that I create my module using the old h2xs tool to create an ExtUtils::MakeMaker-based project. However for pure Perl projects, h2xs/EUMM has long been disfavoured in favour of Module::Install, Module::Build or Dist::Zilla.

Is there a more modern way of creating XS projects? Can Module::Starter create XS projects? Can Module::Build or Dist::Zilla build XS projects? Their pod pages are silent on the matter.

On the flip side, does the criticism that was levelled at h2xs/EUMM apply to XS projects? If you need a C compiler anyway, is it reasonable to demand a make tool as well?

EDIT: I see this question answers my question about creating a project. I'd still like to know about building: is EUMM the only option, or are Module::Build and Dist::Zilla also capable of building XS?

like image 826
Philip Potter Avatar asked Aug 28 '10 08:08

Philip Potter


2 Answers

It turns out that Module::Build is perfectly capable of compiling XS. Here is a complete Build.PL I managed to scrape together:

use strict;
use Module::Build;

my $build = Module::Build->new(
    module_name  => 'Chocolate::Belgian',
    dynamic_config => 1,
    license      => 'perl',
    requires     => {
        'Module::Build' => '0.19', # xs
        'Test::More' => 0,
    },
    extra_compiler_flags => '-Iinclude',
    extra_linker_flags   => '',
    c_source     => 'src',
    needs_compiler => 1,
    xs_files     => {
        './Belgian.xs' => 'lib/Chocolate/Belgian.xs',
    },

   );

$build->create_build_script;

This will build a distribution with .h include files (such as ppport.h) in the include/ directory, .c source files in the src/ directory, and an .xs file corresponding to package Chocolate::Belgian in the project base directory.

extra_compiler_flags corresponds to make CCFLAGS, while extra_linker_flags corresponds to LIBS (so you might want -lm there to link the C math library).

like image 200
Philip Potter Avatar answered Sep 27 '22 20:09

Philip Potter


Dist::Zilla is not a replacement for EUMM or Module::Build, what it will do is generate a Makefile.Pl (etc) for you, I would not be surprised to hear that it can't do this for an XS project, but there are ways of managing your own for a dzil project. It can work with whatever Makefile.Pl it is provided with (or Build.pl).

So my answer on the Dist::Zilla part of your question is, Dist::Zilla does not fill that role in a project.

like image 44
xenoterracide Avatar answered Sep 27 '22 21:09

xenoterracide