The Great Divide: Alien::Build vs. Alien::Xrepo::Base #3
sanko
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Perl developers have almost always faced a dependency problem: how do you ensure a CPAN module can find, download, and build a non-Perl library? Whether it’s
openssl,libpng, ornuklear, the traditional solution has been a complex dance of shell commands,pkg-configprobes, and precariousmakeinvocations.Today, we have two primary philosophies for solving this. On one side stands Alien::Build, the mature, flexible Swiss Army knife of the Perl ecosystem. On the other stands Alien::Xrepo::Base, a new contender that leverages the cross-platform power of the Xmake/Xrepo ecosystem and Perl 5.40's native
classfeatures.In this article, we’ll compare these two approaches and see why moving from "Recipes" to "Registries" might be the biggest productivity boost for Alien authors in years.
1. Alien::Build: The Recipe-Based Approach
Alien::Build(and its companionalienfile) is built on the idea of a recipe. As an author, you write a DSL that describes exactly how to fetch, build, and probe a library.Example: A typical
alienfilefornuklearNuklear is a single-header library, which sounds easy, but to use it with FFI, you must create a C wrapper to compile it into a shared library. (Worth noting: because nuklear is header-only — Xrepo declares it
set_kind("library", { headeronly = true })— there is no prebuiltnuklear.so/nuklear.dllanywhere; you always have to synthesize one for FFI, in Alien::Build or in a registry.)2. Alien::Xrepo::Base: The Registry-Based Approach
Alien::Xrepo::Basetakes a different path. Instead of teaching Perl how to build a specific library, it delegates that responsibility to Xrepo, which already knows how to turn a package likezlibinto a usable shared library.Why
alienfilesteps are redundant with XrepoWhen you use
Alien::Xrepo::Base, the three pillars ofalienfileeffectively disappear:Autoconf,CMake,Meson, orBazel. It handles compiler flags, cross-compilation, and dependency trees automatically.Example: The "Quick & Easy"
Alien::Xrepo::BasesubclassHere is the equivalent
Alien::Zlibusing the new Perl 5.40 syntax:That's it. You don't need to know where the source code lives, how to run
make, or howto find
zlib1.dll/libz.so. You simply ask for the package by name, and the registryhands you a shared library ready for FFI.
3. Comparing the Developer Experience
class).4. Integration with Distribution Builders
Whether you use
Module::BuildorExtUtils::MakeMaker(EUMM), an Alien module needs to hook into the install process to trigger the native build.Using Module::Build (with Alien::Xrepo::Base)
Alien::Xrepo::Baseprovides a helper that makesBuild.PLtrivial. It essentially generates a tinyModule::Build::Tinyclone that understands the Xrepo lifecycle.Build.PL:
When a user runs
./Build,Alien::Xrepo::Basewill:xrepo install zlibinto theblibshare directory.ConfigData.pmcontaining the resolved metadata from Xrepo.Note:
Build_PLreads the distribution'sMETA.jsonto name the generatedBuildscript, so that file must exist before you run
Build_PL('Alien::Zlib').Using ExtUtils::MakeMaker
If you prefer the classic
Makefile.PLapproach, you can still drive the Xmake/Xrepoengine directly. The
cflags/libsaccessors (and theroot-isolated install) areprovided by
Alien::Xrepo::Base; instantiate that instead of the lower-levelAlien::Xrepo, whoseinstallreturns a rawPackageInfowith no such methods.Makefile.PL:
5. The "Zero-Recipe" Advantage
The true strength of
Alien::Xrepo::Baseis revealed when a library has complex dependencies of its own.Imagine building
libwebp. It might requirelibjpeg,libpng, andzlib. In theAlien::Buildworld, you would need to create four separate Alien distributions and coordinate theiralienfiles so they find each other.In the
Alien::Xrepo::Baseworld, you just ask forlibwebp. Xrepo resolves the tree, builds all four libraries in the correct order, links them together, and hands you a singlePackageInfoobject.By basing your work on
Alien::Xrepo::Base, you aren't just writing a wrapper; you are tapping into a global effort to make C/C++ libraries as easy to install as CPAN modules.Summary
Alien::Build remains the right choice if:
Alien::Xrepo::Base is the superior choice if:
Makefileerrors.By moving the "Recipe" out of your Perl code and into a managed registry like Xrepo, you reduce the surface area for bugs and ensure your Alien module stays working long after you've stopped updating the download URLs.
All reactions