|
46 | 46 | import pyproject_metadata |
47 | 47 |
|
48 | 48 | import mesonpy._compat |
49 | | -import mesonpy._dylib |
50 | | -import mesonpy._elf |
| 49 | +import mesonpy._rpath |
51 | 50 | import mesonpy._tags |
52 | 51 | import mesonpy._util |
53 | 52 | import mesonpy._wheelfile |
@@ -285,8 +284,6 @@ def __init__( |
285 | 284 | self._build_dir = build_dir |
286 | 285 | self._sources = sources |
287 | 286 |
|
288 | | - self._libs_build_dir = self._build_dir / 'mesonpy-wheel-libs' |
289 | | - |
290 | 287 | @cached_property |
291 | 288 | def _wheel_files(self) -> DefaultDict[str, List[Tuple[pathlib.Path, str]]]: |
292 | 289 | return _map_to_wheel(self._sources) |
@@ -438,49 +435,22 @@ def _is_native(self, file: Union[str, pathlib.Path]) -> bool: |
438 | 435 | return True |
439 | 436 | return False |
440 | 437 |
|
441 | | - def _install_path( |
442 | | - self, |
443 | | - wheel_file: mesonpy._wheelfile.WheelFile, |
444 | | - origin: Path, |
445 | | - destination: pathlib.Path, |
446 | | - ) -> None: |
447 | | - """"Install" file or directory into the wheel |
448 | | - and do the necessary processing before doing so. |
449 | | -
|
450 | | - Some files might need to be fixed up to set the RPATH to the internal |
451 | | - library directory on Linux wheels for eg. |
452 | | - """ |
453 | | - location = destination.as_posix() |
| 438 | + def _install_path(self, wheel_file: mesonpy._wheelfile.WheelFile, origin: Path, destination: pathlib.Path) -> None: |
| 439 | + """Add a file to the wheel.""" |
454 | 440 |
|
455 | 441 | if self._has_internal_libs: |
456 | | - if platform.system() == 'Linux' or platform.system() == 'Darwin': |
457 | | - # add .mesonpy.libs to the RPATH of ELF files |
458 | | - if self._is_native(os.fspath(origin)): |
459 | | - # copy ELF to our working directory to avoid Meson having to regenerate the file |
460 | | - new_origin = self._libs_build_dir / pathlib.Path(origin).relative_to(self._build_dir) |
461 | | - os.makedirs(new_origin.parent, exist_ok=True) |
462 | | - shutil.copy2(origin, new_origin) |
463 | | - origin = new_origin |
464 | | - # add our in-wheel libs folder to the RPATH |
465 | | - if platform.system() == 'Linux': |
466 | | - elf = mesonpy._elf.ELF(origin) |
467 | | - libdir_path = \ |
468 | | - f'$ORIGIN/{os.path.relpath(f".{self._project.name}.mesonpy.libs", destination.parent)}' |
469 | | - if libdir_path not in elf.rpath: |
470 | | - elf.rpath = [*elf.rpath, libdir_path] |
471 | | - elif platform.system() == 'Darwin': |
472 | | - dylib = mesonpy._dylib.Dylib(origin) |
473 | | - libdir_path = \ |
474 | | - f'@loader_path/{os.path.relpath(f".{self._project.name}.mesonpy.libs", destination.parent)}' |
475 | | - if libdir_path not in dylib.rpath: |
476 | | - dylib.rpath = [*dylib.rpath, libdir_path] |
477 | | - else: |
478 | | - # Internal libraries are currently unsupported on this platform |
479 | | - raise NotImplementedError("Bundling libraries in wheel is not supported on platform '{}'" |
480 | | - .format(platform.system())) |
| 442 | + if self._is_native(os.fspath(origin)): |
| 443 | + # When an executable, libray, or Python extension module is |
| 444 | + # dynamically linked to a library built as part of the project, |
| 445 | + # Meson adds a library load path to it pointing to the build |
| 446 | + # directory, in the form of a relative RPATH entry. meson-python |
| 447 | + # relocates the shared libraries to the $project.mesonpy.libs |
| 448 | + # folder. Rewrite the RPATH to point to that folder instead. |
| 449 | + libspath = os.path.relpath(f'.{self._project.name}.mesonpy.libs', destination.parent) |
| 450 | + mesonpy._rpath.fix_rpath(origin, libspath) |
481 | 451 |
|
482 | 452 | try: |
483 | | - wheel_file.write(origin, location) |
| 453 | + wheel_file.write(origin, destination.as_posix()) |
484 | 454 | except FileNotFoundError: |
485 | 455 | # work around for Meson bug, see https://github.com/mesonbuild/meson/pull/11655 |
486 | 456 | if not os.fspath(origin).endswith('.pdb'): |
|
0 commit comments