哪些工具可以帮助构建 XS 项目?

发布于 2024-09-16 19:48:26 字数 1187 浏览 7 评论 0原文

我最近开始使用 perlxstut 学习 XS,教程建议我使用旧的 h2xs 工具,用于创建 ExtUtils::MakeMaker 基于项目。然而,对于纯 Perl 项目,h2xs/EUMM 长期以来一直不受青睐,取而代之的是 Module::Install< /a>、Module::BuildDist::Zilla

是否有更现代的方式来创建 XS 项目? Module::Starter 可以创建 XS 项目吗? Module::Build 或 Dist::Zilla 可以构建 XS 项目吗?他们的播客页面对此事保持沉默。

另一方面,针对 h2xs/EUMM 的批评是否适用于 XS 项目?如果您无论如何都需要一个 C 编译器,那么还需要一个 make 工具是否合理?

编辑:我看到这个问题 回答了我关于创建项目的问题。我仍然想了解有关构建的信息:EUMM 是唯一的选择,还是 Module::Build 和 Dist::Zilla 也能够构建 XS?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

海夕 2024-09-23 19:48:26

事实证明,Module::Build 完全能够编译 XS。这是我设法拼凑在一起的完整 Build.PL:

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;

这将构建一个包含 include 中的 .h 包含文件(例如 ppport.h)的发行版/ 目录,src/ 目录中的.c 源文件,以及 Chocolate 包对应的 .xs 文件::Belgian 在项目基目录中。

extra_compiler_flags 对应于 make CCFLAGS,而 extra_linker_flags 对应于 LIBS (所以你可能需要 -lm< /code> 链接 C 数学库)。

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).

蔚蓝源自深海 2024-09-23 19:48:26

Dist::Zilla 不是 EUMM 或 Module::Build 的替代品,它会为你生成一个 Makefile.Pl (等等),我不会很惊讶地听到它无法为 XS 项目执行此操作,但有一些方法可以管理您自己的 dzil 项目。它可以与它提供的任何Makefile.Pl(或Build.pl)一起使用。

因此,我对您问题中的 Dist::Zilla 部分的回答是,Dist::Zilla 在项目中不担任该角色。

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.

云朵有点甜 2024-09-23 19:48:26

我总是使用一些相当简单的 XS 发行版作为起点。 h2xs 可以通过解析标头来生成一些 XS,但大多数时候,我发现这太有限了,没有什么用处。

如果您打算包装 C++,您可能需要看看 Module::Build::WithXSpp。

I always just use some fairly simple XS distribution as a starting point. h2xs can do some of the XS generation by parsing a header, but most of the time, I found that too limited to be useful.

If you're planning to wrap C++, you may want to take a look at Module::Build::WithXSpp.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文