Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
### Fixed
- 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)
- Fix `setup.cfg` format for compatibility with "poetry==1.4.0". [#319](https://github.com/PyO3/setuptools-rust/pull/319)
- Fix to use `--crate-type` option of cargo if "toolchain >= 1.64". [#322](https://github.com/PyO3/setuptools-rust/pull/322)

## 1.5.2 (2022-09-19)
### Fixed
Expand Down
38 changes: 32 additions & 6 deletions setuptools_rust/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,22 @@
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


def _check_cargo_supports_crate_type_option() -> bool:
version = get_rust_version()

if version is None:
return False

return version.major > 1 or (version.major == 1 and version.minor >= 64) # type: ignore


class build_rust(RustCommand):
Expand Down Expand Up @@ -142,6 +157,7 @@ def build_extension(

quiet = self.qbuild or ext.quiet
debug = self._is_debug_build(ext)
use_cargo_crate_type = _check_cargo_supports_crate_type_option()

cargo_args = self._cargo_args(
ext=ext, target_triple=target_triple, release=not debug, quiet=quiet
Expand All @@ -160,11 +176,18 @@ def build_extension(
]

else:
rustc_args = [
"--crate-type",
"cdylib",
*ext.rustc_flags,
]
# If toolchain >= 1.64.0, use '--crate-type' option of cargo.
# See https://github.com/PyO3/setuptools-rust/issues/320
if use_cargo_crate_type:
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":
Expand All @@ -189,6 +212,9 @@ def build_extension(
):
rustc_args.extend(["-C", f"link-args=-sSIDE_MODULE=2 -sWASM_BIGINT"])

if use_cargo_crate_type and "--crate-type" not in cargo_args:
cargo_args.extend(["--crate-type", "cdylib"])

command = [
self.cargo,
"rustc",
Expand Down