Find 'helper.so' even when it's in $GEM_HOME/extensions.

See https://github.com/pmahoney/process_shared/issues/4#issuecomment-106777066
This commit is contained in:
Patrick Mahoney 2015-06-09 21:54:21 -05:00
parent 25f9bb2cae
commit 1a05bcd924
1 changed files with 16 additions and 2 deletions

View File

@ -16,8 +16,22 @@ module ProcessShared
FFI::Platform::LIBSUFFIX
end
ffi_lib File.join(File.expand_path(File.dirname(__FILE__)),
'helper.' + suffix)
# Ruby 2.1 (also 2.0?) puts extensions into, e.g.
# $GEM_HOME/extensions/x86_64-linux/2.1.0/static/$gemname-$gemversion,
# so they aren't in the same dir as this file. Normally that's
# fine since you're just 'require'ing them, but 'helper.so'
# isn't a real Ruby extension; it's just a shared lib to
# export some constants that are only available as macros in
# libc.
#
# Fallback to attempting to load from same directory as this file.
helper = 'process_shared/posix/helper.' + suffix
fallback_path = File.expand_path(File.dirname(__FILE__))
path = $LOAD_PATH.find(fallback_path) do |path|
File.exists?(File.join(path, helper))
end
ffi_lib File.join(path, helper)
[:o_rdwr,
:o_creat,