Alien-FFI
view release on metacpan or search on metacpan
asset => 1,
);
plugin 'Build::Autoconf' => ();
my $configure = '--disable-shared --enable-static --disable-builddir';
if($^O eq 'MSWin32')
{
my $bits = $Config{archname} =~ /^MSWin32-x64/ ? 64 : 32;
$configure .= ' --build=x86_64-pc-mingw64' if $bits == 64;
if(meta->prop->{platform}->{compiler_type} eq 'microsoft')
{
# Visual C++ is "special"
$configure .= ' LD=link CPP="cl -nologo -EP"';
if($bits == 64)
{ $configure .= ' CC="%{cwd}/msvcc.sh -m64"' }
else
{ $configure .= ' CC=%{cwd}/msvcc.sh' }
# 3.2.x broke Visual C++ for some reason.
# hopefully 3.3.x or 4.x will fix it.
# otherwise this will start failing again
meta->around_hook( prefer => sub {
my $orig = shift;
my $ret = $orig->(@_);
$ret->{list} = [
grep { $_->{version} ne '3.3' }
grep { $_->{version} ne '3.2' }
grep { $_->{version} !~ /^3\.2\./ }
@{ $ret->{list} }
];
$ret;
});
requires 'Path::Tiny' => '0.077';
patch sub {
my($build) = @_;
my $libffi_pc = Path::Tiny->new('libffi.pc.in');
if(-f $libffi_pc)
{
# I think the actual error is somewhere other
# than the .pc file, but this works around it
# at least in the way that we use it.
$build->log('edit libffi.pc.in');
$libffi_pc->copy('libffi.pc.in.orig');
$libffi_pc->edit_lines(sub {
s/^toolexeclibdir=.*$/toolexeclibdir=\${libdir\}/;
});
}
};
meta->after_hook( gather_share => sub {
my($build) = @_;
$build->runtime_prop->{$_} .= " -DFFI_BUILDING" for qw( cflags cflags_static );
$build->runtime_prop->{$_} =~ s{-L}{-LIBPATH:}g for qw( libs libs_static );
$build->runtime_prop->{$_} =~ s{-l([A-Za-z]+)}{$1.LIB}g for qw( libs libs_static );
});
}
}
if($^O eq 'darwin')
{
my @ldflags = shellwords $Config{ldflags};
my @arch;
while(@ldflags)
{
my $arg = shift @ldflags;
next unless $arg eq "-arch";
push @arch, $arg, shift @ldflags;
}
if(@arch)
{
$configure .= " LDFLAGS='@arch'";
$configure .= " CFLAGS='@arch'";
}
}
if($^O eq 'openbsd')
{
unless($Config{usethreads})
{
meta->after_hook( gather_share => sub {
my($build) = @_;
$build->runtime_prop->{$_} .= " /usr/lib/libpthread.a" for qw( libs libs_static );
});
}
}
if($Config{archname} =~ /^aarch64-linux/)
{
# libffi 3.4.3 broke Linux Arm64
# https://github.com/PerlFFI/FFI-Platypus/issues/374
# For now not black listing it for other Arm64
# systems (like macOS) because I did not see the
# errors there.
meta->around_hook( prefer => sub {
my $orig = shift;
my $ret = $orig->(@_);
$ret->{list} = [
grep { $_->{version} ne '3.4.3' }
@{ $ret->{list} }
];
$ret;
});
}
if($Config{archname} =~ /^i[3456]86/)
{
my %flags;
# TODO: This probe will not work on systems without /proc
if(-f '/proc/cpuinfo')
{
my $fh;
open($fh, '<', '/proc/cpuinfo');
my($flags) = map { my $x = $_; $x =~ s/^.*:\s+//; $x } grep /^flags/, <$fh>;
close $fh;
chomp $flags;
%flags = map { $_ => 1 } split /\s+/, $flags;
}
if($flags{avx} && $flags{aes})
{
log "You seem to have avx and aes flags, allowing libffi to detect the CPU";
log "see https://github.com/PerlFFI/Alien-FFI/issues/6"
}
else
{
# disable avx and aes instructions as the detection logic for libffi seems
# to be broken. See https://github.com/PerlFFI/Alien-FFI/issues/6
log "Could not detect avx and aes flags. The detection logic is pretty dumb, and may be wrong.";
log "Please let us know if we got it wrong, and how we can improve it.";
log "see https://github.com/PerlFFI/Alien-FFI/issues/6";
$configure .= " --with-gcc-arch=pentium4";
}
}
build [
sub {
my($build) = @_;
$build->runtime_prop->{my_configure} = "%{configure} $configure";
},
"%{configure} $configure",
'%{make}',
'%{make} install',
];
};
( run in 1.928 second using v1.01-cache-2.11-cpan-0068ddc7af1 )