Skip to content

Commit

Permalink
improve libname generation
Browse files Browse the repository at this point in the history
library names for ffi vary by platform -- this patch adds a helper
function which tries to generate the right format for max / linux / win.

See #176
  • Loading branch information
jcupitt committed Sep 21, 2019
1 parent 602bcf1 commit 0530df5
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions lib/vips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,29 @@
# This module uses FFI to make a simple layer over the glib and gobject
# libraries.

# Generate a library name for ffi.
#
# Platform notes:
# linux:
# Some distros allow "libvips.so", but only if the -dev headers have been
# installed. To work everywhere, you must include the ABI number.
# Confusingly, the file extension is not at the end. ffi adds the "lib"
# prefix.
# mac:
# As linux, but the extension is at the end and is added by ffi.
# windows:
# The ABI number must be included, but with a hyphen. ffi does not add a
# "lib" prefix or a ".dll" suffix.
def library_name(name, abi_number)
if FFI::Platform.windows?
return "lib#{name}-#{abi_number}.dll"
elsif FFI::Platform.mac?
return "#{name}.#{abi_number}"
else
return "#{name}.so.#{abi_number}"
end
end

module GLib
class << self
attr_accessor :logger
Expand All @@ -19,13 +42,7 @@ class << self

extend FFI::Library

if FFI::Platform.windows?
glib_libname = 'libglib-2.0-0.dll'
else
glib_libname = 'glib-2.0'
end

ffi_lib glib_libname
ffi_lib library_name('glib-2.0', 0)

attach_function :g_malloc, [:size_t], :pointer

Expand Down Expand Up @@ -117,13 +134,7 @@ def self.set_log_domain domain
module GObject
extend FFI::Library

if FFI::Platform.windows?
gobject_libname = 'libgobject-2.0-0.dll'
else
gobject_libname = 'gobject-2.0'
end

ffi_lib gobject_libname
ffi_lib library_name('gobject-2.0', 0)

# we can't just use ulong, windows has different int sizing rules
if FFI::Platform::ADDRESS_SIZE == 64
Expand Down Expand Up @@ -459,13 +470,7 @@ module GObject
module Vips
extend FFI::Library

if FFI::Platform.windows?
vips_libname = 'libvips-42.dll'
else
vips_libname = 'vips'
end

ffi_lib vips_libname
ffi_lib library_name('vips', 42)

LOG_DOMAIN = "VIPS"
GLib::set_log_domain LOG_DOMAIN
Expand Down

0 comments on commit 0530df5

Please sign in to comment.