|
| 1 | +import os |
| 2 | +import shlex |
| 3 | + |
| 4 | +try: |
| 5 | + import tomllib |
| 6 | +except ModuleNotFoundError: |
| 7 | + import tomli as tomllib |
| 8 | +from setuptools import setup |
| 9 | + |
| 10 | +from setuptools_rust import RustBin |
| 11 | + |
| 12 | +# Force the wheel to be platform specific |
| 13 | +# https://stackoverflow.com/a/45150383/3549270 |
| 14 | +# There's also the much more concise solution in |
| 15 | +# https://stackoverflow.com/a/53463910/3549270, |
| 16 | +# but that would require python-dev |
| 17 | +try: |
| 18 | + # noinspection PyPackageRequirements,PyUnresolvedReferences |
| 19 | + from wheel.bdist_wheel import bdist_wheel as _bdist_wheel |
| 20 | + |
| 21 | + # noinspection PyPep8Naming,PyAttributeOutsideInit |
| 22 | + class bdist_wheel(_bdist_wheel): |
| 23 | + def finalize_options(self): |
| 24 | + _bdist_wheel.finalize_options(self) |
| 25 | + self.root_is_pure = False |
| 26 | + |
| 27 | +except ImportError: |
| 28 | + bdist_wheel = None |
| 29 | + |
| 30 | +with open("Cargo.toml", "rb") as fp: |
| 31 | + cargo_data = tomllib.load(fp) |
| 32 | + version = cargo_data["package"]["version"] |
| 33 | + description = cargo_data["package"]["description"] |
| 34 | + |
| 35 | +# Use `--no-default-features` by default for a minimal build to support PEP 517. |
| 36 | +# `MATURIN_SETUP_ARGS` env var can be used to pass customized arguments to cargo. |
| 37 | +cargo_args = ["--no-default-features"] |
| 38 | +long_description = description |
| 39 | + |
| 40 | +setup( |
| 41 | + version=version, |
| 42 | + cmdclass={"bdist_wheel": bdist_wheel}, |
| 43 | + rust_extensions=[RustBin("cargo-ament-build", args=cargo_args, cargo_manifest_args=["--locked"])], |
| 44 | + zip_safe=False, |
| 45 | + description=description, |
| 46 | + long_description=long_description, |
| 47 | +) |
0 commit comments