@@ -204,6 +204,42 @@ impl WindowsResource {
204204 PathBuf :: from ( "/" )
205205 } ;
206206
207+ let prefix = if let Ok ( cross) = env:: var ( "CROSS_COMPILE" ) {
208+ cross
209+ } else if env:: var_os ( "HOST" ) . unwrap ( ) != env:: var_os ( "TARGET" ) . unwrap ( )
210+ && cfg ! ( not( target_env = "msvc" ) )
211+ {
212+ match env:: var ( "TARGET" ) . unwrap ( ) . as_str ( ) {
213+ "x86_64-pc-windows-gnu" => "x86_64-w64-mingw32-" ,
214+ "i686-pc-windows-gnu" => "i686-w64-mingw32-" ,
215+ "i586-pc-windows-gnu" => "i586-w64-mingw32-" ,
216+ // MinGW supports ARM64 only with an LLVM-based toolchain
217+ // (x86 users might also be using LLVM, but we can't tell that from the Rust target...)
218+ "aarch64-pc-windows-gnu" => "llvm-" ,
219+ // fail safe
220+ _ => {
221+ println ! (
222+ "cargo:warning=unknown Windows target used for cross-compilation; \
223+ invoking unprefixed windres"
224+ ) ;
225+ ""
226+ }
227+ }
228+ . into ( )
229+ } else {
230+ "" . into ( )
231+ } ;
232+ let windres_path = if let Ok ( windres) = env:: var ( "WINDRES" ) {
233+ windres
234+ } else {
235+ format ! ( "{}windres" , prefix)
236+ } ;
237+ let ar_path = if let Ok ( ar) = env:: var ( "AR" ) {
238+ ar
239+ } else {
240+ format ! ( "{}ar" , prefix)
241+ } ;
242+
207243 WindowsResource {
208244 toolkit_path : sdk,
209245 properties : props,
@@ -214,17 +250,8 @@ impl WindowsResource {
214250 manifest : None ,
215251 manifest_file : None ,
216252 output_directory : env:: var ( "OUT_DIR" ) . unwrap_or_else ( |_| "." . to_string ( ) ) ,
217-
218- #[ cfg( windows) ]
219- windres_path : "windres.exe" . to_string ( ) ,
220- #[ cfg( unix) ]
221- windres_path : "windres" . to_string ( ) ,
222-
223- #[ cfg( windows) ]
224- ar_path : "ar.exe" . to_string ( ) ,
225- #[ cfg( unix) ]
226- ar_path : "ar" . to_string ( ) ,
227-
253+ windres_path,
254+ ar_path,
228255 add_toolkit_include : false ,
229256 append_rc_content : String :: new ( ) ,
230257 }
0 commit comments