Skip to content

Commit f2224c8

Browse files
authored
Use --crate-type cargo option on >= 1.64.0 (#322)
1 parent 684bf63 commit f2224c8

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
### Fixed
55
- Fix a bug where rebuilding the library would cause any running processes using it to segfault. [#295](https://github.com/PyO3/setuptools-rust/pull/295)
66
- Fix `setup.cfg` format for compatibility with "poetry==1.4.0". [#319](https://github.com/PyO3/setuptools-rust/pull/319)
7+
- Fix to use `--crate-type` option of cargo if "toolchain >= 1.64". [#322](https://github.com/PyO3/setuptools-rust/pull/322)
78

89
## 1.5.2 (2022-09-19)
910
### Fixed

Diff for: setuptools_rust/build.py

+32-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,22 @@
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 (
32+
get_rust_host,
33+
get_rust_target_list,
34+
get_rustc_cfgs,
35+
get_rust_version,
36+
)
37+
from semantic_version import Version
38+
39+
40+
def _check_cargo_supports_crate_type_option() -> bool:
41+
version = get_rust_version()
42+
43+
if version is None:
44+
return False
45+
46+
return version.major > 1 or (version.major == 1 and version.minor >= 64) # type: ignore
3247

3348

3449
class build_rust(RustCommand):
@@ -142,6 +157,7 @@ def build_extension(
142157

143158
quiet = self.qbuild or ext.quiet
144159
debug = self._is_debug_build(ext)
160+
use_cargo_crate_type = _check_cargo_supports_crate_type_option()
145161

146162
cargo_args = self._cargo_args(
147163
ext=ext, target_triple=target_triple, release=not debug, quiet=quiet
@@ -160,11 +176,18 @@ def build_extension(
160176
]
161177

162178
else:
163-
rustc_args = [
164-
"--crate-type",
165-
"cdylib",
166-
*ext.rustc_flags,
167-
]
179+
# If toolchain >= 1.64.0, use '--crate-type' option of cargo.
180+
# See https://github.com/PyO3/setuptools-rust/issues/320
181+
if use_cargo_crate_type:
182+
rustc_args = [
183+
*ext.rustc_flags,
184+
]
185+
else:
186+
rustc_args = [
187+
"--crate-type",
188+
"cdylib",
189+
*ext.rustc_flags,
190+
]
168191

169192
# OSX requires special linker arguments
170193
if rustc_cfgs.get("target_os") == "macos":
@@ -189,6 +212,9 @@ def build_extension(
189212
):
190213
rustc_args.extend(["-C", f"link-args=-sSIDE_MODULE=2 -sWASM_BIGINT"])
191214

215+
if use_cargo_crate_type and "--crate-type" not in cargo_args:
216+
cargo_args.extend(["--crate-type", "cdylib"])
217+
192218
command = [
193219
self.cargo,
194220
"rustc",

0 commit comments

Comments
 (0)