/lib/Foo.pm6
# ...
use NativeCall;
use LibraryMake;
# Find our compiled library.
# It was installed along with this .pm6 file, so it should be somewhere in
# @*INC
sub library {
my $so = get-vars('')<SO>;
for @*INC {
if ($_~'/libfoo'~$so).IO ~~ :f {
return $_~'/libfoo'~$so;
}
}
die "Unable to find library";
}
# we put 'is native(&library)' because it will call the function and resolve the
# library at compile time, while we need it to happen at runtime (because
# this library is installed *after* being compiled).
sub foo() is native(&library) { * };
# ...
use NativeCall;
use LibraryMake;
# Find our compiled library.
# It was installed along with this .pm6 file, so it should be somewhere in
# @*INC
sub library {
my $so = get-vars('')<SO>;
my $libname = "libfoo$so";
my $base = "lib/MyModule/$libname";
for @*INC {
if my @files = ($_.files($base) || $_.files("blib/$base")) {
my $files = @files[0]<files>;
my $tmp = $files{$base} || $files{"blib/$base"};
# copy to a temp dir
#
# This is required because CompUnitRepo::Local::Installation stores the file
# with a different filename (a number with no extension) that NativeCall doesn't
# know how to load. We do this copy to fix the filename.
$tmp.IO.copy($*SPEC.tmpdir ~ '/' ~ $lib);
return $*SPEC.tmpdir ~ '/' ~ $lib;
}
}
die "Unable to find library";
}
# we put 'is native(&library)' because it will call the function and resolve the
# library at compile time, while we need it to happen at runtime (because
# this library is installed *after* being compiled).
sub foo() is native(&library) { * };
Functions
sub get-vars
sub get-vars(
Str $destfolder
) returns Hash