1414)
1515from distutils .sysconfig import get_config_var
1616from subprocess import check_output
17- from typing import NamedTuple , Optional
17+ from typing import List , NamedTuple , Optional , Tuple
1818
1919from setuptools .command .build_ext import get_abi3_suffix
2020
@@ -324,31 +324,18 @@ def build_extension(self, ext: RustExtension, target_triple=None):
324324
325325 if executable :
326326 for name , dest in ext .target .items ():
327- if name :
328- path = os .path .join (artifactsdir , name )
329- if os .access (path , os .X_OK ):
330- dylib_paths .append ((dest , path ))
331- continue
332- else :
333- raise DistutilsExecError (
334- "Rust build failed; "
335- f"unable to find executable '{ name } ' in '{ target_dir } '"
336- )
337- else :
338- # search executable
339- for name in os .listdir (artifactsdir ):
340- path = os .path .join (artifactsdir , name )
341- if name .startswith ("." ) or not os .path .isfile (path ):
342- continue
327+ if not name :
328+ name = dest .split ("." )[- 1 ]
329+ name += sysconfig .get_config_var ("EXE" )
343330
344- if os .access ( path , os . X_OK ):
345- dylib_paths . append (( ext . name , path ))
346- break
347-
348- if not dylib_paths :
349- raise DistutilsExecError (
350- f"Rust build failed; unable to find executable in { target_dir } "
351- )
331+ path = os .path . join ( artifactsdir , name )
332+ if os . access ( path , os . X_OK ):
333+ dylib_paths . append (( dest , path ))
334+ else :
335+ raise DistutilsExecError (
336+ "Rust build failed; "
337+ f" unable to find executable ' { name } ' in ' { artifactsdir } ' "
338+ )
352339 else :
353340 if sys .platform == "win32" or sys .platform == "cygwin" :
354341 dylib_ext = "dll"
@@ -372,7 +359,7 @@ def build_extension(self, ext: RustExtension, target_triple=None):
372359 )
373360 return dylib_paths
374361
375- def install_extension (self , ext : RustExtension , dylib_paths ):
362+ def install_extension (self , ext : RustExtension , dylib_paths : List [ Tuple [ str , str ]] ):
376363 executable = ext .binding == Binding .Exec
377364 debug_build = ext .debug if ext .debug is not None else self .inplace
378365 debug_build = self .debug if self .debug is not None else debug_build
@@ -383,23 +370,26 @@ def install_extension(self, ext: RustExtension, dylib_paths):
383370 build_ext = self .get_finalized_command ("build_ext" )
384371 build_ext .inplace = self .inplace
385372
386- for target_fname , dylib_path in dylib_paths :
387- if not target_fname :
388- target_fname = os .path .basename (
373+ for module_name , dylib_path in dylib_paths :
374+ if not module_name :
375+ module_name = os .path .basename (
389376 os .path .splitext (os .path .basename (dylib_path )[3 :])[0 ]
390377 )
391378
392379 if executable :
393- ext_path = build_ext .get_ext_fullpath (target_fname )
380+ ext_path = build_ext .get_ext_fullpath (module_name )
394381 # remove .so extension
395382 ext_path , _ = os .path .splitext (ext_path )
396383 # remove python3 extension (i.e. cpython-36m)
397384 ext_path , _ = os .path .splitext (ext_path )
398385
386+ # Add expected extension
387+ ext_path += sysconfig .get_config_var ("EXE" )
388+
399389 os .makedirs (os .path .dirname (ext_path ), exist_ok = True )
400- ext .install_script (ext_path )
390+ ext .install_script (module_name . split ( "." )[ - 1 ], ext_path )
401391 else :
402- ext_path = self .get_dylib_ext_path (ext , target_fname )
392+ ext_path = self .get_dylib_ext_path (ext , module_name )
403393 os .makedirs (os .path .dirname (ext_path ), exist_ok = True )
404394
405395 shutil .copyfile (dylib_path , ext_path )
0 commit comments