-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
128 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
/FFI-Platypus-Lang-Go-* | ||
/.build | ||
/share | ||
*.so | ||
*.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package main | ||
|
||
import "C" | ||
|
||
//export add | ||
func add(x, y int) int { | ||
return x + y | ||
} | ||
|
||
func main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
use FFI::Platypus 2.00; | ||
use FFI::CheckLib qw( find_lib_or_die ); | ||
use File::Basename qw( dirname ); | ||
|
||
my $ffi = FFI::Platypus->new( | ||
api => 2, | ||
lib => './add.so', | ||
lang => 'Go', | ||
); | ||
$ffi->attach( add => ['goint', 'goint'] => 'goint' ); | ||
|
||
print add(1,2), "\n"; # prints 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use Test2::V0 -no_srand => 1; | ||
use Capture::Tiny qw( capture_merged ); | ||
use Path::Tiny qw( path ); | ||
use File::chdir; | ||
|
||
plan skip_all => 'developer test set FFI_PLATYPUS_LANG_GO_TEST_EXAMPLES=1 to run' unless $ENV{FFI_PLATYPUS_LANG_GO_TEST_EXAMPLES} || $ENV{CIPSOMETHING}; | ||
|
||
my @lib; | ||
|
||
if(-d 'blib') | ||
{ | ||
push @lib, '-Mblib'; | ||
} | ||
else | ||
{ | ||
$ENV{PERL_FILE_SHAREDIR_DIST} = join '=', 'FFI-Platypus-Lang-Go', "$CWD/share"; | ||
push @lib, '-I../lib'; | ||
} | ||
|
||
foreach my $dir (qw( examples )) | ||
{ | ||
subtest 'Compile/Link Go' => sub { | ||
|
||
foreach my $src (path('examples')->children) | ||
{ | ||
next unless $src->basename =~ /\.go$/; | ||
my $so = $src->parent->child(do { | ||
my $basename = $src->basename; | ||
$basename =~ s/\.go$/.so/; | ||
$basename; | ||
}); | ||
|
||
my @cmd = ('go', 'build', -o => "$so", '-buildmode=c-shared', "$src"); | ||
|
||
my($out, $ret) = capture_merged { | ||
system @cmd; | ||
}; | ||
|
||
if(is $ret, 0, "@cmd") | ||
{ | ||
note $out if $out ne ''; | ||
} | ||
else | ||
{ | ||
diag $out if $out ne ''; | ||
} | ||
} | ||
}; | ||
|
||
subtest 'Run Perl' => sub { | ||
local $CWD = 'examples'; | ||
foreach my $src (path('.')->children) | ||
{ | ||
next unless $src->basename =~ /\.pl$/; | ||
|
||
my @cmd = ($^X, @lib, "$src"); | ||
my($out, $ret) = capture_merged { | ||
system @cmd; | ||
}; | ||
|
||
if(is $ret, 0, "@cmd") | ||
{ | ||
note $out if $out ne ''; | ||
} | ||
else | ||
{ | ||
diag $out if $out ne ''; | ||
} | ||
} | ||
}; | ||
} | ||
|
||
unlink for grep { $_->basename =~ /\.(h|so)$/ } path('examples')->children; | ||
|
||
done_testing; |