Alien-SDL3

 view release on metacpan or  search on metacpan

builder/Alien/SDL3/Builder.pm  view on Meta::CPAN

            my $store = tempdir()->child('SDL3.zip');
            my $okay  = $self->fetch( $archive, $store );
            die 'Failed to fetch SDL binaries' unless $okay;
            if ( $Config{cc} =~ m[gcc]i ) {
                my $platform = $Config{archname} =~ /x64/ ? 'x86_64-w64-mingw32' : 'i686-w64-mingw32';

                #~ $self->add_to_cleanup( $okay->canonpath );
                $okay->child($platform)->visit(
                    sub {
                        my ( $path, $state ) = @_;
                        $path->is_dir ? $p->child( $path->relative( $okay->child($platform) ) )->mkdir( { verbose => $verbose } ) :
                            $path->copy( $p->child( $path->relative( $okay->child($platform) ) ) );
                    },
                    { recurse => 1 }
                );
            }
            else {    # Assume VC
                my $platform = $Config{archname} =~ /x64/ ? 'x64' : 'x86';    # XXX - arm64 is untested, well so is VC right now...
                $okay->child('include')->visit(
                    sub {
                        my ( $path, $state ) = @_;
                        $path->is_dir ? $p->child( $path->relative( $okay->child('include') ) )->mkdir( { verbose => $verbose } ) :
                            $path->copy( $p->child( $path->relative( $okay->child('include') ) ) );
                    },
                    { recurse => 1 }
                );
                $okay->child( 'lib', $platform )->visit(
                    sub {
                        my ( $path, $state ) = @_;
                        $path->is_dir ? $p->child( $path->relative( $okay->child( 'lib', $platform ) ) )->mkdir( { verbose => $verbose } ) :
                            $path->copy( $p->child( $path->relative( $okay->child( 'lib', $platform ) ) ) );
                    },
                    { recurse => 1 }
                );
            }
            $config{type}    = 'share';
            $config{okay}    = 1;
            $config{version} = $version;
        }
        else {
            require DynaLoader;
            require Alien::cmake3;
            unshift @PATH, Alien::cmake3->bin_dir;
            say 'Looking for SDL3 library...' if $verbose;
            my ($path) = DynaLoader::dl_findfile('-lSDL3');
            if ($path) {
                $config{type} = 'system';
                $config{path} = path($path)->realpath->stringify;
                say 'Library found at ' . $config{path} if $verbose;
            }
            else {
                say 'Building SDL3 from source...' if $verbose;
                my $store = tempdir()->child( path($archive)->basename );
                my $build = tempdir()->child('build');
                my $okay  = $self->fetch( $archive, $store );
                die 'Failed to download SDL3 source' unless $okay;

                #~ $self->add_to_cleanup( $okay->canonpath );
                $config{path} = 'share';
                $config{okay} = 0;
                my $cflags = '';
                {
                    $self->_do_in_dir(
                        $okay,
                        sub {
                            system( Alien::cmake3->exe, grep {length} '-S ' . $okay,
                                '-B ' . $build->canonpath,      '--install-prefix=' . $p->canonpath,
                                '-Wdeprecated -Wdev -Werror',   '-DSDL_SHARED=ON',
                                '-DSDL_TESTS=OFF',              '-DSDL_INSTALL_TESTS=OFF',
                                '-DSDL_DISABLE_INSTALL_MAN=ON', '-DSDL_VENDOR_INFO=SDL3.pm',
                                '-DCMAKE_BUILD_TYPE=Release',   '-DSDL3_DIR=' . $cwd->child('share')->absolute,
                                $cflags
                            );
                            system( Alien::cmake3->exe, '--build', $build->canonpath

                                #, '--config Release', '--parallel'
                            );
                            die sprintf "Failed to build SDL3! %s\n", $archive // '' if system( Alien::cmake3->exe, '--install', $build->canonpath );
                            $config{okay}    = 1;
                            $config{version} = $version;
                        }
                    );
                }
            }
        }
        {
            my @out;
            push @out, sprintf '%s = %s', $_, $config{$_} for sort keys %config;
            $p->child('.config')->spew( join "\n", @out );
        }
    }

    method get_arguments (@sources) {
        $_ = detildefy($_) for grep {defined} $install_base, $destdir, $prefix, values %{$install_paths};
        $install_paths = ExtUtils::InstallPaths->new( dist_name => $meta->name );
        return;
    }

    method fetch ( $liburl, $outfile ) {
        $http //= HTTP::Tiny->new();
        printf 'Downloading %s... ', $liburl if $verbose;
        $outfile->parent->mkpath;
        my $response = $http->mirror( $liburl, $outfile, {} );
        say $response->{reason} if $verbose;
        if ( $response->{success} ) {    #ddx $response;

            #~ $self->add_to_cleanup($outfile);
            my $outdir = $outfile->parent->child( $outfile->basename( '.tar.gz', '.zip' ) );
            printf 'Extracting %s to %s... ', $outfile, $outdir if $verbose;
            require Archive::Extract;
            my $ae = Archive::Extract->new( archive => $outfile );
            if ( $ae->extract( to => $outdir ) ) {
                say 'done' if $verbose;

                #~ $self->add_to_cleanup( $ae->extract_path );
                return path( $ae->extract_path );
            }
            else {
                croak 'Failed to extract ' . $outfile;
            }
        }
        else {
            croak 'Failed to download ' . $liburl;
        }
        return 0;
    }

    method Build(@args) {
        my $method = $self->can( 'step_' . $action );
        $method // die "No such action '$action'\n";
        exit $method->($self);
    }



( run in 0.740 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )