Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt native library version detection.
Added to mysql and Pg for testing + minor cleanups. Will be extended but now closes #60.
- Loading branch information
Showing
8 changed files
with
76 additions
and
61 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
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
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,33 @@ | ||
use v6; | ||
|
||
unit module NativeLibs:auth<sortiz>:ver<0.0.1>; | ||
use NativeCall :ALL; | ||
|
||
class Searcher { | ||
method !test($try, $wks) { | ||
(try cglobal($try, $wks, Pointer)) ~~ Pointer ?? $try !! Nil | ||
} | ||
method search(Str $libname, Str $wks, *@vers) { | ||
my $wlibname; | ||
for @vers { | ||
my $ver = $_.defined ?? Version.new($_) !! Version; | ||
$wlibname = $_ and last with self!test: | ||
guess_library_name(($libname, $ver)), $wks; | ||
} | ||
$wlibname //= self!test: guess_library_name($libname), $wks unless @vers; | ||
$wlibname; | ||
} | ||
method at-runtime($libname, $wks, *@vers) { | ||
-> { | ||
with self.search($libname, $wks, |@vers) { | ||
$_ | ||
} else { | ||
die "Cannot locate native library '$libname'"; | ||
} | ||
} | ||
} | ||
} | ||
# Reexport all NativeCall | ||
CHECK for NativeCall::EXPORT::.keys { | ||
UNIT::EXPORT::{$_} := NativeCall::EXPORT::{$_}; | ||
} |
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,13 @@ | ||
use v6; | ||
use Test; | ||
|
||
plan 5; | ||
|
||
use-ok 'NativeLibs'; | ||
ok (my \Util = ::('NativeLibs::Searcher')) !~~ Failure, 'Class Searcher exists'; | ||
my $sub = Util.at-runtime('mysqlclient', 'mysql_init', 16..20); | ||
does-ok $sub, Callable; | ||
my $lib; | ||
is $lib = $sub.(), "libmysqlclient.so.18", "Indeed $lib"; | ||
ok $lib = Util.search('pq', 'PQstatus', 5), "Postgres is $lib"; | ||
|