Skip to content

Commit 3f308cf

Browse files
committed
Accept both Rust DLL naming variants on Windows
1 parent 33b481b commit 3f308cf

2 files changed

Lines changed: 66 additions & 30 deletions

File tree

Rakefile

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ task test: :compile
5050
task default: :test
5151

5252
def stage_rust_extension_for_ruby
53-
source = File.join(RUST_EXT_DIR, "target", "release", rust_cdylib_filename)
54-
unless File.exist?(source)
55-
abort "Expected Rust extension artifact at #{source}, but it was not produced."
53+
source = rust_cdylib_source
54+
unless source
55+
abort(
56+
"Expected Rust extension artifact at one of: " \
57+
"#{rust_cdylib_candidates.join(', ')}, but none were produced."
58+
)
5659
end
5760

5861
destination = File.join(
@@ -65,19 +68,35 @@ def stage_rust_extension_for_ruby
6568
destination
6669
end
6770

68-
def rust_cdylib_filename
71+
def rust_cdylib_source
72+
rust_cdylib_candidates.find { |path| File.exist?(path) }
73+
end
74+
75+
def rust_cdylib_candidates
76+
rust_cdylib_filenames.map { |filename| File.join(RUST_EXT_DIR, "target", "release", filename) }
77+
end
78+
79+
def rust_cdylib_filenames
6980
host_os = RbConfig::CONFIG.fetch("host_os")
70-
extension =
71-
case host_os
72-
when /darwin/
73-
"dylib"
74-
when /mswin|mingw|cygwin/
75-
"dll"
76-
else
77-
"so"
78-
end
81+
case host_os
82+
when /mswin|mingw|cygwin/
83+
# On Windows cargo may emit either prefixed or unprefixed DLL names.
84+
["lda_ruby_rust.dll", "liblda_ruby_rust.dll"]
85+
else
86+
extension =
87+
case host_os
88+
when /darwin/
89+
"dylib"
90+
else
91+
"so"
92+
end
93+
94+
["liblda_ruby_rust.#{extension}"]
95+
end
96+
end
7997

80-
"liblda_ruby_rust.#{extension}"
98+
def rust_cdylib_filename
99+
rust_cdylib_filenames.first
81100
end
82101

83102
def rust_build_env
@@ -87,10 +106,15 @@ def rust_build_env
87106
dynamic_lookup_flag = "-C link-arg=-Wl,-undefined,dynamic_lookup"
88107
existing = ENV.fetch("RUSTFLAGS", "")
89108
merged =
90-
if existing.include?(dynamic_lookup_flag)
91-
existing
109+
case host_os
110+
when /darwin/
111+
if existing.include?(dynamic_lookup_flag)
112+
existing
113+
else
114+
[existing, dynamic_lookup_flag].reject(&:empty?).join(" ")
115+
end
92116
else
93-
[existing, dynamic_lookup_flag].reject(&:empty?).join(" ")
117+
existing
94118
end
95119

96120
{ "RUSTFLAGS" => merged }

ext/lda-ruby-rust/extconf.rb

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,39 @@ def build_and_stage!
6161
success or raise "cargo build --release failed"
6262
end
6363

64-
source = File.join(__dir__, "target", "release", rust_cdylib_filename)
65-
raise "Rust extension artifact not found at #{source}" unless File.exist?(source)
64+
source = rust_cdylib_source
65+
raise "Rust extension artifact not found at #{rust_cdylib_candidates.join(', ')}" unless source
6666

6767
destination = File.expand_path("../../lib/lda_ruby_rust.#{RbConfig::CONFIG.fetch('DLEXT')}", __dir__)
6868
FileUtils.cp(source, destination)
6969
puts("Staged Rust extension to #{destination}")
7070
end
7171

72-
def rust_cdylib_filename
72+
def rust_cdylib_source
73+
rust_cdylib_candidates.find { |path| File.exist?(path) }
74+
end
75+
76+
def rust_cdylib_candidates
77+
rust_cdylib_filenames.map { |filename| File.join(__dir__, "target", "release", filename) }
78+
end
79+
80+
def rust_cdylib_filenames
7381
host_os = RbConfig::CONFIG.fetch("host_os")
74-
extension =
75-
case host_os
76-
when /darwin/
77-
"dylib"
78-
when /mswin|mingw|cygwin/
79-
"dll"
80-
else
81-
"so"
82-
end
82+
case host_os
83+
when /mswin|mingw|cygwin/
84+
# On Windows cargo may emit either prefixed or unprefixed DLL names.
85+
["lda_ruby_rust.dll", "liblda_ruby_rust.dll"]
86+
else
87+
extension =
88+
case host_os
89+
when /darwin/
90+
"dylib"
91+
else
92+
"so"
93+
end
8394

84-
"liblda_ruby_rust.#{extension}"
95+
["liblda_ruby_rust.#{extension}"]
96+
end
8597
end
8698

8799
def rust_build_env

0 commit comments

Comments
 (0)