|
3 | 3 | import os
|
4 | 4 | import platform
|
5 | 5 | import shutil
|
6 |
| -import sys |
7 | 6 | import subprocess
|
| 7 | +import sys |
8 | 8 | import sysconfig
|
9 | 9 | from distutils.errors import (
|
10 | 10 | CompileError,
|
|
13 | 13 | DistutilsPlatformError,
|
14 | 14 | )
|
15 | 15 | from distutils.sysconfig import get_config_var
|
16 |
| -from setuptools.command.build_ext import get_abi3_suffix |
17 | 16 | from subprocess import check_output
|
18 | 17 |
|
| 18 | +from setuptools.command.build_ext import get_abi3_suffix |
| 19 | + |
19 | 20 | from .command import RustCommand
|
20 | 21 | from .extension import Binding, RustExtension, Strip
|
21 |
| -from .utils import binding_features, get_rust_target_info, get_rust_target_list |
| 22 | +from .utils import ( |
| 23 | + PyLimitedApi, |
| 24 | + binding_features, |
| 25 | + get_rust_target_info, |
| 26 | + get_rust_target_list, |
| 27 | +) |
| 28 | + |
22 | 29 |
|
23 | 30 | class _TargetInfo:
|
24 | 31 | def __init__(self, triple=None, cross_lib=None, linker=None, link_args=None):
|
@@ -203,10 +210,9 @@ def build_extension(self, ext: RustExtension, target_triple=None):
|
203 | 210 | f"can't find Rust extension project file: {ext.path}"
|
204 | 211 | )
|
205 | 212 |
|
206 |
| - bdist_wheel = self.get_finalized_command('bdist_wheel') |
207 | 213 | features = {
|
208 | 214 | *ext.features,
|
209 |
| - *binding_features(ext, py_limited_api=bdist_wheel.py_limited_api) |
| 215 | + *binding_features(ext, py_limited_api=self._py_limited_api()) |
210 | 216 | }
|
211 | 217 |
|
212 | 218 | debug_build = ext.debug if ext.debug is not None else self.inplace
|
@@ -421,12 +427,11 @@ def get_dylib_ext_path(
|
421 | 427 | target_fname: str
|
422 | 428 | ) -> str:
|
423 | 429 | build_ext = self.get_finalized_command("build_ext")
|
424 |
| - bdist_wheel = self.get_finalized_command("bdist_wheel") |
425 | 430 |
|
426 | 431 | filename = build_ext.get_ext_fullpath(target_fname)
|
427 | 432 |
|
428 | 433 | if (
|
429 |
| - (ext.py_limited_api == "auto" and bdist_wheel.py_limited_api) |
| 434 | + (ext.py_limited_api == "auto" and self._py_limited_api()) |
430 | 435 | or (ext.py_limited_api)
|
431 | 436 | ):
|
432 | 437 | abi3_suffix = get_abi3_suffix()
|
@@ -463,3 +468,13 @@ def create_universal2_binary(output_path, input_paths):
|
463 | 468 | with open(input_path, "rb") as f:
|
464 | 469 | fat.add(f.read())
|
465 | 470 | fat.write_to(output_path)
|
| 471 | + |
| 472 | + def _py_limited_api(self) -> PyLimitedApi: |
| 473 | + bdist_wheel = self.distribution.get_command_obj("bdist_wheel", create=0) |
| 474 | + |
| 475 | + if bdist_wheel is None: |
| 476 | + # wheel package is not installed, not building a limited-api wheel |
| 477 | + return False |
| 478 | + else: |
| 479 | + bdist_wheel.ensure_finalized() |
| 480 | + return bdist_wheel.py_limited_api |
0 commit comments