Skip to content

Commit a6d03ca

Browse files
committed
First try the default DLL directories on Windows
Ruby Installer 2 adds the bin directory of MSYS2 (DEVKIT) in the default DLL directories. Trying to seach DLLs in the default search directories makes us easy to use OpenBLAS and LAPACK installed by pacman command.
1 parent 474eb9f commit a6d03ca

1 file changed

Lines changed: 36 additions & 8 deletions

File tree

lib/numo/linalg/autoloader.rb

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,26 @@ def detect_library_extension
6868
so_ext = RbConfig::CONFIG["SOEXT"]
6969
return so_ext if so_ext
7070

71+
return 'dll' if windows?
72+
7173
# For Ruby < 2.5, we use RUBY_PLATFORM
7274
case RUBY_PLATFORM
73-
when /mswin|msys|mingw|cygwin/
74-
'dll'
7575
when /darwin|mac os/
7676
'dylib'
7777
else
7878
'so'
7979
end
8080
end
8181

82+
def windows?
83+
case RUBY_PLATFORM
84+
when /mswin|msys|mingw|cygwin/
85+
true
86+
else
87+
false
88+
end
89+
end
90+
8291
def select_dirs(dirs)
8392
dirs.select!{|d| Dir.exist?(d)}
8493
end
@@ -87,17 +96,36 @@ def find_libs(lib_names, lib_dirs)
8796
lib_ext = detect_library_extension
8897
lib_arr = lib_names.map do |l|
8998
x = nil
90-
lib_dirs.find do |d|
91-
x = Dir.glob("#{d}/lib#{l}{,64}.#{lib_ext}{,.*}").find do |lib|
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|
92105
begin
93-
Fiddle.dlopen(lib).close
106+
Fiddle.dlopen(filename).close
94107
rescue Fiddle::DLError
95-
false
108+
x = nil
96109
else
97-
true
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
98126
end
127+
break if x
99128
end
100-
break if x
101129
end
102130
[l.to_sym, x]
103131
end

0 commit comments

Comments
 (0)