NAME

Alien::Xmake::Project - Compose and drive an xmake project from Perl

SYNOPSIS

use v5.40;
use Alien::Xmake::Project;

my $p = Alien::Xmake::Project->new( file => 'build/xmake.lua' );
$p->set_project('myapp')->set_version('0.1.0');
$p->add_requires('zlib');

$p->target('cli')
    ->set_kind('binary')
    ->add_files('src/*.cpp')
    ->add_packages('zlib');

$p->save;                                   # writes build/xmake.lua

$p->xmake->configure(mode => 'release');    # xmake configure -F build/xmake.lua
$p->xmake->build;
$p->xmake->run;

DESCRIPTION

xmake.lua is just a Lua file. Rather than editing it by hand, this class lets you describe a project with fluent Perl method calls and then hands you a normal Alien::Xmake object. Using chains like $p->set_kind('binary')->add_files('src/*.cpp') you may drive every stage (configure, build, run, install, IDE generation, queries) directly from Perl.

CONSTRUCTOR

new( ... )

my $p = Alien::Xmake::Project->new(
    file => 'build/xmake.lua',   # where save() writes the build file
    yes  => 1                    # auto-confirm prompts, forwarded to Alien::Xmake
);

METHODS

Project level

Identity

Global options and defaults

Global scope (applies to every target)

Structure

Packages and repositories

Domain builders

Emission and execution

Target builder

Each method is chainable and corresponds to the same-named xmake.lua statement inside a target(...) block. A trailing hashref is emitted as an options table; true/false emit bare Lua booleans.

Option builder

An option(...) block describes a configurable build option. Every method is chainable. A trailing hashref becomes an options table; true/false emit bare Lua booleans. Note that an option created with the inline table form (option('name', { ... })) cannot be extended with these setters.

Rule builder

A rule(...) block describes a custom build rule. Every method is chainable.

Toolchain builder

A toolchain(...) block describes a custom toolchain. Every method is chainable.

Package builder

A package(...) block describes how a dependency package is fetched and installed. Every method is chainable; a trailing hashref becomes an options table; true/false emit bare Lua booleans.

Xpack builder

An xpack(...) block describes a distributable installer package. The first xpack call also emits includes("@builtin/xpack") to enable the plugin. Every method is chainable; a trailing hashref becomes an options table; true/false emit bare Lua booleans.

XpackComponent builder

An xpack_component(...) block describes one sub-component of an xpack. Every method is chainable.

OPTION TABLES AND BOOLEANS

Any method that in xmake takes a trailing table accepts a Perl hashref as its last argument. It is rendered with bracket keys so any string key is valid Lua:

$t->add_files('src/*.cpp', { unity_group => 'core' });   # add_files("src/*.cpp", {["unity_group"]="core"})

Use the v5.36+ true/false keywords for booleans so xmake receives a real boolean, not the string "1":

$p->add_requires('zlib', { shared => true });

Key order in tables is deterministic (sorted).

EXAMPLES

A dependency-driven executable and a shared library with a test, built from Perl:

use v5.40;
use Alien::Xmake::Project;

my $p = Alien::Xmake::Project->new(file => 'xmake.lua');
$p->set_project('app')->set_version('0.1.0');
$p->add_rules('mode.debug', 'mode.release');
$p->add_requires('zlib', { configs => { shared => true } });

$p->target('core')
    ->set_kind('shared')
    ->add_files('src/core/*.cpp')
    ->add_packages('zlib');

$p->target('app')
    ->set_kind('binary')
    ->add_files('src/main.cpp')
    ->add_deps('core')
    ->add_packages('zlib')
    ->set_languages('c++20')
    ->add_values('wasm.preloadfiles', 'src/assets/app.js')
    ->on_install('windows', 'function (target) end');

$p->save;

$p->xmake->configure(mode => 'release');
$p->xmake->build;
$p->xmake->test;
$p->xmake->project(kind => 'vsxmake');   # feed any IDE generator

SEE ALSO

Alien::Xmake, the example in eg/xmake_project.pl

LICENSE

Copyright (C) Sanko Robinson.

This library is free software; you can redistribute it and/or modify it under the terms found in the Artistic License 2. Other copyrights, terms, and conditions may apply to data transmitted through this module.

AUTHOR

Sanko Robinson https://github.com/sanko