Skip to content

Commit 6bee2ad

Browse files
committed
python: fix support for 3.6.0
1 parent cf9db7c commit 6bee2ad

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixed
6+
- Fix incompatibility with Python 3.6.0 using default values for NamedTuple classes. [#184](https://github.com/PyO3/setuptools-rust/pull/184)
7+
38
## 1.0.0 (2021-11-21)
49
### Added
510
- Add `--target` command line option for specifying target triple. [#136](https://github.com/PyO3/setuptools-rust/pull/136)

setuptools_rust/build.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ def get_target_info(self) -> "_TargetInfo":
8282
# Automatic target detection can be overridden via the CARGO_BUILD_TARGET
8383
# environment variable or --target command line option
8484
if self.plat_name == "win32":
85-
return _TargetInfo("i686-pc-windows-msvc")
85+
return _TargetInfo.for_triple("i686-pc-windows-msvc")
8686
elif self.plat_name == "win-amd64":
87-
return _TargetInfo("x86_64-pc-windows-msvc")
87+
return _TargetInfo.for_triple("x86_64-pc-windows-msvc")
8888
elif self.plat_name.startswith("macosx-") and platform.machine() == "x86_64":
8989
# x86_64 or arm64 macOS targeting x86_64
90-
return _TargetInfo("x86_64-apple-darwin")
90+
return _TargetInfo.for_triple("x86_64-apple-darwin")
9191

9292
cross_compile_info = self.get_nix_cross_compile_info()
9393
if cross_compile_info is not None:
@@ -105,15 +105,17 @@ def get_target_info(self) -> "_TargetInfo":
105105
return target_info
106106

107107
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+
)
109111

110112
raise DistutilsPlatformError(
111113
"Don't know the correct rust target for system type %s. Please "
112114
"set the CARGO_BUILD_TARGET environment variable."
113115
% cross_compile_info.host_type
114116
)
115117

116-
return _TargetInfo(self.target)
118+
return _TargetInfo.for_triple(self.target)
117119

118120
def get_nix_cross_compile_info(self) -> Optional["_CrossCompileInfo"]:
119121
# See https://github.com/PyO3/setuptools-rust/issues/138
@@ -129,16 +131,15 @@ def get_nix_cross_compile_info(self) -> Optional["_CrossCompileInfo"]:
129131
return None
130132

131133
stdlib = sysconfig.get_path("stdlib")
134+
assert stdlib is not None
132135
cross_lib = os.path.dirname(stdlib)
133136

134137
bldshared = sysconfig.get_config_var("BLDSHARED")
135138
if not bldshared:
136139
linker = None
137140
linker_args = None
138141
else:
139-
bldshared = bldshared.split()
140-
linker = bldshared[0]
141-
linker_args = bldshared[1:]
142+
[linker, linker_args] = bldshared.split(maxsplit=1)
142143

143144
return _CrossCompileInfo(host_type, cross_lib, linker, linker_args)
144145

@@ -169,7 +170,7 @@ def build_extension(self, ext: RustExtension, target_triple=None):
169170
if target_triple is None:
170171
target_info = self.get_target_info()
171172
else:
172-
target_info = _TargetInfo(target_triple)
173+
target_info = _TargetInfo.for_triple(target_triple)
173174
rust_target_info = get_rust_target_info(target_info.triple)
174175

175176
# 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):
326327
for name, dest in ext.target.items():
327328
if not name:
328329
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
330333

331334
path = os.path.join(artifactsdir, name)
332335
if os.access(path, os.X_OK):
@@ -469,9 +472,13 @@ def _py_limited_api(self) -> PyLimitedApi:
469472

470473
class _TargetInfo(NamedTuple):
471474
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)
475482

476483
def is_compatible_with(self, target: str) -> bool:
477484
if self.triple == target:
@@ -487,9 +494,9 @@ def is_compatible_with(self, target: str) -> bool:
487494

488495
class _CrossCompileInfo(NamedTuple):
489496
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]
493500

494501
def to_target_info(self) -> Optional[_TargetInfo]:
495502
"""Maps this cross compile info to target info.
@@ -507,7 +514,7 @@ def to_target_info(self) -> Optional[_TargetInfo]:
507514
# the vendor field can be ignored, so x86_64-pc-linux-gnu is compatible
508515
# with x86_64-unknown-linux-gnu
509516
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:
511518
return _TargetInfo(
512519
without_vendor, self.cross_lib, self.linker, self.linker_args
513520
)

0 commit comments

Comments
 (0)