File tree 1 file changed +47
-5
lines changed
1 file changed +47
-5
lines changed Original file line number Diff line number Diff line change @@ -64,16 +64,30 @@ def load_library
64
64
end
65
65
66
66
def detect_library_extension
67
- case RbConfig ::CONFIG [ 'host_os' ]
68
- when /mswin|msys|mingw|cygwin/
69
- 'dll'
67
+ # Ruby >= 2.5 provides SOEXT in rbconfig
68
+ so_ext = RbConfig ::CONFIG [ "SOEXT" ]
69
+ return so_ext if so_ext
70
+
71
+ return 'dll' if windows?
72
+
73
+ # For Ruby < 2.5, we use RUBY_PLATFORM
74
+ case RUBY_PLATFORM
70
75
when /darwin|mac os/
71
76
'dylib'
72
77
else
73
78
'so'
74
79
end
75
80
end
76
81
82
+ def windows?
83
+ case RUBY_PLATFORM
84
+ when /mswin|msys|mingw|cygwin/
85
+ true
86
+ else
87
+ false
88
+ end
89
+ end
90
+
77
91
def select_dirs ( dirs )
78
92
dirs . select! { |d | Dir . exist? ( d ) }
79
93
end
@@ -82,8 +96,36 @@ def find_libs(lib_names, lib_dirs)
82
96
lib_ext = detect_library_extension
83
97
lib_arr = lib_names . map do |l |
84
98
x = nil
85
- lib_dirs . each do |d |
86
- break if x = Dir . glob ( "#{ d } /lib#{ l } {,64}.#{ lib_ext } {,.*}" ) . last
99
+ if windows?
100
+ # On Windows, try to search the default DLL search path at first
101
+ [
102
+ "lib#{ l } .#{ lib_ext } " ,
103
+ "lib#{ l } 64.#{ lib_ext } "
104
+ ] . each do |filename |
105
+ begin
106
+ Fiddle . dlopen ( filename ) . close
107
+ rescue Fiddle ::DLError
108
+ x = nil
109
+ else
110
+ x = filename
111
+ break
112
+ end
113
+ end
114
+ end
115
+ if x . nil?
116
+ # Search in the candidate directories
117
+ lib_dirs . find do |d |
118
+ x = Dir . glob ( "#{ d } /lib#{ l } {,64}.#{ lib_ext } {,.*}" ) . find do |lib |
119
+ begin
120
+ Fiddle . dlopen ( lib ) . close
121
+ rescue Fiddle ::DLError
122
+ false
123
+ else
124
+ true
125
+ end
126
+ end
127
+ break if x
128
+ end
87
129
end
88
130
[ l . to_sym , x ]
89
131
end
You can’t perform that action at this time.
0 commit comments