Affix
view release on metacpan or search on metacpan
builder/Affix/Builder.pm view on Meta::CPAN
use Config qw[%Config];
field $force : param //= 0;
field $debug : param //= 0;
field $libver;
field $cflags;
field $ldflags;
field $cppver = 'c++17'; # https://en.wikipedia.org/wiki/C%2B%2B20#Compiler_support
field $cver = 'c17'; # https://en.wikipedia.org/wiki/C17_(C_standard_revision)
field $make : param //= $Config{make} || 'dmake';
#
field $action : param //= 'build';
field $meta : reader = CPAN::Meta->load_file('META.json');
# Params to Build script
field $install_base : param //= '';
field $installdirs : param //= '';
field $uninst : param //= 0; # Make more sense to have a ./Build uninstall command but...
field $install_paths : param //= ExtUtils::InstallPaths->new( dist_name => $meta->name );
field $verbose : param(v) //= 0;
field $dry_run : param //= 0;
field $pureperl : param //= 0;
field $jobs : param //= 1;
field $destdir : param //= '';
field $prefix : param //= '';
#
ADJUST {
die "No META information provided\n" unless -e 'META.json';
die "OS unsupported: Affix requires a 64-bit architecture\n" if $Config{ptrsize} < 8;
# Configure Flags
my $is_bsd = $^O =~ /bsd/i;
my $is_win = $^O =~ /MSWin32/i;
my $is_sun = $^O =~ /(solaris|sunos)/i;
$cflags = ( $is_bsd || $is_sun ) ? '' : '-fPIC ';
$ldflags = ( $is_bsd || $is_sun ) ? '' : ' -flto=auto ';
$cflags .= ' -D__EXTENSIONS__ -D_LARGEFILE64_SOURCE' if $is_sun;
if ( $debug > 0 ) {
$cflags
.= '-DDEBUG=' .
$debug .
' -g3 -gdwarf-4 ' .
' -Wno-deprecated -pipe ' .
' -Wall -Wextra -Wpedantic -Wvla -Wnull-dereference ' .
' -Wswitch-enum -Wduplicated-cond ' .
' -Wduplicated-branches';
$cflags .= ' -fvar-tracking-assignments' unless $Config{osname} eq 'darwin';
}
elsif ( !$is_win ) {
$cflags .= ' -DNDEBUG -DBOOST_DISABLE_ASSERTS -O3 -ftree-vectorize -ffast-math -fno-align-functions -fno-omit-frame-pointer';
$cflags .= ' -flto' unless ( $is_bsd || $is_sun );
}
# Threading support (Critical for shm_open/librt on Linux)
if ( !$is_win ) {
$cflags .= ' -pthread';
$ldflags .= ' -pthread';
$ldflags .= ' -Wl,-z,nobtcfi' if $^O eq 'openbsd'; # XXX - Temp BTI/IBT workaround https://www.openbsd.org/innovations.html
}
}
method write_file( $filename, $content ) { path($filename)->spew_raw($content) or die "Could not open $filename: $!\n" }
method read_file ($filename) { path($filename)->slurp_utf8 or die "Could not open $filename: $!\n" }
method step_build() {
$self->step_affix;
my %modules = map { $_ => catfile( 'blib', $_ ) } find( qr/\.pm$/, 'lib' );
my %docs = map { $_ => catfile( 'blib', $_ ) } find( qr/\.pod$/, 'lib' );
my %scripts = map { $_ => catfile( 'blib', $_ ) } find( qr/(?:)/, 'script' );
my %sdocs = map { $_ => delete $scripts{$_} } grep {/.pod$/} keys %scripts;
my %dist_shared = map { $_ => catfile( qw[blib lib auto share dist], $meta->name, abs2rel( $_, 'share' ) ) } find( qr/(?:)/, 'share' );
my %module_shared = map { $_ => catfile( qw[blib lib auto share module], abs2rel( $_, 'module-share' ) ) } find( qr/(?:)/, 'module-share' );
pm_to_blib( { %modules, %docs, %scripts, %dist_shared, %module_shared }, catdir(qw[blib lib auto]) );
make_executable($_) for values %scripts;
make_path( catdir(qw[blib arch]), { chmod => 0755, verbose => $verbose } );
0;
}
method _clean_objects() {
my $lib_dir = path('lib');
my @objs;
$lib_dir->visit(
sub ( $path, $state ) {
push @objs, $path if $path->is_file && $path =~ /\.(?:o|obj)\z/i;
},
{ recurse => 1 }
);
remove_tree( $_, { verbose => $verbose } ) for @objs;
0;
}
method step_clean() {
remove_tree( $_, { verbose => $verbose } ) for qw[blib temp];
$self->_clean_objects;
0;
}
method step_install() {
$self->step_build() unless -d 'blib';
my %res;
install(
[ from_to => $install_paths->install_map,
verbose => $verbose,
always_copy => 1,
dry_run => $dry_run,
uninst => $uninst,
result => \%res
]
);
# In the future, I might check the values of %res according to https://metacpan.org/pod/ExtUtils::Install#install
0;
}
method step_realclean () {
remove_tree( $_, { verbose => $verbose } ) for qw[blib temp Build _build_params MYMETA.yml MYMETA.json];
remove_tree( 'infix/build_lib', { verbose => $verbose } );
$self->_clean_objects;
0;
}
method step_test(%args) {
$jobs = $args{j} // $args{jobs} // $jobs;
( run in 3.047 seconds using v1.01-cache-2.11-cpan-234fa220139 )