Skip to content

Commit f82e388

Browse files
authored
Merge pull request #63 from openzim/rgaudin/macos-load
Rewrite runtime path lookup to libzim on macOS
2 parents b725cb6 + bfb21ae commit f82e388

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

.github/workflows/release.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
echo ::set-env name=LIBZIM_RELEASE::libzim_macos-x86_64-$LIBZIM_VERSION
3939
echo ::set-env name=LIBZIM_LIBRARY_PATH::lib/libzim.${LIBZIM_VERSION:0:1}.dylib
4040
echo ::set-env name=PLAFTORM_NAME::macosx_10.9_x86_64
41+
echo ::set-env name=RPATH::@loader_path/
4142
4243
- name: set linux environ
4344
if: matrix.os == 'ubuntu-latest'
@@ -46,6 +47,7 @@ jobs:
4647
echo ::set-env name=LIBZIM_RELEASE::libzim_linux-x86_64-$LIBZIM_VERSION
4748
echo ::set-env name=LIBZIM_LIBRARY_PATH::lib/x86_64-linux-gnu/libzim.so.$LIBZIM_VERSION
4849
echo ::set-env name=PLAFTORM_NAME::manylinux1_x86_64
50+
echo ::set-env name=RPATH::\$ORIGIN
4951
5052
- name: Cache libzim dylib & headers
5153
uses: actions/cache@master
@@ -78,15 +80,17 @@ jobs:
7880
- name: Build cython, sdist, and bdist_wheels
7981
run: |
8082
pip install --upgrade "cython>=0.29.20,<3.0" setuptools pip wheel
81-
python3 setup.py build_ext --rpath='$ORIGIN'
83+
python3 setup.py build_ext --rpath $RPATH
8284
if [[ "${{ matrix.python-version }}" == "3.6" ]]
8385
then
8486
python3 setup.py sdist
8587
fi
8688
8789
- name: add macOS libzim binary to source for wheel
8890
if: matrix.os == 'macos-latest'
89-
run: cp -p lib/libzim.${LIBZIM_VERSION:0:1}.dylib libzim
91+
run: |
92+
install_name_tool -change libzim.6.dylib @loader_path/libzim.6.dylib $(find build -name "wrapper*.so")
93+
cp -p lib/libzim.${LIBZIM_VERSION:0:1}.dylib libzim
9094
9195
- name: add Linux libzim binary to source for wheel
9296
if: matrix.os == 'ubuntu-latest'

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.0.3.post0
2+
3+
* fixed access to bundled libzim on macOS (missing rpath)
4+
15
## 0.0.3
26

37
* [reader] fixed `main_page` retrieval

setup.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
from setuptools import setup, Extension
3636
from Cython.Build import cythonize
37+
from Cython.Distutils.build_ext import new_build_ext as build_ext
3738

3839
GITHUB_URL = "https://github.com/openzim/python-libzim"
3940
BASE_DIR = Path(__file__).parent
@@ -42,6 +43,21 @@
4243
LIBZIM_DYLIB = 'libzim.{ext}'.format(ext='dylib' if platform.system() == 'Darwin' else 'so')
4344

4445

46+
class fixed_build_ext(build_ext):
47+
"""Workaround for rpath bug in distutils for OSX."""
48+
49+
def finalize_options(self):
50+
super().finalize_options()
51+
# Special treatment of rpath in case of OSX, to work around python
52+
# distutils bug 36353. This constructs proper rpath arguments for clang.
53+
# See https://bugs.python.org/issue36353
54+
if platform.system() == 'Darwin':
55+
for path in self.rpath:
56+
for ext in self.extensions:
57+
ext.extra_link_args.append("-Wl,-rpath," + path)
58+
self.rpath[:] = []
59+
60+
4561
# Check for the CPP Libzim library headers in expected directory
4662
if not (BASE_DIR / LIBZIM_INCLUDE_DIR / 'zim/zim.h').exists():
4763
print(
@@ -77,7 +93,7 @@ def get_long_description():
7793
setup(
7894
# Basic information about libzim module
7995
name="libzim",
80-
version="0.0.3",
96+
version="0.0.3.post0",
8197
url=GITHUB_URL,
8298
project_urls={
8399
'Source': GITHUB_URL,
@@ -96,6 +112,7 @@ def get_long_description():
96112

97113
# Content
98114
packages=["libzim"],
115+
cmdclass={'build_ext': fixed_build_ext},
99116
ext_modules=cythonize([wrapper_extension],
100117
compiler_directives={"language_level": "3"}
101118
),

0 commit comments

Comments
 (0)