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