|
42 | 42 | import tomllib |
43 | 43 |
|
44 | 44 | import mesonpy._compat |
| 45 | +import mesonpy._dylib |
45 | 46 | import mesonpy._elf |
46 | 47 | import mesonpy._introspection |
47 | 48 | import mesonpy._tags |
@@ -528,19 +529,32 @@ def _install_path( |
528 | 529 | arcname = os.path.join(destination, os.path.relpath(path, origin).replace(os.path.sep, '/')) |
529 | 530 | wheel_file.write(path, arcname) |
530 | 531 | else: |
531 | | - if self._has_internal_libs and platform.system() == 'Linux': |
532 | | - # add .mesonpy.libs to the RPATH of ELF files |
533 | | - if self._is_native(os.fspath(origin)): |
534 | | - # copy ELF to our working directory to avoid Meson having to regenerate the file |
535 | | - new_origin = self._libs_build_dir / pathlib.Path(origin).relative_to(self._build_dir) |
536 | | - os.makedirs(new_origin.parent, exist_ok=True) |
537 | | - shutil.copy2(origin, new_origin) |
538 | | - origin = new_origin |
539 | | - # add our in-wheel libs folder to the RPATH |
540 | | - elf = mesonpy._elf.ELF(origin) |
541 | | - libdir_path = f'$ORIGIN/{os.path.relpath(f".{self._project.name}.mesonpy.libs", destination.parent)}' |
542 | | - if libdir_path not in elf.rpath: |
543 | | - elf.rpath = [*elf.rpath, libdir_path] |
| 532 | + if self._has_internal_libs: |
| 533 | + if platform.system() == 'Linux' or platform.system() == 'Darwin': |
| 534 | + # add .mesonpy.libs to the RPATH of ELF files |
| 535 | + if self._is_native(os.fspath(origin)): |
| 536 | + # copy ELF to our working directory to avoid Meson having to regenerate the file |
| 537 | + new_origin = self._libs_build_dir / pathlib.Path(origin).relative_to(self._build_dir) |
| 538 | + os.makedirs(new_origin.parent, exist_ok=True) |
| 539 | + shutil.copy2(origin, new_origin) |
| 540 | + origin = new_origin |
| 541 | + # add our in-wheel libs folder to the RPATH |
| 542 | + if platform.system() == 'Linux': |
| 543 | + elf = mesonpy._elf.ELF(origin) |
| 544 | + libdir_path = \ |
| 545 | + f'$ORIGIN/{os.path.relpath(f".{self._project.name}.mesonpy.libs", destination.parent)}' |
| 546 | + if libdir_path not in elf.rpath: |
| 547 | + elf.rpath = [*elf.rpath, libdir_path] |
| 548 | + elif platform.system() == 'Darwin': |
| 549 | + dylib = mesonpy._dylib.Dylib(origin) |
| 550 | + libdir_path = \ |
| 551 | + f'@loader_path/{os.path.relpath(f".{self._project.name}.mesonpy.libs", destination.parent)}' |
| 552 | + if libdir_path not in dylib.rpath: |
| 553 | + dylib.rpath = [*dylib.rpath, libdir_path] |
| 554 | + else: |
| 555 | + # Internal libraries are currently unsupported on this platform |
| 556 | + raise NotImplementedError("Bundling libraries in wheel is not supported on platform '{}'" |
| 557 | + .format(platform.system())) |
544 | 558 |
|
545 | 559 | wheel_file.write(origin, location) |
546 | 560 |
|
@@ -577,7 +591,6 @@ def build(self, directory: Path) -> pathlib.Path: |
577 | 591 |
|
578 | 592 | # install bundled libraries |
579 | 593 | for destination, origin in self._wheel_files['mesonpy-libs']: |
580 | | - assert platform.system() == 'Linux', 'Bundling libraries in wheel is currently only supported in POSIX!' |
581 | 594 | destination = pathlib.Path(f'.{self._project.name}.mesonpy.libs', destination) |
582 | 595 | self._install_path(whl, counter, origin, destination) |
583 | 596 |
|
|
0 commit comments