@@ -50,9 +50,12 @@ task test: :compile
5050task default : :test
5151
5252def 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
6669end
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
81100end
82101
83102def 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 }
0 commit comments