14
14
)
15
15
from distutils .sysconfig import get_config_var
16
16
from subprocess import check_output
17
- from typing import NamedTuple , Optional
17
+ from typing import List , NamedTuple , Optional , Tuple
18
18
19
19
from setuptools .command .build_ext import get_abi3_suffix
20
20
@@ -324,31 +324,18 @@ def build_extension(self, ext: RustExtension, target_triple=None):
324
324
325
325
if executable :
326
326
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" )
343
330
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
+ )
352
339
else :
353
340
if sys .platform == "win32" or sys .platform == "cygwin" :
354
341
dylib_ext = "dll"
@@ -372,7 +359,7 @@ def build_extension(self, ext: RustExtension, target_triple=None):
372
359
)
373
360
return dylib_paths
374
361
375
- def install_extension (self , ext : RustExtension , dylib_paths ):
362
+ def install_extension (self , ext : RustExtension , dylib_paths : List [ Tuple [ str , str ]] ):
376
363
executable = ext .binding == Binding .Exec
377
364
debug_build = ext .debug if ext .debug is not None else self .inplace
378
365
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):
383
370
build_ext = self .get_finalized_command ("build_ext" )
384
371
build_ext .inplace = self .inplace
385
372
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 (
389
376
os .path .splitext (os .path .basename (dylib_path )[3 :])[0 ]
390
377
)
391
378
392
379
if executable :
393
- ext_path = build_ext .get_ext_fullpath (target_fname )
380
+ ext_path = build_ext .get_ext_fullpath (module_name )
394
381
# remove .so extension
395
382
ext_path , _ = os .path .splitext (ext_path )
396
383
# remove python3 extension (i.e. cpython-36m)
397
384
ext_path , _ = os .path .splitext (ext_path )
398
385
386
+ # Add expected extension
387
+ ext_path += sysconfig .get_config_var ("EXE" )
388
+
399
389
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 )
401
391
else :
402
- ext_path = self .get_dylib_ext_path (ext , target_fname )
392
+ ext_path = self .get_dylib_ext_path (ext , module_name )
403
393
os .makedirs (os .path .dirname (ext_path ), exist_ok = True )
404
394
405
395
shutil .copyfile (dylib_path , ext_path )
0 commit comments