Skip to content

Commit 120e427

Browse files
committed
Fix compilation bug in toolchain >= 1.70.0
Fix #320
1 parent 336a03b commit 120e427

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

setuptools_rust/build.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@
2828
from ._utils import format_called_process_error
2929
from .command import RustCommand
3030
from .extension import Binding, RustBin, RustExtension, Strip
31-
from .rustc_info import get_rust_host, get_rust_target_list, get_rustc_cfgs
31+
from .rustc_info import get_rust_host, get_rust_target_list, get_rustc_cfgs, get_rust_version
32+
from semantic_version import Version
33+
34+
35+
def _detect_toolchain_1_70_or_later() -> bool:
36+
version = get_rust_version()
37+
return version.major > 1 or (
38+
version.major == 1 and version.minor >= 70
39+
)
3240

3341

3442
class build_rust(RustCommand):
@@ -142,6 +150,7 @@ def build_extension(
142150

143151
quiet = self.qbuild or ext.quiet
144152
debug = self._is_debug_build(ext)
153+
is_toolchain_1_70_or_later = _detect_toolchain_1_70_or_later()
145154

146155
cargo_args = self._cargo_args(
147156
ext=ext, target_triple=target_triple, release=not debug, quiet=quiet
@@ -160,11 +169,18 @@ def build_extension(
160169
]
161170

162171
else:
163-
rustc_args = [
164-
"--crate-type",
165-
"cdylib",
166-
*ext.rustc_flags,
167-
]
172+
# If toolchain >= 1.70.0, use '--crate-type' option of cargo.
173+
# See https://github.com/PyO3/setuptools-rust/issues/320
174+
if is_toolchain_1_70_or_later:
175+
rustc_args = [
176+
*ext.rustc_flags,
177+
]
178+
else:
179+
rustc_args = [
180+
"--crate-type",
181+
"cdylib",
182+
*ext.rustc_flags,
183+
]
168184

169185
# OSX requires special linker arguments
170186
if rustc_cfgs.get("target_os") == "macos":
@@ -189,6 +205,9 @@ def build_extension(
189205
):
190206
rustc_args.extend(["-C", f"link-args=-sSIDE_MODULE=2 -sWASM_BIGINT"])
191207

208+
if is_toolchain_1_70_or_later:
209+
cargo_args.extend(["--crate-type", "cdylib"])
210+
192211
command = [
193212
self.cargo,
194213
"rustc",

0 commit comments

Comments
 (0)