Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 2a4992d851f216a4b34b386179475e6417cb24a4
Author: Ari Jolma <[email protected]>
Date:   Mon Jul 10 18:19:23 2023 +0300

    Add linux bin build action

commit 323301e
Author: Ari Jolma <[email protected]>
Date:   Thu Jun 22 16:25:58 2023 +0300

    Try to fix bin build

commit 498150a
Author: Ari Jolma <[email protected]>
Date:   Thu Jun 22 16:12:38 2023 +0300

    Add binary based build

commit 974f746
Author: Ari Jolma <[email protected]>
Date:   Thu Jun 22 15:14:33 2023 +0300

    Do not cache CPAN modules

commit 060dd63
Author: Ari Jolma <[email protected]>
Date:   Thu Jun 22 07:58:58 2023 +0300

    linux share build: turn cache back on and be more verbose

commit aa9b54a
Author: Ari Jolma <[email protected]>
Date:   Wed Jun 21 14:03:43 2023 +0300

    Create Geo::GDAL::gdal.pm but leave it empty if using Alien::gdal.

commit a61d3ee
Author: Ari Jolma <[email protected]>
Date:   Wed Jun 21 13:34:32 2023 +0300

    Report dynamic libs in case of error.

commit f14daae
Author: Ari Jolma <[email protected]>
Date:   Wed Jun 21 13:19:51 2023 +0300

    Fixes to make Alien::gdal usable after previous changes

commit 616481e
Author: Ari Jolma <[email protected]>
Date:   Wed Jun 21 12:06:54 2023 +0300

    Add forgotten 'use'

commit b18243c
Author: Ari Jolma <[email protected]>
Date:   Wed Jun 21 11:58:42 2023 +0300

    Add option GDAL=<path> to Makefile.PL. Optionally use any GDAL in the system.

commit dcb7fcc
Author: Ari Jolma <[email protected]>
Date:   Sun Jun 18 16:06:26 2023 +0300

    again, no cache

commit 6807471
Author: Ari Jolma <[email protected]>
Date:   Sun Jun 18 15:55:48 2023 +0300

    again

commit 879aa45
Author: Ari Jolma <[email protected]>
Date:   Sun Jun 18 15:54:01 2023 +0300

    more info

commit 75961e1
Author: Ari Jolma <[email protected]>
Date:   Sun Jun 18 15:47:29 2023 +0300

    Test build with more info
  • Loading branch information
Ari Jolma committed Jul 10, 2023
1 parent 1ff3c70 commit e326fad
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 39 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/linux_bin_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: linux_bin_build

on:
push:
branches:
- '*'
tags-ignore:
- '*'
pull_request:

env:
PERL_MOD_DIR: /home/runner/perl5/lib/perl5

jobs:
perl:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: shogo82148/actions-setup-perl@v1
with:
perl-version: '5.32'

- name: Locale check
run: |
locale -a
echo Current locale:
locale
- name: perl -V
run: perl -V

- name: Install Dependencies
run: |
sudo apt-get install -y zlib1g-dev
sudo apt-get install -y libnet-ssleay-perl
sudo apt-get install -y software-properties-common
sudo add-apt-repository ppa:ubuntugis/ppa
sudo apt-get install -y gdal-bin
cpanm --notest local::lib
cpanm --notest PkgConfig
cpanm --notest Alien::Base::Wrapper
cpanm --notest FFI::Platypus
cpanm --notest FFI::Platypus::Declare
cpanm --notest Sort::Versions
cpanm --notest Test::Exception
cpanm --notest JSON
cpanm --notest PDL
- name: Build
run: |
perl Makefile.PL
make test
20 changes: 8 additions & 12 deletions .github/workflows/linux_share_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ jobs:
echo '20220320a' >> perlversion.txt
ls -l perlversion.txt
- name: Cache CPAN modules
uses: actions/cache@v3
with:
path: ~/perl5
key: ${{ runner.os }}-build-${{ hashFiles('perlversion.txt') }}
restore-keys: |
${{ runner.os }}-build-${{ hashFiles('perlversion.txt') }}
- name: Install Dynamic Dependencies
run: |
which -a cpanm
Expand All @@ -68,10 +60,11 @@ jobs:
cpanm --installdeps --notest Alien::proj
cpanm -v Alien::proj
cpanm --installdeps --notest Alien::gdal
cpanm -v Alien::gdal
#cpanm -v Alien::gdal
cpanm -v https://github.com/shawnlaffan/perl-alien-gdal.git@issue_23_runtime_props
# some feedback to check the system
#echo GDAL LDD
#ldd `perl -MAlien::gdal -E'print q{}, Alien::gdal->dist_dir, q{/lib/libgdal.so}'`
echo GDAL LDD
ldd `perl -MAlien::gdal -E'print q{}, Alien::gdal->dist_dir, q{/lib/libgdal.so}'`
- name: Install Geo::GDAL::FFI deps
Expand All @@ -86,8 +79,11 @@ jobs:
eval "$(perl -Mlocal::lib=${HOME}/perl5)"
# ideally we would not need this
export LD_LIBRARY_PATH=`perl -MAlien::geos::af -e'print Alien::geos::af->dist_dir . "/lib"'`
echo $LD_LIBRARY_PATH
#echo GDAL LDD again
#ldd `perl -MAlien::gdal -E'print q{}, Alien::gdal->dist_dir, q{/lib/libgdal.so}'`
export GDAL_LIB=`perl -MAlien::gdal -E'print q{}, Alien::gdal->dist_dir'`
ls -lR $GDAL_LIB
ldd `perl -MAlien::gdal -E'print q{}, Alien::gdal->dist_dir, q{/lib/libgdal.so}'`
perl Makefile.PL
cpanm --installdeps --notest .
make test
8 changes: 0 additions & 8 deletions .github/workflows/macos_share_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ jobs:
echo '20221130' >> perlversion.txt
ls -l perlversion.txt
- name: Cache CPAN modules
uses: actions/cache@v3
with:
path: ~/perl5
key: ${{ runner.os }}-build-${{ hashFiles('perlversion.txt') }}
restore-keys: |
${{ runner.os }}-build-${{ hashFiles('perlversion.txt') }}
- name: Install Dynamic Dependencies
run: |
cpanm --notest PDL
Expand Down
79 changes: 67 additions & 12 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -1,25 +1,75 @@
use Alien::gdal;
BEGIN {
my $gdal = 'Alien::gdal';
my @argv = ();
for (@ARGV) {
if (/GDAL=(.+)/) {
$gdal = $1;
} else {
push @argv, $_;
}
}
@ARGV = @argv;
eval "use Alien::gdal" if $gdal eq 'Alien::gdal';
if ($gdal ne 'Alien::gdal' or $@) {
if ($gdal eq 'Alien::gdal') {
print "I can't find Alien::gdal.\n";
$gdal = '/usr';
}
print "Trying GDAL from '$gdal'.\n";
$have_alien = 0;
my $version = `$gdal/bin/gdalinfo --version`;
unless ($version) {
print "I can't find gdal in '$gdal', I'm sorry.\n";
exit(1);
}
$version = $1 if $version =~ /(\d+\.\d+\.\d+)/;
my @a = (grep {-l} glob("$gdal/lib/libgdal*"));
my $lib = $a[0];
my $data = "$gdal/share/gdal";
print "I'm creating Geo::GDAL::gdal as a wrapper to $lib, which I believe is GDAL $version.\n";
$fh = new IO::File;
$fh->open("lib/Geo/GDAL/gdal.pm","w");
print $fh <<EOF;
package Geo::GDAL::gdal;
sub new {
return shift;
}
sub version {
return '$version';
}
sub data_dir {
return ('$data');
}
sub dynamic_libs {
return '$lib';
}
1;
EOF
} else {
eval "use Alien::Base::Wrapper qw(Alien::gdal !export)";
$have_alien = 1;
$fh = new IO::File;
$fh->open("lib/Geo/GDAL/gdal.pm","w");
}
}
use ExtUtils::MakeMaker;
use Alien::Base::Wrapper qw( Alien::gdal !export );
use Config;

WriteMakefile(
%args = (
AUTHOR => ['Ari Jolma <ari.jolma at gmail.com>'],
NAME => 'Geo::GDAL::FFI',
ABSTRACT_FROM => "lib/Geo/GDAL/FFI.pm",
VERSION_FROM => "lib/Geo/GDAL/FFI.pm",
LICENSE => "artistic_2",
Alien::Base::Wrapper->mm_args,
CONFIGURE_REQUIRES => {
'Alien::gdal' => 0
Alien::gdal => 0,
},
PREREQ_PM => {
'PkgConfig' => 0.23026,
'FFI::Platypus' => 0,
'FFI::Platypus::Declare' => 0,
'Alien::gdal' => 0,
'PDL' => 0,
'Sort::Versions' => 0,
PkgConfig => 0.23026,
FFI::Platypus => 0,
FFI::Platypus::Declare => 0,
PDL => 0,
Sort::Versions => 0,
Alien::gdal => 0,
},
TEST_REQUIRES => {
'Test::More' => 0,
Expand All @@ -41,3 +91,8 @@ WriteMakefile(
},
},
);
if ($have_alien) {
%agrs = (%args, Alien::Base::Wrapper->mm_args);
}

WriteMakefile(%args);
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
![Linux bin workflow](https://github.com/ajolma/Geo-GDAL-FFI/actions/workflows/linux_bin_build.yml/badge.svg)<br/>
![Linux share workflow](https://github.com/ajolma/Geo-GDAL-FFI/actions/workflows/linux_share_build.yml/badge.svg)<br/>
![Linus sys workflow](https://github.com/ajolma/Geo-GDAL-FFI/actions/workflows/linux_sys_build.yml/badge.svg)<br/>
![MacOS share workflow](https://github.com/ajolma/Geo-GDAL-FFI/actions/workflows/macos_share_builds.yml/badge.svg)<br/>
Expand All @@ -20,6 +21,17 @@ make install

DEPENDENCIES

FFI::Platypus
PDL
Alien::gdal

Alien::gdal downloads and compiles GDAL. This package will try to use
an existing GDAL in the system if Alien::gdal is not found or GDAL
location prefix is specified as an argument to Makefile.PL, for
example

perl Makefile.PL GDAL=/usr/local

DOCUMENTATION

COPYRIGHT AND LICENCE
Expand Down
24 changes: 19 additions & 5 deletions lib/Geo/GDAL/FFI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,14 @@ sub isint {

sub new {
my $class = shift;
my $gdal = shift;

return $instance if $instance;

my $ffi = FFI::Platypus->new;
$ffi->load_custom_type('::StringPointer' => 'string_pointer');
$ffi->lib(Alien::gdal->dynamic_libs);
my @libs = $gdal->dynamic_libs;
$ffi->lib(@libs);

$ffi->type('(pointer,size_t,size_t,opaque)->size_t' => 'VSIWriteFunction');
$ffi->type('(int,int,string)->void' => 'CPLErrorHandler');
Expand All @@ -450,7 +452,7 @@ sub new {

# from port/*.h
$ffi->attach(VSIMalloc => [qw/uint/] => 'opaque');
croak "Can't attach to GDAL methods. Does Alien::gdal provide GDAL dynamic libs?" unless $class->can('VSIMalloc');
croak "Can't attach to GDAL methods. Problem with GDAL dynamic libs: '@libs'?" unless $class->can('VSIMalloc');
$ffi->attach(VSIFree => ['opaque'] => 'void');
$ffi->attach(CPLError => [qw/int int string/] => 'void');
$ffi->attach(VSIFOpenL => [qw/string string/] => 'opaque');
Expand Down Expand Up @@ -1562,7 +1564,7 @@ $ffi->attach('GDALVectorInfoOptionsFree' => [qw/opaque/] => 'void');
$ffi->attach('GDALVectorInfo' => [qw/opaque opaque/] => 'string');
# end of generated code

if (versioncmp(Alien::gdal->version, '2.3.1') <= 0) {
if ($gdal eq 'Alien::gdal' and versioncmp($gdal->version, '2.3.1') <= 0) {
# we do not use Alien::gdal->data_dir since it issues warnings due to GDAL bug
my $pc = PkgConfig->find('gdal');
if ($pc->errmsg) {
Expand All @@ -1589,10 +1591,13 @@ $ffi->attach('GDALVectorInfo' => [qw/opaque opaque/] => 'string');
}
}
}
} else {
CPLSetConfigOption(GDAL_DATA => $gdal->data_dir);
}

$instance = {};
$instance->{ffi} = $ffi;
$instance->{gdal} = $gdal;
SetErrorHandling();
GDALAllRegister();
return bless $instance, $class;
Expand Down Expand Up @@ -1801,8 +1806,17 @@ sub FinderClean {
BEGIN {
require PkgConfig;
PkgConfig->import;
require Alien::gdal;
$instance = Geo::GDAL::FFI->new();
my $gdal;
eval {
require Geo::GDAL::gdal;
$gdal = Geo::GDAL::gdal->new();
};
if ($@) {
require Alien::gdal;
no strict 'subs';
$gdal = Alien::gdal;
}
$instance = Geo::GDAL::FFI->new($gdal);
}

1;
Expand Down
5 changes: 3 additions & 2 deletions t/00.t
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ if(1){
ok(defined $path, "GDAL support files found.");

my $version = Geo::GDAL::FFI::GetVersionInfo('SEMANTIC');
say STDERR "FYI: Your GDAL is of version $version";
say STDERR "FYI: Your GDAL is version $version";

say STDERR "FYI: GDAL_DATA = $gdal_data_dir";
if (!$path) {
Expand Down Expand Up @@ -189,14 +189,15 @@ if(1){

# test dataset
if(1){
my $ffi = Geo::GDAL::FFI->new;
my $dr = GetDriver('GTiff');
my $ds = $dr->Create('/vsimem/test.tiff', 10);
my $ogc_wkt =
'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS84",6378137,298.257223563,'.
'AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,'.
'AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,'.
'AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]';
if (Alien::gdal->version ge '3') {
if ($ffi->{gdal}->version ge '3') {
$ogc_wkt =
'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS84",6378137,298.257223563,'.
'AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,'.
Expand Down

0 comments on commit e326fad

Please sign in to comment.