8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/ffi-compiler/loader.rb', line 8
def self.find(name, start_path = nil)
library = Platform.system.map_library_name(name)
start_path ||= caller_path(caller[0])
if defined?(Gem::Specification) &&
(spec = Gem::Specification.find_active_stub_by_path(library)&.spec) &&
spec.respond_to?(:extension_dir) &&
start_path.start_with?(spec.gem_dir)
ext_path = File.join(spec.extension_dir, library)
return ext_path if File.exist?(ext_path)
end
root = false
Pathname.new(start_path).ascend do |path|
Dir.glob("#{path}/**/#{FFI::Platform::ARCH}-#{FFI::Platform::OS}/#{library}") do |f|
return f
end
Dir.glob("#{path}/**/#{library}") do |f|
return f
end
break if root
root = File.basename(path) == 'lib'
end
raise LoadError.new("cannot find '#{name}' library")
end
|