diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..96c5ac0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,107 @@ +name: perl +on: + push: + branches: + - '*' + tags-ignore: + - '*' + pull_request: + create: +jobs: + notify: + runs-on: ubuntu-latest + continue-on-error: true + if: ${{ always() }} + steps: + - uses: PDLPorters/devops/github-actions/irc-notifications@master + with: + target-notifications: false # TODO + dist: + name: Make distribution using Dist::Zilla + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: 'build-dzil-dist' + uses: PDLPorters/devops/github-actions/build-dzil-dist@master + ci: + runs-on: ${{ matrix.os }} + if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' }} + needs: [ notify, dist ] + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + perl-version: ['5.10', '5.14', '5.20', '5.30'] + alien-install-type: [ 'system' ] + include: + - perl-version: '5.30' + os: ubuntu-latest + release-test: true + coverage: true + alien-install-type: 'share' + # Automatically set ALIEN_INSTALL_TYPE=share + # because no system install on Windows. + - perl-version: '5.30' + os: windows-latest + - perl-version: '5.30' + os: macos-latest + alien-install-type: 'system' + - perl-version: '5.30' + os: macos-latest + alien-install-type: 'share' + steps: + - uses: actions/checkout@v2 + - name: Get dist artifact + uses: actions/download-artifact@v2 + with: + name: dist + path: build-dir + - name: 'ci-dist: target-setup-perl' + uses: PDLPorters/devops/github-actions/ci-dist@master + with: + path: build-dir + target-setup-perl: true + perl-version: ${{ matrix.perl-version }} + - name: Install PLplot (system) + if: ${{ matrix.alien-install-type == 'system' }} + uses: PDLPorters/devops/github-actions/install-dep-plplot@master + - name: 'ci-dist: target-install-dist-perl-deps' + uses: PDLPorters/devops/github-actions/ci-dist@master + with: + path: build-dir + target-setup-perl: false + target-install-dist-perl-deps: true + - name: Install Perl optional deps + shell: bash + run: | + # test dep + if ${{ toJSON( runner.os != 'Windows' ) }}; then + cpanm -n FFI::Platypus + fi + - name: Set ALIEN_INSTALL_TYPE + shell: bash + run: | + echo "ALIEN_INSTALL_TYPE=${{ matrix.alien-install-type }}" >> $GITHUB_ENV + - name: 'ci-dist: target-all after install-dist-perl-deps' + uses: PDLPorters/devops/github-actions/ci-dist@master + with: + path: build-dir + target-setup-perl: false + target-install-dist-perl-deps: false + target-test-release-testing: true + target-test: true + test-enable-release-testing: ${{ matrix.release-test }} + test-enable-coverage: ${{ matrix.coverage }} + github-token: ${{ secrets.GITHUB_TOKEN }} + + build-status: + runs-on: ubuntu-latest + continue-on-error: true + if: ${{ always() }} + needs: [ 'ci' ] + steps: + - uses: PDLPorters/devops/github-actions/irc-notifications@master + with: + target-build-status: false # TODO + needs: ${{ toJSON(needs) }} diff --git a/.github/workflows/issue-notify.yml b/.github/workflows/issue-notify.yml new file mode 100644 index 0000000..65023d7 --- /dev/null +++ b/.github/workflows/issue-notify.yml @@ -0,0 +1,17 @@ +name: issue-notify + +on: + issues: + types: [opened] + issue_comment: + types: [created] + +jobs: + notify: + runs-on: ubuntu-latest + continue-on-error: true + if: ${{ always() }} + steps: + - uses: PDLPorters/devops/github-actions/irc-notifications@master + with: + target-notifications: true diff --git a/alienfile b/alienfile index 59e6124..e62768f 100644 --- a/alienfile +++ b/alienfile @@ -3,6 +3,7 @@ use alienfile; plugin PkgConfig => 'plplot'; share { + requires 'File::Which'; # NOTE currently only pulling PLplot 5.15.0 start_url 'https://sourceforge.net/projects/plplot/files/plplot/5.15.0%20Source/'; plugin 'Decode::SourceForge'; @@ -36,6 +37,13 @@ share { -DPLPLOT_USE_QT5=OFF -DPL_DOUBLE=ON ), + ( $^O eq 'MSWin32' + ? ( '-DPKG_CONFIG_EXECUTABLE=' . File::Which::which('pkg-config'), ) + : () + ), + qw( + -DBUILD_SHARED_LIBS=OFF + ), @{ meta->prop->{plugin_build_cmake}->{args} }, '%{.install.extract}' ], diff --git a/lib/Alien/PLplot.pm b/lib/Alien/PLplot.pm index 35ab2e4..5c7dbe5 100644 --- a/lib/Alien/PLplot.pm +++ b/lib/Alien/PLplot.pm @@ -3,8 +3,33 @@ package Alien::PLplot; use strict; use warnings; use base qw( Alien::Base ); +use File::Spec; use 5.008004; +sub inline_auto_include { + return [ 'plplot.h' ]; +} + +sub _fix_libs_flags { + my ($class, $libs_flags) = @_; + if( $class->install_type('share') ) { + my $lib_dir = File::Spec->catfile( $class->dist_dir, 'lib' ); + $libs_flags =~ s/(^|\s)-Llib\b/$1-L$lib_dir/g; + } + return $libs_flags; +} + +sub libs { + my $class = shift; + my $libs = $class->SUPER::libs(@_); + return $class->_fix_libs_flags($libs); +} +sub libs_static { + my $class = shift; + my $libs = $class->SUPER::libs_static(@_); + return $class->_fix_libs_flags($libs); +} + 1; __END__ # ABSTRACT: Alien package for the PLplot plotting library diff --git a/t/basic.t b/t/basic.t index 129e4de..18b19c5 100644 --- a/t/basic.t +++ b/t/basic.t @@ -3,25 +3,39 @@ use Test::Alien; use Test::Alien::Diag; use Alien::PLplot; + alien_diag 'Alien::PLplot'; alien_ok 'Alien::PLplot'; -ffi_ok { symbols => ['c_plgver'] }, with_subtest { - my ($ffi) = @_; - eval q{ - use FFI::Platypus::Memory qw( malloc free ); - use FFI::Platypus::Buffer qw( scalar_to_buffer ); - 1; } or skip "$@"; - my $get_version = $ffi->function( c_plgver => ['opaque'] => 'void' ); - - my $buffer = malloc(80); - $get_version->call($buffer); - my $version = $ffi->cast( 'opaque' => 'string', $buffer ); - - note "version: $version"; - like $version, qr/^(\d+)\.(\d+)\.(\d+)$/; +my $version_re = qr/^(\d+)\.(\d+)\.(\d+)$/; - free($buffer); +my $xs = do { local $/; }; +xs_ok $xs, with_subtest { + my($module) = @_; + like $module->version, $version_re; }; done_testing; +__DATA__ +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +#include +#include + +SV* +version(const char *class) +{ + char ver[80]; + c_plgver(ver); + + SV* ver_sv = newSVpv( ver, strlen(ver) ); + + return ver_sv; +} + +MODULE = TA_MODULE PACKAGE = TA_MODULE + +SV* version(class); + const char *class; diff --git a/t/ffi.t b/t/ffi.t new file mode 100644 index 0000000..0fadb74 --- /dev/null +++ b/t/ffi.t @@ -0,0 +1,48 @@ +use Test2::V0; +use Test::Alien; +use Alien::PLplot; + +use Env qw(@LD_LIBRARY_PATH @DYLD_FALLBACK_LIBRARY_PATH @PATH); +use DynaLoader; +use File::Basename qw(dirname); + +if( Alien::PLplot->install_type('share') ) { + if( Alien::PLplot->dynamic_libs ) { + my $rpath = dirname( ( Alien::PLplot->dynamic_libs )[0] ); + unshift @LD_LIBRARY_PATH, $rpath; + unshift @DYLD_FALLBACK_LIBRARY_PATH, $rpath; + unshift @PATH, $rpath; + unshift @DynaLoader::dl_library_path, $rpath; + # load shared object dependencies + for my $lib ( qw(-lcsirocsa -lqsastime -lplplot) ) { + my @files = DynaLoader::dl_findfile($lib); + DynaLoader::dl_load_file($files[0]) if @files; + } + } else { + plan skip_all => 'shared install does not support dynamic linkage'; + } + +} + +my $version_re = qr/^(\d+)\.(\d+)\.(\d+)$/; + +ffi_ok { symbols => ['c_plgver'] }, with_subtest { + my ($ffi) = @_; + eval q{ + use FFI::Platypus::Memory qw( malloc free ); + use FFI::Platypus::Buffer qw( scalar_to_buffer ); + 1; } or skip "$@"; + my $get_version = $ffi->function( c_plgver => ['opaque'] => 'void' ); + + my $buffer = malloc(80); + $get_version->call($buffer); + my $version = $ffi->cast( 'opaque' => 'string', $buffer ); + + note "version: $version"; + like $version, $version_re; + + free($buffer); +}; + + +done_testing;