Skip to content

Commit

Permalink
Ensure compatibility with a single shared libvips library
Browse files Browse the repository at this point in the history
  • Loading branch information
kleisauke committed Mar 4, 2024
1 parent 866f509 commit 4d99847
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions lib/vips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4d99847

Please sign in to comment.