Alien-Xmake
view release on metacpan or search on metacpan
my $xmake = Alien::Xmake->new;
print $xmake->version; # v3.0.6
print $xmake->buildid; # HEAD.9fdcf69f6
$xmake->show('platforms'); # @platforms = ('windows', 'linux', ...)
$xmake->show('targets', format => 'json'); # decoded JSON structure
$xmake->create('hello', template => 'console'); # scaffold a project
$xmake->configure(mode => 'debug'); # configure a build
$xmake->build; # build it
$xmake->run; # run the target
system $xmake->exe, '--help';
system $xmake->xrepo, qw[info libpng];
```
# DESCRIPTION
Xmake is a lightweight, cross-platform build utility based on Lua. It uses a Lua script to maintain project builds, but
List all available templates instead of creating (`--list`).
- **project**
Alternate project path (`-P`).
## `configure( %options )`
```perl
$xmake->configure(mode => 'debug', plat => 'windows', arch => 'x64');
```
Configures the current project (clone of `xmake config`). Accepts the shared platform/toolchain options (`plat`,
`arch`, `mode`, `kind`, `toolchain`, `toolchain_host`, `cross`, `target_os`, `sdk`, `runtimes`, `vs`,
`vs_toolset`, `vs_sdkver`, `vs_runtime`, `ndk`, `ndk_stdcxx`, `ndk_sdkver`, `android_sdk`, `mingw`, `emsdk`,
`cuda`, `qt`, `qt_host`, `vcpkg`, `wdk`, `build_toolver`, `ccache`, `ccachedir`, `debugger`, `trybuild`,
`tryconfigs`, `require`, `includedirs`, `linkdirs`, `links`, `syslinks`, `rc*`, `fc*`, ...) as well as the
compiler/flag subtables `cflags`, `cxflags`, `cxxflags`, `mflags`, `mmflags`, `mxflags`, `ldflags`, `arflags`,
`asflags`, `shflags`, and `cuflags`. Any `--key=value` pair can be passed via `set => { key => value }`.
- **clean**
Reset the configuration to defaults (`-c`).
- **check**
`qt_host`, `vcpkg`, `vs`, `wdk`).
- **clean**
Reset global configuration to defaults (`-c`).
- **check**, **menu**
Same semantics as `configure( ... )`.
- **theme**, **debugger**, **ccache**
Global UI/terminal settings.
- **cachedir**
Global cache directory.
- **policies**
Global policy overrides (`--policies=`).
Standard package-install controls. **clean\_modes** resets the configs of the matched packages, **clean** only clears
unused packages, **build** always build from source, and **addon** manages addon packages.
## `run( [$target], %options )`
```perl
$xmake->run;
$xmake->run('hello', args => [qw[--flag value]]);
```
Runs the build target (or the `run` script). `debug` attaches a debugger, `all`/`group` select targets, `workdir`
sets the working directory (`-w`), `jobs` sets the parallelism and `detach` runs the target in the background. Extra
program arguments go in `args`.
## `test( [$target], %options )`
```perl
$xmake->test;
$xmake->test( 'hello', rebuild => 1 );
```
Swift, D, Zig, Vale, Pascal, Nim, Fortran, and more. You can also generate boilerplate projects for simple console
apps, static and shared libraries, macOS bundles, GUI apps based on Qt or wxWidgets, IOS apps, and more.
See `xmake create --help` for a full list.
The following examples drive xmake from Perl. These all call the wrapper methods (see ["METHODS"](#methods)), so output is
streamed to your terminal and each returns truthy on success.
## Scaffold, configure, build, test and run a target
The whole edit-run-debug lifecycle. `create` scaffolds a fresh project (`template` picks the base), `configure` sets
the build mode, then `build`/`test`/`run` compile, run the tests (if any) and launch the binary:
```perl
use v5.40;
use Alien::Xmake;
my $x = Alien::Xmake->new;
$x->create('demo', template => 'console'); # writes xmake.lua + src/main.cpp
chdir 'demo';
lib/Alien/Xmake.pm view on Meta::CPAN
$hit;
};
}
method global (%opts) {
my @args;
push @args, '-c' if $opts{clean};
push @args, '--check' if $opts{check};
push @args, '--menu' if $opts{menu};
push @args, '--theme=' . $opts{theme} if $opts{theme};
push @args, '--debugger=' . $opts{debugger} if $opts{debugger};
push @args, '--ccache=' . $opts{ccache} if defined $opts{ccache};
push @args, '--cachedir=' . $opts{cachedir} if $opts{cachedir};
push @args, '--policies=' . $opts{policies} if $opts{policies};
push @args, '--network=' . $opts{network} if $opts{network};
push @args, '--insecure-ssl' if $opts{insecure_ssl};
push @args, '--proxy=' . $opts{proxy} if $opts{proxy};
push @args, '--proxy_hosts=' . $opts{proxy_hosts} if $opts{proxy_hosts};
push @args, '--proxy_pac=' . $opts{proxy_pac} if $opts{proxy_pac};
push @args, '--pkg_searchdirs=' . $self->_join( $opts{pkg_searchdirs}, ';' ) if $opts{pkg_searchdirs};
push @args, '--pkg_cachedir=' . $opts{pkg_cachedir} if $opts{pkg_cachedir};
lib/Alien/Xmake.pm view on Meta::CPAN
push @args, $pkg if defined $pkg && length $pkg;
push @args, $self->_extra_args( \%opts );
# Query modes: return the output instead of streaming it.
return $self->_out( 'require', \%opts, @args ) if $opts{list} || $opts{scan} || $opts{info} || $opts{depgraph};
$self->_run( 'require', @args );
}
method run ( $target //= (), %opts ) {
my @args;
push @args, '-d' if $opts{debug};
push @args, '-a' if $opts{all};
push @args, '-g', $opts{group} if $opts{group};
push @args, '-w', $opts{workdir} if $opts{workdir};
push @args, '-j', $opts{jobs} if $opts{jobs};
push @args, '--detach' if $opts{detach};
push @args, $target if defined $target && length $target;
push @args, $self->_extra_args( \%opts );
$self->_run( 'run', @args );
}
lib/Alien/Xmake.pm view on Meta::CPAN
# Translate the shared xmake `f`-style option names into command line switches.
method _config_args ($opts) {
my @args;
push @args, '-p', $opts->{plat} if $opts->{plat};
push @args, '-a', $opts->{arch} if $opts->{arch};
push @args, '-m', $opts->{mode} if $opts->{mode};
push @args, '-k', $opts->{kind} if $opts->{kind};
for my $key (
qw[toolchain toolchain_host cross target_os bin sdk runtimes ndk ndk_sdkver android_sdk
build_toolver ndk_stdcxx cuda cuda_sdkver qt qt_host qt_sdkver vcpkg mingw emsdk vs vs_toolset
vs_sdkver vs_runtime wdk wdk_sdkver wdk_winver debugger ccache ccachedir trybuild tryconfigs
require pkg_searchdirs pkg_cachedir pkg_installdir rc rcld rcar rcsh fc fcld fcsh linkdirs links
syslinks includedirs ]
) {
push @args, "--$key=" . $self->_join( $opts->{$key}, ';' ) if defined $opts->{$key};
}
push @args, "--$_=$opts->{set}{$_}" for sort keys %{ $opts->{set} // {} };
@args;
}
# Introspection helpers
lib/Alien/Xmake.pod view on Meta::CPAN
my $xmake = Alien::Xmake->new;
print $xmake->version; # v3.0.6
print $xmake->buildid; # HEAD.9fdcf69f6
$xmake->show('platforms'); # @platforms = ('windows', 'linux', ...)
$xmake->show('targets', format => 'json'); # decoded JSON structure
$xmake->create('hello', template => 'console'); # scaffold a project
$xmake->configure(mode => 'debug'); # configure a build
$xmake->build; # build it
$xmake->run; # run the target
system $xmake->exe, '--help';
system $xmake->xrepo, qw[info libpng];
=head1 DESCRIPTION
Xmake is a lightweight, cross-platform build utility based on Lua. It uses a Lua script to maintain project builds, but
is driven by a dependency-free core program written in C. Compared with Makefiles or CMake, the configuration syntax is
lib/Alien/Xmake.pod view on Meta::CPAN
List all available templates instead of creating (C<--list>).
=item B<project>
Alternate project path (C<-P>).
=back
=head2 C<configure( %options )>
$xmake->configure(mode => 'debug', plat => 'windows', arch => 'x64');
Configures the current project (clone of C<xmake config>). Accepts the shared platform/toolchain options (C<plat>,
C<arch>, C<mode>, C<kind>, C<toolchain>, C<toolchain_host>, C<cross>, C<target_os>, C<sdk>, C<runtimes>, C<vs>,
C<vs_toolset>, C<vs_sdkver>, C<vs_runtime>, C<ndk>, C<ndk_stdcxx>, C<ndk_sdkver>, C<android_sdk>, C<mingw>, C<emsdk>,
C<cuda>, C<qt>, C<qt_host>, C<vcpkg>, C<wdk>, C<build_toolver>, C<ccache>, C<ccachedir>, C<debugger>, C<trybuild>,
C<tryconfigs>, C<require>, C<includedirs>, C<linkdirs>, C<links>, C<syslinks>, C<rc*>, C<fc*>, ...) as well as the
compiler/flag subtables C<cflags>, C<cxflags>, C<cxxflags>, C<mflags>, C<mmflags>, C<mxflags>, C<ldflags>, C<arflags>,
C<asflags>, C<shflags>, and C<cuflags>. Any C<--key=value> pair can be passed via C<set =E<gt> { key =E<gt> value }>.
=over
=item B<clean>
Reset the configuration to defaults (C<-c>).
lib/Alien/Xmake.pod view on Meta::CPAN
=over
=item B<clean>
Reset global configuration to defaults (C<-c>).
=item B<check>, B<menu>
Same semantics as C<configure( ... )>.
=item B<theme>, B<debugger>, B<ccache>
Global UI/terminal settings.
=item B<cachedir>
Global cache directory.
=item B<policies>
Global policy overrides (C<--policies=>).
lib/Alien/Xmake.pod view on Meta::CPAN
Standard package-install controls. B<clean_modes> resets the configs of the matched packages, B<clean> only clears
unused packages, B<build> always build from source, and B<addon> manages addon packages.
=back
=head2 C<run( [$target], %options )>
$xmake->run;
$xmake->run('hello', args => [qw[--flag value]]);
Runs the build target (or the C<run> script). C<debug> attaches a debugger, C<all>/C<group> select targets, C<workdir>
sets the working directory (C<-w>), C<jobs> sets the parallelism and C<detach> runs the target in the background. Extra
program arguments go in C<args>.
=head2 C<test( [$target], %options )>
$xmake->test;
$xmake->test( 'hello', rebuild => 1 );
Runs the project's tests. C<group>, C<workdir>, C<jobs> and C<rebuild> behave as elsewhere.
lib/Alien/Xmake.pod view on Meta::CPAN
Swift, D, Zig, Vale, Pascal, Nim, Fortran, and more. You can also generate boilerplate projects for simple console
apps, static and shared libraries, macOS bundles, GUI apps based on Qt or wxWidgets, IOS apps, and more.
See C<xmake create --help> for a full list.
The following examples drive xmake from Perl. These all call the wrapper methods (see L</METHODS>), so output is
streamed to your terminal and each returns truthy on success.
=head2 Scaffold, configure, build, test and run a target
The whole edit-run-debug lifecycle. C<create> scaffolds a fresh project (C<template> picks the base), C<configure> sets
the build mode, then C<build>/C<test>/C<run> compile, run the tests (if any) and launch the binary:
use v5.40;
use Alien::Xmake;
my $x = Alien::Xmake->new;
$x->create('demo', template => 'console'); # writes xmake.lua + src/main.cpp
chdir 'demo';
$x->configure(mode => 'release'); # configure the build
t/001_xmake.t view on Meta::CPAN
ok !scalar @none, 'lua_json with no JSON returns empty list';
};
subtest 'scaffold a project and drive it' => sub {
my $old = getcwd;
my $dir = tempdir( CLEANUP => 0 );
chdir $dir or die "chdir $dir: $!";
local $@;
ok $xmake->create( 't_demo', template => 'console' ), 'create scaffolds a project';
ok -f 't_demo/xmake.lua', 'xmake.lua was generated';
chdir 't_demo' or die 'chdir t_demo: $!';
ok $xmake->configure( mode => 'debug', jobs => 2 ), 'configure succeeds';
my $targets = $xmake->show( 'targets', format => 'json' );
is ref $targets, 'ARRAY', 'show -l targets --format=json is an array';
ok scalar @{$targets}, 'at least one target';
my $t = $xmake->target_info( $targets->[0] );
is ref $t, 'HASH', 'target_info returns a decoded HASH';
ok $t->{name} && $t->{kind}, 'target_info has name and kind';
ok defined $t->{targetfile}, 'target_info exposes targetfile';
my $t_plain = $xmake->target_info( $targets->[0], plain => 1 );
ok length $t_plain, 'target_info(plain=>1) returns text';
ok $xmake->clean, 'clean succeeds';
t/003_broken_config.t view on Meta::CPAN
return $d;
}
#
sub phantom_count ($text) {
return scalar grep {/^Can't spawn /} split /\n/, $text;
}
#
subtest 'never-resolvable config fails cleanly without phantom warnings' => sub {
make_broken();
my $ret;
my ( $out, $err ) = capture { $ret = $xmake->configure( mode => 'debug' ) };
ok !$ret, 'configure returns false (no toolchain can ever resolve)';
is phantom_count($err), 0, "no phantom Can't spawn lines in the streamed path";
my $compiler = Alien::Xmake::_c_compiler_on_path();
if ( defined $compiler ) {
unlike $err, qr[retrying with --toolchain], 'retry hint stays quiet unless verbose';
my $loud = Alien::Xmake->new( verbose => 1 );
my ( $l_out, $l_err ) = capture { $loud->configure( mode => 'debug' ) };
like $l_err, qr[retrying with --toolchain], "verbose: retried once with --toolchain=($compiler)";
is phantom_count($l_err), 0, 'the verbose path also stays phantom-free';
}
else {
ok 1, 'no compiler on PATH; the retry step is skipped by design';
}
note 'stderr excerpt: ' . substr( $err, 0, 120 ) if length $err;
};
#
subtest 'nonzero xmake exits under the spawn wrapper stay ghost-free' => sub {
( run in 0.904 second using v1.01-cache-2.11-cpan-c32d3c3b8f1 )