Alien-Xmake
view release on metacpan or search on metacpan
lib/Alien/Xrepo.pm view on Meta::CPAN
system(@install_cmd) == 0 or die "xrepo install failed for $full_spec";
# Fetch (must use same args to get correct paths for arch/mode)
warn "[*] xrepo: fetching paths...\n" if $verbose;
my @fetch_cmd = ( $xmake->exe, qw[lua private.xrepo], 'fetch', '--json', @args, $full_spec );
$self->blah("Running: @fetch_cmd");
my ( $json_out, $json_err, $json_exit ) = capture { system @fetch_cmd };
die "xrepo fetch failed:\nCommand: @fetch_cmd\nError:\n$json_err" if $json_exit != 0;
my $data;
try { $data = decode_json($json_out); } catch ($e) {
die "Failed to decode xrepo JSON output: $e\nOutput was: $json_out"
};
# xrepo might return a single object or a list.
$self->_process_info( ( ref $data eq 'ARRAY' ) ? $data->[0] : $data );
}
method uninstall ( $pkg_spec, %opts ) {
my @args = $self->_build_args( \%opts );
say "[*] xrepo: uninstalling $pkg_spec..." if $verbose;
system $xmake->exe, qw[lua private.xrepo], 'remove', '-y', @args, $pkg_spec;
}
method search ($query) {
say "[*] xrepo: searching for $query..." if $verbose;
system $xmake->exe, qw[lua private.xrepo], 'search', $query;
}
method clean () {
say '[*] xrepo: cleaning cache...' if $verbose;
system $xmake->exe, qw[lua private.xrepo], 'clean', '-y';
}
#
method add_repo ( $name, $url, $branch //= () ) {
say "[*] xrepo: adding repo $name..." if $verbose;
my @cmd = ( $xmake->exe, qw[lua private.xrepo], 'add-repo', '-y', $name, $url );
push @cmd, $branch if defined $branch;
my ( $out, $err, $exit ) = capture { system @cmd };
die "xrepo add-repo failed:\n$err" if $exit != 0;
return 1;
}
method remove_repo ($name) {
say "[*] xrepo: removing repo $name..." if $verbose;
system $xmake->exe, qw[lua private.xrepo], 'remove-repo', '-y', $name;
}
method update_repo ( $name //= () ) {
say '[*] xrepo: updating repositories...' if $verbose;
my @cmd = ( $xmake->exe, qw[lua private.xrepo], 'update-repo', '-y' );
push @cmd, $name if defined $name;
system @cmd;
}
#
method _build_args ($opts) {
my @args;
# Standard xmake/xrepo flags
push @args, '-p', $opts->{plat} if $opts->{plat}; # platform (iphoneos, android, etc)
push @args, '-a', $opts->{arch} if $opts->{arch}; # architecture (arm64, x86_64)
push @args, '-m', $opts->{mode} if $opts->{mode}; # debug/release
push @args, '-k', ( $opts->{kind} // 'shared' ); # static/shared (Default to shared for FFI)
push @args, '--toolchain=' . $opts->{toolchain} if $opts->{toolchain};
# Complex configs (passed as --configs='key=val,key2=val2')
if ( my $c = $opts->{configs} ) {
if ( ref $c eq 'HASH' ) {
my $str = join( ',', map {"$_=$c->{$_}"} sort keys %$c );
push @args, "--configs=$str";
}
else {
push @args, "--configs=$c";
}
}
# Build Includes (deps)
if ( my $i = $opts->{includes} ) {
push @args, '--includes=' . ( ref $i eq 'ARRAY' ? join( ',', @$i ) : $i );
}
return @args;
}
method _process_info ($info) {
return () unless defined $info;
my $libfiles = $info->{libfiles} // [];
my $incdirs = $info->{includedirs} // [];
my $linkdirs = $info->{linkdirs} // [];
my $bindirs = $info->{bindirs} // [];
# 1. Validate that we actually got files back
unless (@$libfiles) {
$self->blah('[!] xrepo returned no library files. Package might be header-only.');
# Return a generic object (likely header-only)
return Alien::Xrepo::PackageInfo->new(
includedirs => $incdirs,
libfiles => [],
libpath => undef,
linkdirs => $linkdirs,
links => $info->{links} // [],
license => $info->{license} // (),
shared => $info->{shared} // 0,
static => $info->{static} // 0,
version => $info->{version} // ()
);
}
# 2. Heuristic to find the Runtime Library (DLL/SO/DyLib) for FFI
my $runtime_lib;
if ( $^O eq 'MSWin32' ) {
# Check if the DLL is already in libfiles (MinGW often does this)
($runtime_lib) = grep {/\.dll$/i} @$libfiles;
# If not, we must hunt for it in the 'bin' directory sibling to the 'lib' directory.
unless ($runtime_lib) {
my ($imp_lib) = grep {/\.lib$/i} @$libfiles;
if ($imp_lib) {
my $lib_path = path($imp_lib);
my $basename = $lib_path->basename(qr/\.lib$/i); # e.g., 'zlib' from 'zlib.lib'
( run in 0.376 second using v1.01-cache-2.11-cpan-02777c243ea )