New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle library api version in NativeCall #4751
Comments
From @SkarsnikSome distribution (debian) does not provide the libfoo.so symlink in the binary that provide a libfoo. In the case of debian it's provided by libfoo-dev. I was not able to find what was a standard behavior for the unversioned .so file But allowing to specify the api version could fix this so NC can find libfoo.so.apiversion Here a quick patch that make it work. sub foo is native('libfoo:42') ... |
From @Skarsnikdiff --git a/lib/NativeCall.pm b/lib/NativeCall.pm my %lib; |
From @geekosaurOn Sat, Nov 14, 2015 at 7:09 PM, Sylvain Colinet <
There isn't one, and really nobody should be linking to that because the Unfortunately, NativeCall doesn't really support this sensibly. For I've been thinking about this a bit, and plan to write up a proposal when I -- |
The RT System itself - Status changed from 'new' to 'open' |
From @SkarsnikLe Dim 15 Nov 2015 20:02:52, allbery.b@gmail.com a écrit :
Did you have a look at my proposed fix? It's a quick fix and not probably the best solution. (it even support full version like 1.2.3!) But it's something x) |
From @FROGGSHi, do you know if that patch also works on other linux distros, on BSDs and on osx? |
From @SkarsnikLe Lun 16 Nov 2015 23:31:15, FROGGS.de a écrit :
According to https://www.freebsd.org/doc/en/books/developers-handbook/policies-shlib.html and http://www.openbsd.org/faq/ports/specialtopics.html it should work too. I am not sure to understand exactly how freebsd handle minor version (it said it's ignored by ld or libtool, it's not clear) For Os X it's similar: https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/DynamicLibraryDesignGuidelines.html#//apple_ref/doc/uid/TP40002013-SW20 but it's libname.version.dylib |
From @SkarsnikLe Mar 17 Nov 2015 04:22:05, scolinet@gmail.com a écrit :
Ok I tried to create a new branch on rakudo for it (but I don't have the right) So here another patch with tests. I don't have a win32 nor an Os X environement to test it on these plateform. I added a warning if someone write 'libfoo' without an api version (but not in the case of what look like a path) |
From @Skarsnik0001-Add-a-support-for-apiversion-in-nativecall.patchFrom a7beb3f9d2f9a6bacd8aa1741ed3076bf58a636d Mon Sep 17 00:00:00 2001
From: Skarsnik <scolinet@gmail.com>
Date: Thu, 19 Nov 2015 16:14:51 +0000
Subject: [PATCH] Add a support for apiversion in nativecall
---
lib/NativeCall.pm | 42 +++++++++++++++++++++---------------------
t/04-nativecall/17-libnames.t | 16 ++++++++++++++++
2 files changed, 37 insertions(+), 21 deletions(-)
create mode 100644 t/04-nativecall/17-libnames.t
diff --git a/lib/NativeCall.pm b/lib/NativeCall.pm
index ea7bd50..b7146d1 100644
--- a/lib/NativeCall.pm
+++ b/lib/NativeCall.pm
@@ -155,7 +155,7 @@ my role NativeCallSymbol[Str $name] {
method native_symbol() { $name }
}
-sub guess_library_name($lib) {
+sub guess_library_name($lib) is export(:libraries) {
my $libname;
if ($lib ~~ Callable) {
$libname = $lib();
@@ -163,27 +163,27 @@ sub guess_library_name($lib) {
else {
$libname = $lib;
}
-
- if !$libname.DEFINITE { '' }
- elsif $libname ~~ /\.<.alpha>+$/ { $libname }
- elsif $libname ~~ /\.so(\.<.digit>+)+$/ { $libname }
- elsif $*VM.config<load_ext> :exists { $libname ~ $*VM.config<load_ext> }
- elsif $*VM.config<nativecall.so> :exists {
- if $*KERNEL.name eq 'darwin' {
- ($libname ~ '.' ~ $*VM.config<nativecall.so>).IO.absolute
- }
- else {
- $libname ~ '.' ~ $*VM.config<nativecall.so>
- }
- }
- elsif $*VM.config<dll> :exists {
- my $ext = $*VM.config<dll>;
- $ext ~~ s/^.*\%s//;
- "$libname$ext";
+ #Already a full name
+ return $libname if ($libname ~~ /\.<.alpha>+$/ or $libname ~~ /\.so(\.<.digit>+)+$/);
+
+ my $apiversion = '';
+ my $ext;
+ if $libname.index(':') {
+ ($libname, $apiversion) = $libname.split(':');
+ } else {
+ note "Consider adding the api version of the library you want to use, eg: $libname:1" if $libname ~~ /^<-[\.\/\\]>+$/;
}
- elsif $*DISTRO.is-win { "{$libname}.dll"; }
- # TODO: more extension guessing
- else { "{$libname}.so"; }
+ #Err, this is a mess, why so many way to get the extension?
+ $ext = "dynlib" if $*KERNEL.name eq 'darwin'; #Os X?
+ $ext = "dll" if $*DISTRO.is-win;
+ $ext = $*VM.config<load_ext>.substr(1) if $*VM.config<load_ext> :exists;
+ $ext = $*VM.config<nativecall.so> if $*VM.config<nativecall.so> :exists;
+ {$ext = $*VM.config<dll>; $ext ~~ s/^.*\%s\.//;} if $*VM.config<dll> :exists;
+ $apiversion = '.' ~ $apiversion if $apiversion ne '';
+ return ("$libname$apiversion.$ext").IO.absolute if $*KERNEL.name eq 'darwin';
+ return "$libname.$ext$apiversion" if !$*DISTRO.is-win;
+ return "$libname.$ext" if $*DISTRO.is-win;
+ return "$libname.so";
}
my %lib;
diff --git a/t/04-nativecall/17-libnames.t b/t/04-nativecall/17-libnames.t
new file mode 100644
index 0000000..cac72cb
--- /dev/null
+++ b/t/04-nativecall/17-libnames.t
@@ -0,0 +1,16 @@
+use Test;
+
+use NativeCall :libraries;
+
+plan 6;
+
+if $*KERNEL ~~ 'linux' {
+ ok guess_library_name("libfoo") eq "libfoo.so", "libfoo is libfoo.so and should warn";
+ ok guess_library_name("libfoo:3") eq "libfoo.so.3", "libfoo:3 is libfoo.so.3";
+ ok guess_library_name("libfoo.so") eq "libfoo.so", "libfoo.so is libfoo.so";
+ ok guess_library_name("./libfoo") eq "./libfoo.so", "./libfoo is ./libfoo.so";
+ ok guess_library_name("./libfoo.so") eq "./libfoo.so", "./libfoo.so is ./libfoo.so";
+ ok guess_library_name("/libfoo.so") eq "/libfoo.so", "/libfoo.so is /libfoo.so";
+} else {
+ skip 6;
+}
--
2.6.2
|
From @FROGGSPatches by Skarsnik++: Tests: Closing as resolved. Thanks Skarsnik++! |
@FROGGS - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#126645 (status was 'resolved')
Searchable as RT126645$
The text was updated successfully, but these errors were encountered: