Skip to content

Commit

Permalink
Merge pull request #63 from openzim/rgaudin/macos-load
Browse files Browse the repository at this point in the history
Rewrite runtime path lookup to libzim on macOS
  • Loading branch information
kelson42 authored Jul 3, 2020
2 parents b725cb6 + bfb21ae commit f82e388
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
echo ::set-env name=LIBZIM_RELEASE::libzim_macos-x86_64-$LIBZIM_VERSION
echo ::set-env name=LIBZIM_LIBRARY_PATH::lib/libzim.${LIBZIM_VERSION:0:1}.dylib
echo ::set-env name=PLAFTORM_NAME::macosx_10.9_x86_64
echo ::set-env name=RPATH::@loader_path/
- name: set linux environ
if: matrix.os == 'ubuntu-latest'
Expand All @@ -46,6 +47,7 @@ jobs:
echo ::set-env name=LIBZIM_RELEASE::libzim_linux-x86_64-$LIBZIM_VERSION
echo ::set-env name=LIBZIM_LIBRARY_PATH::lib/x86_64-linux-gnu/libzim.so.$LIBZIM_VERSION
echo ::set-env name=PLAFTORM_NAME::manylinux1_x86_64
echo ::set-env name=RPATH::\$ORIGIN
- name: Cache libzim dylib & headers
uses: actions/cache@master
Expand Down Expand Up @@ -78,15 +80,17 @@ jobs:
- name: Build cython, sdist, and bdist_wheels
run: |
pip install --upgrade "cython>=0.29.20,<3.0" setuptools pip wheel
python3 setup.py build_ext --rpath='$ORIGIN'
python3 setup.py build_ext --rpath $RPATH
if [[ "${{ matrix.python-version }}" == "3.6" ]]
then
python3 setup.py sdist
fi
- name: add macOS libzim binary to source for wheel
if: matrix.os == 'macos-latest'
run: cp -p lib/libzim.${LIBZIM_VERSION:0:1}.dylib libzim
run: |
install_name_tool -change libzim.6.dylib @loader_path/libzim.6.dylib $(find build -name "wrapper*.so")
cp -p lib/libzim.${LIBZIM_VERSION:0:1}.dylib libzim
- name: add Linux libzim binary to source for wheel
if: matrix.os == 'ubuntu-latest'
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.3.post0

* fixed access to bundled libzim on macOS (missing rpath)

## 0.0.3

* [reader] fixed `main_page` retrieval
Expand Down
19 changes: 18 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

from setuptools import setup, Extension
from Cython.Build import cythonize
from Cython.Distutils.build_ext import new_build_ext as build_ext

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


class fixed_build_ext(build_ext):
"""Workaround for rpath bug in distutils for OSX."""

def finalize_options(self):
super().finalize_options()
# Special treatment of rpath in case of OSX, to work around python
# distutils bug 36353. This constructs proper rpath arguments for clang.
# See https://bugs.python.org/issue36353
if platform.system() == 'Darwin':
for path in self.rpath:
for ext in self.extensions:
ext.extra_link_args.append("-Wl,-rpath," + path)
self.rpath[:] = []


# Check for the CPP Libzim library headers in expected directory
if not (BASE_DIR / LIBZIM_INCLUDE_DIR / 'zim/zim.h').exists():
print(
Expand Down Expand Up @@ -77,7 +93,7 @@ def get_long_description():
setup(
# Basic information about libzim module
name="libzim",
version="0.0.3",
version="0.0.3.post0",
url=GITHUB_URL,
project_urls={
'Source': GITHUB_URL,
Expand All @@ -96,6 +112,7 @@ def get_long_description():

# Content
packages=["libzim"],
cmdclass={'build_ext': fixed_build_ext},
ext_modules=cythonize([wrapper_extension],
compiler_directives={"language_level": "3"}
),
Expand Down

0 comments on commit f82e388

Please sign in to comment.