@@ -124,7 +124,7 @@ def build_extension(
124
124
cross_lib = None
125
125
linker = None
126
126
127
- rust_target_info = get_rust_target_info (target_triple )
127
+ rustc_cfgs = _get_rustc_cfgs (target_triple )
128
128
129
129
env = _prepare_build_environment (cross_lib )
130
130
@@ -174,7 +174,7 @@ def build_extension(
174
174
175
175
# Tell musl targets not to statically link libc. See
176
176
# https://github.com/rust-lang/rust/issues/59302 for details.
177
- if b' target_env= "musl"' in rust_target_info :
177
+ if rustc_cfgs . get ( " target_env" ) == "musl" :
178
178
rustc_args .extend (["-C" , "target-feature=-crt-static" ])
179
179
180
180
command = [
@@ -368,7 +368,7 @@ def _py_limited_api(self) -> PyLimitedApi:
368
368
def _detect_rust_target (
369
369
self , forced_target_triple : Optional [str ]
370
370
) -> Optional ["_TargetInfo" ]:
371
- cross_compile_info = detect_unix_cross_compile_info ()
371
+ cross_compile_info = _detect_unix_cross_compile_info ()
372
372
if cross_compile_info is not None :
373
373
cross_target_info = cross_compile_info .to_target_info ()
374
374
if forced_target_triple is not None :
@@ -417,8 +417,12 @@ def _detect_local_rust_target(self) -> Optional["_TargetInfo"]:
417
417
# If we are on a 64-bit machine, but running a 32-bit Python, then
418
418
# we'll target a 32-bit Rust build.
419
419
if self .plat_name == "win32" :
420
+ if _get_rustc_cfgs (None ).get ("target_env" ) == "gnu" :
421
+ return _TargetInfo .for_triple ("i686-pc-windows-gnu" )
420
422
return _TargetInfo .for_triple ("i686-pc-windows-msvc" )
421
423
elif self .plat_name == "win-amd64" :
424
+ if _get_rustc_cfgs (None ).get ("target_env" ) == "gnu" :
425
+ return _TargetInfo .for_triple ("x86_64-pc-windows-gnu" )
422
426
return _TargetInfo .for_triple ("x86_64-pc-windows-msvc" )
423
427
elif self .plat_name .startswith ("macosx-" ) and platform .machine () == "x86_64" :
424
428
# x86_64 or arm64 macOS targeting x86_64
@@ -561,7 +565,7 @@ def to_target_info(self) -> Optional[_TargetInfo]:
561
565
return None
562
566
563
567
564
- def detect_unix_cross_compile_info () -> Optional ["_CrossCompileInfo" ]:
568
+ def _detect_unix_cross_compile_info () -> Optional ["_CrossCompileInfo" ]:
565
569
# See https://github.com/PyO3/setuptools-rust/issues/138
566
570
# This is to support cross compiling on *NIX, where plat_name isn't
567
571
# necessarily the same as the system we are running on. *NIX systems
@@ -588,6 +592,21 @@ def detect_unix_cross_compile_info() -> Optional["_CrossCompileInfo"]:
588
592
return _CrossCompileInfo (host_type , cross_lib , linker , linker_args )
589
593
590
594
595
+ _RustcCfgs = Dict [str , Optional [str ]]
596
+
597
+
598
+ def _get_rustc_cfgs (target_triple : Optional [str ]) -> _RustcCfgs :
599
+ cfgs : _RustcCfgs = {}
600
+ for entry in get_rust_target_info (target_triple ):
601
+ maybe_split = entry .split ("=" , maxsplit = 1 )
602
+ if len (maybe_split ) == 2 :
603
+ cfgs [maybe_split [0 ]] = maybe_split [1 ].strip ('"' )
604
+ else :
605
+ assert len (maybe_split ) == 1
606
+ cfgs [maybe_split [0 ]] = None
607
+ return cfgs
608
+
609
+
591
610
def _replace_vendor_with_unknown (target : str ) -> Optional [str ]:
592
611
"""Replaces vendor in the target triple with unknown.
593
612
0 commit comments