Initial Commit

This commit is contained in:
Riley Schneider
2025-12-03 16:38:10 +01:00
parent c5e26bf594
commit b732d8d4b5
17680 changed files with 5977495 additions and 2 deletions

View File

@@ -0,0 +1,297 @@
package Alien::Build::Plugin::Probe::CBuilder;
use strict;
use warnings;
use 5.008004;
use Alien::Build::Plugin;
use File::chdir;
use File::Temp ();
use Capture::Tiny qw( capture_merged capture );
# ABSTRACT: Probe for system libraries by guessing with ExtUtils::CBuilder
our $VERSION = '2.38'; # VERSION
has options => sub { {} };
has cflags => '';
has libs => '';
has program => 'int main(int argc, char *argv[]) { return 0; }';
has version => undef;
has aliens => [];
has lang => 'C';
sub init
{
my($self, $meta) = @_;
$meta->add_requires('configure' => 'ExtUtils::CBuilder' => 0 );
if(@{ $self->aliens })
{
die "You can't specify both 'aliens' and either 'cflags' or 'libs' for the Probe::CBuilder plugin" if $self->cflags || $self->libs;
$meta->add_requires('configure' => $_ => 0 ) for @{ $self->aliens };
$meta->add_requires('Alien::Build::Plugin::Probe::CBuilder' => '0.53');
my $cflags = '';
my $libs = '';
foreach my $alien (@{ $self->aliens })
{
my $pm = "$alien.pm";
$pm =~ s/::/\//g;
require $pm;
$cflags .= $alien->cflags . ' ';
$libs .= $alien->libs . ' ';
}
$self->cflags($cflags);
$self->libs($libs);
}
my @cpp;
if($self->lang ne 'C')
{
$meta->add_requires('Alien::Build::Plugin::Probe::CBuilder' => '0.53');
@cpp = ('C++' => 1) if $self->lang eq 'C++';
}
$meta->register_hook(
probe => sub {
my($build) = @_;
$build->hook_prop->{probe_class} = __PACKAGE__;
$build->hook_prop->{probe_instance_id} = $self->instance_id;
local $CWD = File::Temp::tempdir( CLEANUP => 1, DIR => $CWD );
open my $fh, '>', 'mytest.c';
print $fh $self->program;
close $fh;
$build->log("trying: cflags=@{[ $self->cflags ]} libs=@{[ $self->libs ]}");
my $cb = ExtUtils::CBuilder->new(%{ $self->options });
my($out1, $obj) = capture_merged { eval {
$cb->compile(
source => 'mytest.c',
extra_compiler_flags => $self->cflags,
@cpp,
);
} };
if(my $error = $@)
{
$build->log("compile failed: $error");
$build->log("compile failed: $out1");
die $@;
}
my($out2, $exe) = capture_merged { eval {
$cb->link_executable(
objects => [$obj],
extra_linker_flags => $self->libs,
);
} };
if(my $error = $@)
{
$build->log("link failed: $error");
$build->log("link failed: $out2");
die $@;
}
my($out, $err, $ret) = capture { system($^O eq 'MSWin32' ? $exe : "./$exe") };
die "execute failed" if $ret;
my $cflags = $self->cflags;
my $libs = $self->libs;
$cflags =~ s{\s*$}{ };
$libs =~ s{\s*$}{ };
$build->install_prop->{plugin_probe_cbuilder_gather}->{$self->instance_id} = {
cflags => $cflags,
libs => $libs,
};
if(defined $self->version)
{
my($version) = $out =~ $self->version;
$build->hook_prop->{version} = $version;
$build->install_prop->{plugin_probe_cbuilder_gather}->{$self->instance_id}->{version} = $version;
}
'system';
}
);
$meta->register_hook(
gather_system => sub {
my($build) = @_;
return if $build->hook_prop->{name} eq 'gather_system'
&& ($build->install_prop->{system_probe_instance_id} || '') ne $self->instance_id;
if(my $p = $build->install_prop->{plugin_probe_cbuilder_gather}->{$self->instance_id})
{
$build->runtime_prop->{$_} = $p->{$_} for keys %$p;
}
},
);
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Alien::Build::Plugin::Probe::CBuilder - Probe for system libraries by guessing with ExtUtils::CBuilder
=head1 VERSION
version 2.38
=head1 SYNOPSIS
use alienfile;
plugin 'Probe::CBuilder' => (
cflags => '-I/opt/libfoo/include',
libs => '-L/opt/libfoo/lib -lfoo',
);
alternately:
ues alienfile;
plugin 'Probe::CBuilder' => (
aliens => [ 'Alien::libfoo', 'Alien::libbar' ],
);
=head1 DESCRIPTION
This plugin probes for compiler and linker flags using L<ExtUtils::CBuilder>. This is a useful
alternative to L<Alien::Build::Plugin::PkgConfig::Negotiate> for packages that do not provide
a pkg-config C<.pc> file, or for when those C<.pc> files may not be available. (For example,
on FreeBSD, C<libarchive> is a core part of the operating system, but doesn't include a C<.pc>
file which is usually provided when you install the C<libarchive> package on Linux).
=head1 PROPERTIES
=head2 options
Any extra options that you want to have passed into the constructor to L<ExtUtils::CBuilder>.
=head2 cflags
The compiler flags.
=head2 libs
The linker flags
=head2 program
The program to use in the test.
=head2 version
This is a regular expression to parse the version out of the output from the
test program.
=head2 aliens
List of aliens to query fro compiler and linker flags.
=head2 lang
The programming language to use. One of either C<C> or C<C++>.
=head1 SEE ALSO
L<Alien::Build>, L<alienfile>, L<Alien::Build::MM>, L<Alien>
=head1 AUTHOR
Author: Graham Ollis E<lt>plicease@cpan.orgE<gt>
Contributors:
Diab Jerius (DJERIUS)
Roy Storey (KIWIROY)
Ilya Pavlov
David Mertens (run4flat)
Mark Nunberg (mordy, mnunberg)
Christian Walde (Mithaldu)
Brian Wightman (MidLifeXis)
Zaki Mughal (zmughal)
mohawk (mohawk2, ETJ)
Vikas N Kumar (vikasnkumar)
Flavio Poletti (polettix)
Salvador Fandiño (salva)
Gianni Ceccarelli (dakkar)
Pavel Shaydo (zwon, trinitum)
Kang-min Liu (劉康民, gugod)
Nicholas Shipp (nshp)
Juan Julián Merelo Guervós (JJ)
Joel Berger (JBERGER)
Petr Pisar (ppisar)
Lance Wicks (LANCEW)
Ahmad Fatoum (a3f, ATHREEF)
José Joaquín Atria (JJATRIA)
Duke Leto (LETO)
Shoichi Kaji (SKAJI)
Shawn Laffan (SLAFFAN)
Paul Evans (leonerd, PEVANS)
Håkon Hægland (hakonhagland, HAKONH)
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2011-2020 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut

View File

@@ -0,0 +1,248 @@
package Alien::Build::Plugin::Probe::CommandLine;
use strict;
use warnings;
use 5.008004;
use Alien::Build::Plugin;
use Carp ();
use Capture::Tiny qw( capture );
use File::Which ();
# ABSTRACT: Probe for tools or commands already available
our $VERSION = '2.38'; # VERSION
has '+command' => sub { Carp::croak "@{[ __PACKAGE__ ]} requires command property" };
has 'args' => [];
has 'secondary' => 0;
has 'match' => undef;
has 'match_stderr' => undef;
has 'version' => undef;
has 'version_stderr' => undef;
sub init
{
my($self, $meta) = @_;
my $check = sub {
my($build) = @_;
unless(File::Which::which($self->command))
{
die 'Command not found ' . $self->command;
}
if(defined $self->match || defined $self->match_stderr || defined $self->version || defined $self->version_stderr)
{
my($out,$err,$ret) = capture {
system( $self->command, @{ $self->args } );
};
die 'Command did not return a true value' if $ret;
die 'Command output did not match' if defined $self->match && $out !~ $self->match;
die 'Command standard error did not match' if defined $self->match_stderr && $err !~ $self->match_stderr;
if(defined $self->version)
{
if($out =~ $self->version)
{
$build->runtime_prop->{version} = $1;
}
}
if(defined $self->version_stderr)
{
if($err =~ $self->version_stderr)
{
$build->hook_prop->{version} = $1;
$build->runtime_prop->{version} = $1;
}
}
}
$build->runtime_prop->{command} = $self->command;
'system';
};
if($self->secondary)
{
$meta->around_hook(
probe => sub {
my $orig = shift;
my $build = shift;
my $type = $orig->($build, @_);
return $type unless $type eq 'system';
$check->($build);
},
);
}
else
{
$meta->register_hook(
probe => $check,
);
}
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Alien::Build::Plugin::Probe::CommandLine - Probe for tools or commands already available
=head1 VERSION
version 2.38
=head1 SYNOPSIS
use alienfile;
plugin 'Probe::CommandLine' => (
command => 'gzip',
args => [ '--version' ],
match => qr/gzip/,
version => qr/gzip ([0-9\.]+)/,
);
=head1 DESCRIPTION
This plugin probes for the existence of the given command line program.
=head1 PROPERTIES
=head2 command
The name of the command.
=head2 args
The arguments to pass to the command.
=head2 secondary
If you are using another probe plugin (such as L<Alien::Build::Plugin::Probe::CBuilder> or
L<Alien::Build::Plugin::PkgConfig::Negotiate>) to detect the existence of a library, but
also need a program to exist, then you should set secondary to a true value. For example
when you need both:
use alienfile;
# requires both liblzma library and xz program
plugin 'PkgConfig' => 'liblzma';
plugin 'Probe::CommandLine => (
command => 'xz',
secondary => 1,
);
When you don't:
use alienfile;
plugin 'Probe::CommandLine' => (
command => 'gzip',
secondary => 0, # default
);
=head2 match
Regular expression for which the program output should match.
=head2 match_stderr
Regular expression for which the program standard error should match.
=head2 version
Regular expression to parse out the version from the program output.
The regular expression should store the version number in C<$1>.
=head2 version_stderr
Regular expression to parse out the version from the program standard error.
The regular expression should store the version number in C<$1>.
=head1 SEE ALSO
L<Alien::Build>, L<alienfile>, L<Alien::Build::MM>, L<Alien>
=head1 AUTHOR
Author: Graham Ollis E<lt>plicease@cpan.orgE<gt>
Contributors:
Diab Jerius (DJERIUS)
Roy Storey (KIWIROY)
Ilya Pavlov
David Mertens (run4flat)
Mark Nunberg (mordy, mnunberg)
Christian Walde (Mithaldu)
Brian Wightman (MidLifeXis)
Zaki Mughal (zmughal)
mohawk (mohawk2, ETJ)
Vikas N Kumar (vikasnkumar)
Flavio Poletti (polettix)
Salvador Fandiño (salva)
Gianni Ceccarelli (dakkar)
Pavel Shaydo (zwon, trinitum)
Kang-min Liu (劉康民, gugod)
Nicholas Shipp (nshp)
Juan Julián Merelo Guervós (JJ)
Joel Berger (JBERGER)
Petr Pisar (ppisar)
Lance Wicks (LANCEW)
Ahmad Fatoum (a3f, ATHREEF)
José Joaquín Atria (JJATRIA)
Duke Leto (LETO)
Shoichi Kaji (SKAJI)
Shawn Laffan (SLAFFAN)
Paul Evans (leonerd, PEVANS)
Håkon Hægland (hakonhagland, HAKONH)
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2011-2020 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut

View File

@@ -0,0 +1,269 @@
package Alien::Build::Plugin::Probe::Vcpkg;
use strict;
use warnings;
use 5.008004;
use Alien::Build::Plugin;
# ABSTRACT: Probe for system libraries using Vcpkg
our $VERSION = '2.38'; # VERSION
has '+name';
has 'lib';
has 'ffi_name';
has 'include';
sub init
{
my($self, $meta) = @_;
if(defined $self->include)
{
$meta->add_requires('configure' => 'Alien::Build::Plugin::Probe::Vcpkg' => '2.16' );
}
elsif(defined $self->ffi_name)
{
$meta->add_requires('configure' => 'Alien::Build::Plugin::Probe::Vcpkg' => '2.14' );
}
else
{
$meta->add_requires('configure' => 'Alien::Build::Plugin::Probe::Vcpkg' => '0' );
}
if($meta->prop->{platform}->{compiler_type} eq 'microsoft')
{
$meta->register_hook(
probe => sub {
my($build) = @_;
$build->hook_prop->{probe_class} = __PACKAGE__;
$build->hook_prop->{probe_instance_id} = $self->instance_id;
eval {
require Win32::Vcpkg;
require Win32::Vcpkg::List;
require Win32::Vcpkg::Package;
Win32::Vcpkg->VERSION('0.02');
};
if(my $error = $@)
{
$build->log("unable to load Win32::Vcpkg: $error");
return 'share';
}
my $package;
if($self->name)
{
$package = Win32::Vcpkg::List->new
->search($self->name, include => $self->include);
}
elsif($self->lib)
{
$package = eval { Win32::Vcpkg::Package->new( lib => $self->lib, include => $self->include) };
return 'share' if $@;
}
else
{
$build->log("you must provode either name or lib property for Probe::Vcpkg");
return 'share';
}
my $version = $package->version;
$version = 'unknown' unless defined $version;
$build->install_prop->{plugin_probe_vcpkg}->{$self->instance_id} = {
version => $version,
cflags => $package->cflags,
libs => $package->libs,
};
$build->hook_prop->{version} = $version;
$build->install_prop->{plugin_probe_vcpkg}->{$self->instance_id}->{ffi_name} = $self->ffi_name
if defined $self->ffi_name;
return 'system';
},
);
$meta->register_hook(
gather_system => sub {
my($build) = @_;
return if $build->hook_prop->{name} eq 'gather_system'
&& ($build->install_prop->{system_probe_instance_id} || '') ne $self->instance_id;
if(my $c = $build->install_prop->{plugin_probe_vcpkg}->{$self->instance_id})
{
$build->runtime_prop->{version} = $c->{version} unless defined $build->runtime_prop->{version};
$build->runtime_prop->{$_} = $c->{$_} for grep { defined $c->{$_} } qw( cflags libs ffi_name );
}
},
);
}
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Alien::Build::Plugin::Probe::Vcpkg - Probe for system libraries using Vcpkg
=head1 VERSION
version 2.38
=head1 SYNOPSIS
use alienfile;
plugin 'Probe::Vcpkg' => 'libffi';
=head1 DESCRIPTION
This plugin probe can be used to find "system" packages using Microsoft's C<Vcpkg> package manager for
Visual C++ builds of Perl. C<Vcpkg> is a package manager for Visual C++ that includes a number of
open source packages. Although C<Vcpkg> does also support Linux and macOS, this plugin does not
support finding C<Vcpkg> packages on those platforms. For more details on C<Vcpkg>, see the project
github page here:
L<https://github.com/microsoft/vcpkg>
Here is the quick start guide for getting L<Alien::Build> to work with C<Vpkg>:
# install Vcpkg
C:\> git clone https://github.com/Microsoft/vcpkg.git
C:\> cd vcpkg
C:\vcpkg> .\bootstrap-vcpkg.bat
C:\vcpkg> .\vcpkg integrate install
# update PATH to include the bin directory
# so that .DLL files can be found by Perl
C:\vcpkg> path c:\vcpkg\installed\x64-windows\bin;%PATH%
# install the packages that you want
C:\vcpkg> .\vcpkg install libffi
# install the alien that uses it
C:\vcpkg> cpanm Alien::FFI
If you are using 32 bit build of Perl, then substitute C<x86-windows> for C<x64-windows>. If you do
not want to add the C<bin> directory to the C<PATH>, then you can use C<x64-windows-static> instead,
which will provide static libraries. (As of this writing static libraries for 32 bit Windows are not
available). The main downside to using C<x64-windows-static> is that Aliens that require dynamic
libraries for FFI will not be installable.
If you do not want to install C<Vcpkg> user wide (the C<integrate install> command above), then you
can use the C<PERL_WIN32_VCPKG_ROOT> environment variable instead:
# install Vcpkg
C:\> git clone https://github.com/Microsoft/vcpkg.git
C:\> cd vcpkg
C:\vcpkg> .\bootstrap-vcpkg.bat
C:\vcpkg> set PERL_WIN32_VCPKG_ROOT=c:\vcpkg
=head1 PROPERTIES
=head2 name
Specifies the name of the Vcpkg. This should not be used with the C<lib> property below, choose only one.
This is the default property, so these two are equivalent:
plugin 'Probe::Vcpkg' => (name => 'foo');
and
plugin 'Probe::Vcpkg' => 'foo';
=head2 lib
Specifies the list of libraries that make up the Vcpkg. This should not be used with the C<name> property
above, choose only one. Note that using this detection method, the version number of the package will
not be automatically determined (since multiple packages could potentially make up the list of libraries),
so you need to determine the version number another way if you need it.
This must be an array reference. Do not include the C<.lib> extension.
plugin 'Probe::Vcpkg' => (lib => ['foo','bar']);
=head2 ffi_name
Specifies an alternate ffi_name for finding dynamic libraries.
=head1 SEE ALSO
L<Alien::Build>, L<alienfile>, L<Alien::Build::MM>, L<Alien>
=head1 AUTHOR
Author: Graham Ollis E<lt>plicease@cpan.orgE<gt>
Contributors:
Diab Jerius (DJERIUS)
Roy Storey (KIWIROY)
Ilya Pavlov
David Mertens (run4flat)
Mark Nunberg (mordy, mnunberg)
Christian Walde (Mithaldu)
Brian Wightman (MidLifeXis)
Zaki Mughal (zmughal)
mohawk (mohawk2, ETJ)
Vikas N Kumar (vikasnkumar)
Flavio Poletti (polettix)
Salvador Fandiño (salva)
Gianni Ceccarelli (dakkar)
Pavel Shaydo (zwon, trinitum)
Kang-min Liu (劉康民, gugod)
Nicholas Shipp (nshp)
Juan Julián Merelo Guervós (JJ)
Joel Berger (JBERGER)
Petr Pisar (ppisar)
Lance Wicks (LANCEW)
Ahmad Fatoum (a3f, ATHREEF)
José Joaquín Atria (JJATRIA)
Duke Leto (LETO)
Shoichi Kaji (SKAJI)
Shawn Laffan (SLAFFAN)
Paul Evans (leonerd, PEVANS)
Håkon Hægland (hakonhagland, HAKONH)
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2011-2020 by Graham Ollis.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut