From 4d99847ece08e21aae8c35363f71427aa597c830 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Mon, 4 Mar 2024 15:48:35 +0100 Subject: [PATCH] Ensure compatibility with a single shared libvips library See: #372. --- lib/vips.rb | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/vips.rb b/lib/vips.rb index f0e7461..425797b 100644 --- a/lib/vips.rb +++ b/lib/vips.rb @@ -25,11 +25,28 @@ # "lib" prefix or a ".dll" suffix. def library_name(name, abi_number) if FFI::Platform.windows? - "lib#{name}-#{abi_number}.dll" + # On Windows, `GetProcAddress()` can only search in a specified DLL and + # doesn't look into its dependent libraries for symbols. Therefore, we + # check if the GLib DLLs are available. If these can not be found, we + # assume that GLib is statically linked into libvips. + begin + lib = FFI::DynamicLibrary.open("lib#{name}-#{abi_number}.dll", + FFI::DynamicLibrary::RTLD_LAZY | FFI::DynamicLibrary::RTLD_LOCAL) + return lib if lib + + # LoadError for JRuby, RuntimeError for TruffleRuby + rescue LoadError, RuntimeError + return "libvips-42.dll" + end + + # macOS and *nix uses `dlsym()`, which also searches for named symbols + # in the dependencies of the shared library. Therefore, we can support + # a single shared libvips library with all dependencies statically + # linked. elsif FFI::Platform.mac? - "#{name}.#{abi_number}" + "vips.42" else - "#{name}.so.#{abi_number}" + "vips.so.42" end end