diff --git a/setuptools_rust/build.py b/setuptools_rust/build.py index a0685efa..d8bea752 100644 --- a/setuptools_rust/build.py +++ b/setuptools_rust/build.py @@ -28,7 +28,8 @@ from ._utils import format_called_process_error from .command import RustCommand from .extension import Binding, RustBin, RustExtension, Strip -from .rustc_info import get_rust_host, get_rust_target_list, get_rustc_cfgs +from .rustc_info import get_rust_host, get_rust_target_list, get_rustc_cfgs, get_rust_version +from semantic_version import Version class build_rust(RustCommand): @@ -142,6 +143,7 @@ def build_extension( quiet = self.qbuild or ext.quiet debug = self._is_debug_build(ext) + is_new_toolchain = get_rust_version() >= Version('1.70.0-nightly') cargo_args = self._cargo_args( ext=ext, target_triple=target_triple, release=not debug, quiet=quiet @@ -160,11 +162,18 @@ def build_extension( ] else: - rustc_args = [ - "--crate-type", - "cdylib", - *ext.rustc_flags, - ] + # If toolchain >= 1.70.0, use '--crate-type' option of cargo. + # See https://github.com/PyO3/setuptools-rust/issues/320 + if is_new_toolchain: + rustc_args = [ + *ext.rustc_flags, + ] + else: + rustc_args = [ + "--crate-type", + "cdylib", + *ext.rustc_flags, + ] # OSX requires special linker arguments if rustc_cfgs.get("target_os") == "macos": @@ -189,6 +198,9 @@ def build_extension( ): rustc_args.extend(["-C", f"link-args=-sSIDE_MODULE=2 -sWASM_BIGINT"]) + if is_new_toolchain: + cargo_args.extend(["--crate-type", "cdylib"]) + command = [ self.cargo, "rustc",