xmake as a Build Back-End for Perl + C Projects #4
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.
Uh oh!
There was an error while loading. Please reload this page.
If your Perl distribution contains C code that needs to be compiled (an
.xsextension, a helper tool, or a shared library for FFI) you have traditionally reached forExtUtils::MakeMaker,Module::Build, orAlien::Build. Each drivesmakeorcmakethrough its own abstraction.Alien::Xmaketakes a different approach: it is xmake, directly callable from Perl. If your C code already has (or could have) anxmake.luabuild description, you can skip the MakeMaker layer entirely and let xmake handle the build, test, install, and packaging all invoked from a two-lineBuild.PLorMakefile.PL.What is xmake?
xmake is a cross-platform, Lua-scriptable build system. It supports C, C++, Rust, Go, and more; runs on Windows, macOS, and Linux; and integrates directly with xrepo (its package manager). A single
xmake.luadescribes your targets, dependencies, and build rules.Driving xmake from Perl
Alien::Xmakegives you the xmake binary, a convenience constructor, and a one-to-one method for every xmake action:Every method corresponds to a command-line invocation (
xmake build,xmake test, etc.). Theverboseflag prints the commands as they run, which is invaluable during development.The
task()escape hatchIf a method doesn't exist for a particular xmake command (and I haven't noticed such an upstream change yet),
task()is the escape hatch to run the command manually.task()forwards arguments two ways: a target list viatargets => [...], and raw command-line arguments viaargs => [...]:You can also write to xmake's persistent global configuration:
A practical example: the nuklear single-header library
Nuklear is a single-header GUI library. There is no prebuilt
nuklear.soanywhere, you have to synthesize one. Anxmake.luathat does this is just a few lines:Driving this from Perl looks like this:
No
Makefile.PL, noalienfile, noExtUtils::CBuilder, just a three line Perl driver on top of a four linexmake.lua.Dependency graphs
If your
xmake.luadeclares xrepo dependencies, you can ask xrepo—throughAlien::Xrepo—to print the full dependency graph in Graphviz DOT format.Alien::Xrepoexposes aninfomethod that renders the graph that xmake itself produces:This is the same graph that xmake renders. It may be useful for understanding a complex native dependency tree without leaving Perl.
When xmake makes sense
-p,-a,--toolchain,--ndkflags map directly toAlien::Xmake->build().xmake packagecreates a distributable archive;xmake packproduces.deb/.rpm/.nsiinstallers all callable via$xmake->package().Makefile.PLfor anything beyond trivial C code.For the right project, xmake replaces an entire build toolchain with a single Lua file and a two-line Perl driver.
All reactions