@@ -82,12 +82,12 @@ def get_target_info(self) -> "_TargetInfo":
82
82
# Automatic target detection can be overridden via the CARGO_BUILD_TARGET
83
83
# environment variable or --target command line option
84
84
if self .plat_name == "win32" :
85
- return _TargetInfo ("i686-pc-windows-msvc" )
85
+ return _TargetInfo . for_triple ("i686-pc-windows-msvc" )
86
86
elif self .plat_name == "win-amd64" :
87
- return _TargetInfo ("x86_64-pc-windows-msvc" )
87
+ return _TargetInfo . for_triple ("x86_64-pc-windows-msvc" )
88
88
elif self .plat_name .startswith ("macosx-" ) and platform .machine () == "x86_64" :
89
89
# x86_64 or arm64 macOS targeting x86_64
90
- return _TargetInfo ("x86_64-apple-darwin" )
90
+ return _TargetInfo . for_triple ("x86_64-apple-darwin" )
91
91
92
92
cross_compile_info = self .get_nix_cross_compile_info ()
93
93
if cross_compile_info is not None :
@@ -105,15 +105,17 @@ def get_target_info(self) -> "_TargetInfo":
105
105
return target_info
106
106
107
107
if self .target :
108
- return _TargetInfo (self .target , cross_compile_info .cross_lib )
108
+ return _TargetInfo (
109
+ self .target , cross_compile_info .cross_lib , None , None
110
+ )
109
111
110
112
raise DistutilsPlatformError (
111
113
"Don't know the correct rust target for system type %s. Please "
112
114
"set the CARGO_BUILD_TARGET environment variable."
113
115
% cross_compile_info .host_type
114
116
)
115
117
116
- return _TargetInfo (self .target )
118
+ return _TargetInfo . for_triple (self .target )
117
119
118
120
def get_nix_cross_compile_info (self ) -> Optional ["_CrossCompileInfo" ]:
119
121
# See https://github.com/PyO3/setuptools-rust/issues/138
@@ -129,16 +131,15 @@ def get_nix_cross_compile_info(self) -> Optional["_CrossCompileInfo"]:
129
131
return None
130
132
131
133
stdlib = sysconfig .get_path ("stdlib" )
134
+ assert stdlib is not None
132
135
cross_lib = os .path .dirname (stdlib )
133
136
134
137
bldshared = sysconfig .get_config_var ("BLDSHARED" )
135
138
if not bldshared :
136
139
linker = None
137
140
linker_args = None
138
141
else :
139
- bldshared = bldshared .split ()
140
- linker = bldshared [0 ]
141
- linker_args = bldshared [1 :]
142
+ [linker , linker_args ] = bldshared .split (maxsplit = 1 )
142
143
143
144
return _CrossCompileInfo (host_type , cross_lib , linker , linker_args )
144
145
@@ -169,7 +170,7 @@ def build_extension(self, ext: RustExtension, target_triple=None):
169
170
if target_triple is None :
170
171
target_info = self .get_target_info ()
171
172
else :
172
- target_info = _TargetInfo (target_triple )
173
+ target_info = _TargetInfo . for_triple (target_triple )
173
174
rust_target_info = get_rust_target_info (target_info .triple )
174
175
175
176
# Make sure that if pythonXX-sys is used, it builds against the current
@@ -326,7 +327,9 @@ def build_extension(self, ext: RustExtension, target_triple=None):
326
327
for name , dest in ext .target .items ():
327
328
if not name :
328
329
name = dest .split ("." )[- 1 ]
329
- name += sysconfig .get_config_var ("EXE" )
330
+ exe = sysconfig .get_config_var ("EXE" )
331
+ if exe is not None :
332
+ name += exe
330
333
331
334
path = os .path .join (artifactsdir , name )
332
335
if os .access (path , os .X_OK ):
@@ -469,9 +472,13 @@ def _py_limited_api(self) -> PyLimitedApi:
469
472
470
473
class _TargetInfo (NamedTuple ):
471
474
triple : str
472
- cross_lib : Optional [str ] = None
473
- linker : Optional [str ] = None
474
- linker_args : Optional [str ] = None
475
+ cross_lib : Optional [str ]
476
+ linker : Optional [str ]
477
+ linker_args : Optional [str ]
478
+
479
+ @staticmethod
480
+ def for_triple (triple : str ) -> "_TargetInfo" :
481
+ return _TargetInfo (triple , None , None , None )
475
482
476
483
def is_compatible_with (self , target : str ) -> bool :
477
484
if self .triple == target :
@@ -487,9 +494,9 @@ def is_compatible_with(self, target: str) -> bool:
487
494
488
495
class _CrossCompileInfo (NamedTuple ):
489
496
host_type : str
490
- cross_lib : Optional [str ] = None
491
- linker : Optional [str ] = None
492
- linker_args : Optional [str ] = None
497
+ cross_lib : Optional [str ]
498
+ linker : Optional [str ]
499
+ linker_args : Optional [str ]
493
500
494
501
def to_target_info (self ) -> Optional [_TargetInfo ]:
495
502
"""Maps this cross compile info to target info.
@@ -507,7 +514,7 @@ def to_target_info(self) -> Optional[_TargetInfo]:
507
514
# the vendor field can be ignored, so x86_64-pc-linux-gnu is compatible
508
515
# with x86_64-unknown-linux-gnu
509
516
without_vendor = _replace_vendor_with_unknown (self .host_type )
510
- if without_vendor in targets :
517
+ if without_vendor is not None and without_vendor in targets :
511
518
return _TargetInfo (
512
519
without_vendor , self .cross_lib , self .linker , self .linker_args
513
520
)
0 commit comments