| 1 |
# maturin is self bootstrapping, however on platforms like FreeBSD that aren't |
| 2 |
# manylinux/musllinux, pip will try installing maturin from the source distribution. |
| 3 |
# That source distribution obviously can't depend on maturin, so we're using |
| 4 |
# the always available setuptools. |
| 5 |
# |
| 6 |
# Note that this is really only a workaround for bootstrapping and not suited |
| 7 |
# for general purpose packaging, i.e. only building a wheel (as in |
| 8 |
# `python setup.py bdist_wheel`) and installing (as in |
| 9 |
# `pip install <source dir>`) are supported. For creating a source distribution |
| 10 |
# for maturin itself use `maturin sdist`. |
| 11 |
|
| 12 |
import os |
| 13 |
import shlex |
| 14 |
import shutil |
| 15 |
|
| 16 |
try: |
| 17 |
import tomllib |
| 18 |
except ModuleNotFoundError: |
| 19 |
import tomli as tomllib |
| 20 |
from setuptools import setup |
| 21 |
|
| 22 |
from setuptools_rust import RustBin |
| 23 |
|
| 24 |
# Force the wheel to be platform specific |
| 25 |
# https://stackoverflow.com/a/45150383/3549270 |
| 26 |
# There's also the much more concise solution in |
| 27 |
# https://stackoverflow.com/a/53463910/3549270, |
| 28 |
# but that would require python-dev |
| 29 |
try: |
| 30 |
# noinspection PyPackageRequirements,PyUnresolvedReferences |
| 31 |
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel |
| 32 |
|
| 33 |
# noinspection PyPep8Naming,PyAttributeOutsideInit |
| 34 |
class bdist_wheel(_bdist_wheel): |
| 35 |
def finalize_options(self): |
| 36 |
_bdist_wheel.finalize_options(self) |
| 37 |
self.root_is_pure = False |
| 38 |
|
| 39 |
except ImportError: |
| 40 |
bdist_wheel = None |
| 41 |
|
| 42 |
with open("Cargo.toml", "rb") as fp: |
| 43 |
version = tomllib.load(fp)["package"]["version"] |
| 44 |
|
| 45 |
# Use `--no-default-features` by default for a minimal build to support PEP 517. |
| 46 |
# `MATURIN_SETUP_ARGS` env var can be used to pass customized arguments to cargo. |
| 47 |
cargo_args = ["--no-default-features"] |
| 48 |
if os.getenv("MATURIN_SETUP_ARGS"): |
| 49 |
cargo_args = shlex.split(os.getenv("MATURIN_SETUP_ARGS", "")) |
| 50 |
|
| 51 |
if not os.environ.get("MATURIN_NO_INSTALL_RUST") and not shutil.which("cargo"): |
| 52 |
from puccinialin import setup_rust |
| 53 |
|
| 54 |
print("Rust not found, installing into a temporary directory") |
| 55 |
extra_env = setup_rust() |
| 56 |
env = {**os.environ, **extra_env} |
| 57 |
else: |
| 58 |
env = None |
| 59 |
|
| 60 |
setup( |
| 61 |
version=version, |
| 62 |
cmdclass={"bdist_wheel": bdist_wheel}, |
| 63 |
rust_extensions=[RustBin("maturin", args=cargo_args, cargo_manifest_args=["--locked"], env=env)], |
| 64 |
zip_safe=False, |
| 65 |
) |