|
10 | 10 | DistutilsExecError,
|
11 | 11 | DistutilsFileError,
|
12 | 12 | )
|
| 13 | +from distutils.sysconfig import get_config_var |
| 14 | +from setuptools.command.build_ext import get_abi3_suffix |
13 | 15 | from subprocess import check_output
|
14 | 16 |
|
15 | 17 | from .command import RustCommand
|
16 | 18 | from .extension import Binding, RustExtension, Strip
|
17 |
| -from .utils import rust_features, get_rust_target_info |
| 19 | +from .utils import binding_features, get_rust_target_info |
18 | 20 |
|
19 | 21 |
|
20 | 22 | class build_rust(RustCommand):
|
@@ -138,8 +140,11 @@ def build_extension(self, ext: RustExtension, target_triple=None):
|
138 | 140 | f"can't find Rust extension project file: {ext.path}"
|
139 | 141 | )
|
140 | 142 |
|
141 |
| - features = set(ext.features) |
142 |
| - features.update(rust_features(binding=ext.binding)) |
| 143 | + bdist_wheel = self.get_finalized_command('bdist_wheel') |
| 144 | + features = { |
| 145 | + *ext.features, |
| 146 | + *binding_features(ext, py_limited_api=bdist_wheel.py_limited_api) |
| 147 | + } |
143 | 148 |
|
144 | 149 | debug_build = ext.debug if ext.debug is not None else self.inplace
|
145 | 150 | debug_build = self.debug if self.debug is not None else debug_build
|
@@ -340,18 +345,26 @@ def install_extension(self, ext: RustExtension, dylib_paths):
|
340 | 345 | mode |= (mode & 0o444) >> 2 # copy R bits to X
|
341 | 346 | os.chmod(ext_path, mode)
|
342 | 347 |
|
343 |
| - def get_dylib_ext_path(self, ext, target_fname): |
| 348 | + def get_dylib_ext_path( |
| 349 | + self, |
| 350 | + ext: RustExtension, |
| 351 | + target_fname: str |
| 352 | + ) -> str: |
344 | 353 | build_ext = self.get_finalized_command("build_ext")
|
345 |
| - # Technically it's supposed to contain a |
346 |
| - # `setuptools.Extension`, but in practice the only attribute it |
347 |
| - # checks is `ext.py_limited_api`. |
348 |
| - modpath = target_fname.split('.')[-1] |
349 |
| - assert modpath not in build_ext.ext_map |
350 |
| - build_ext.ext_map[modpath] = ext |
351 |
| - try: |
352 |
| - return build_ext.get_ext_fullpath(target_fname) |
353 |
| - finally: |
354 |
| - del build_ext.ext_map[modpath] |
| 354 | + bdist_wheel = self.get_finalized_command("bdist_wheel") |
| 355 | + |
| 356 | + filename = build_ext.get_ext_fullpath(target_fname) |
| 357 | + |
| 358 | + if ( |
| 359 | + (ext.py_limited_api == "auto" and bdist_wheel.py_limited_api) |
| 360 | + or (ext.py_limited_api) |
| 361 | + ): |
| 362 | + abi3_suffix = get_abi3_suffix() |
| 363 | + if abi3_suffix is not None: |
| 364 | + so_ext = get_config_var('EXT_SUFFIX') |
| 365 | + filename = filename[:-len(so_ext)] + get_abi3_suffix() |
| 366 | + |
| 367 | + return filename |
355 | 368 |
|
356 | 369 | @staticmethod
|
357 | 370 | def create_universal2_binary(output_path, input_paths):
|
|
0 commit comments