Skip to content

Commit 334c0e0

Browse files
authored
Merge pull request #35 from openzim/macos
build and test on macOS
2 parents 47fa5ae + dcbce16 commit 334c0e0

File tree

5 files changed

+99
-35
lines changed

5 files changed

+99
-35
lines changed

.github/workflows/release.yml

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ on:
66
- v*
77

88
env:
9-
LIBZIM_RELEASE: libzim_linux-x86_64-6.1.5
9+
LIBZIM_VERSION: 6.1.6
1010
LIBZIM_INCLUDE_PATH: include/zim
1111
CYTHON_VERSION: 0.29.6
12+
TWINE_USERNAME: __token__
13+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
14+
# TWINE_REPOSITORY_URL: https://test.pypi.org/legacy/
1215

1316
jobs:
1417
release:
1518
runs-on: ${{ matrix.os }}
1619
strategy:
1720
matrix:
18-
os: [ubuntu-latest]
21+
os: [ubuntu-latest, macos-latest]
1922
# TODO: expand this to cross-platform builds (see V2 approach below)
2023
# os: [ubuntu-latest, windows-latest, macos-latest]
2124
python-version: [3.6, 3.7, 3.8]
@@ -29,25 +32,49 @@ jobs:
2932
python-version: ${{ matrix.python-version }}
3033
architecture: x64
3134

35+
- name: set macOS environ
36+
if: matrix.os == 'macos-latest'
37+
run: |
38+
echo ::set-env name=LIBZIM_EXT::dylib
39+
echo ::set-env name=LIBZIM_RELEASE::libzim_macos-x86_64-$LIBZIM_VERSION
40+
echo ::set-env name=LIBZIM_LIBRARY_PATH::lib/libzim.${LIBZIM_VERSION:0:1}.dylib
41+
echo ::set-env name=PLAFTORM_NAME::macosx_10.9_x86_64
42+
43+
- name: set linux environ
44+
if: matrix.os == 'ubuntu-latest'
45+
run: |
46+
echo ::set-env name=LIBZIM_EXT::so
47+
echo ::set-env name=LIBZIM_RELEASE::libzim_linux-x86_64-$LIBZIM_VERSION
48+
echo ::set-env name=LIBZIM_LIBRARY_PATH::lib/x86_64-linux-gnu/libzim.so.$LIBZIM_VERSION
49+
echo ::set-env name=PLAFTORM_NAME::manylinux1_x86_64
50+
3251
- name: Cache libzim dylib & headers
3352
uses: actions/cache@master
3453
id: cache-libzim
3554
with:
36-
path: libzim_linux
55+
path: libzim_dist
3756
key: ${{ env.LIBZIM_RELEASE }}-libzim-cache
3857

3958
- name: Download libzim dylib & headers from OpenZIM.org releases
4059
if: steps.cache-libzim.outputs.cache-hit != 'true'
4160
run: |
4261
wget -q https://download.openzim.org/release/libzim/$LIBZIM_RELEASE.tar.gz
4362
tar --gunzip --extract --file=$LIBZIM_RELEASE.tar.gz
44-
mv $LIBZIM_RELEASE libzim_linux
63+
mv $LIBZIM_RELEASE libzim_dist
4564
46-
- name: Link libzim dylib & headers into workspace lib and include folders
65+
- name: Link Linux libzim dylib & headers into workspace lib and include folders
66+
if: matrix.os == 'ubuntu-latest'
4767
run: |
48-
cp -dp $GITHUB_WORKSPACE/libzim_linux/lib/x86_64-linux-gnu/* lib/
49-
ln -s libzim.so.6 lib/libzim.so
50-
ln -s $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_INCLUDE_PATH include/zim
68+
cp -dp $GITHUB_WORKSPACE/libzim_dist/lib/x86_64-linux-gnu/* lib/
69+
ln -s libzim.so.${LIBZIM_VERSION:0:1} lib/libzim.so
70+
ln -s $GITHUB_WORKSPACE/libzim_dist/$LIBZIM_INCLUDE_PATH include/zim
71+
72+
- name: Link macOS libzim dylib & headers into workspace lib and include folders
73+
if: matrix.os == 'macos-latest'
74+
run: |
75+
cp -Pp $GITHUB_WORKSPACE/libzim_dist/lib/* lib/
76+
ln -sf libzim.${LIBZIM_VERSION:0:1}.dylib lib/libzim.dylib
77+
ln -s $GITHUB_WORKSPACE/libzim_dist/$LIBZIM_INCLUDE_PATH include/zim
5178
5279
- name: Build cython, sdist, and bdist_wheels
5380
run: |
@@ -57,8 +84,17 @@ jobs:
5784
then
5885
python3 setup.py sdist
5986
fi
60-
cp -p lib/libzim.so.6 libzim
61-
python3 setup.py bdist_wheel --plat-name=manylinux1_x86_64
87+
88+
- name: add macOS libzim binary to source for wheel
89+
if: matrix.os == 'macos-latest'
90+
run: cp -p lib/libzim.${LIBZIM_VERSION:0:1}.dylib libzim
91+
92+
- name: add Linux libzim binary to source for wheel
93+
if: matrix.os == 'ubuntu-latest'
94+
run: cp -p lib/libzim.so.${LIBZIM_VERSION:0:1} libzim
95+
96+
- name: build wheel
97+
run: python3 setup.py bdist_wheel --plat-name=$PLAFTORM_NAME
6298

6399
- uses: actions/upload-artifact@v1
64100
with:
@@ -67,7 +103,11 @@ jobs:
67103

68104
- name: Push release to PyPI
69105
if: github.event_name == 'release'
70-
uses: pypa/gh-action-pypi-publish@master
71-
with:
72-
user: __token__
73-
password: ${{ secrets.PYPI_API_TOKEN }}
106+
run: |
107+
pip install --upgrade twine
108+
twine check dist/*
109+
if [ "${{ matrix.os }}" == "ubuntu-latest" -a "${{ matrix.python-version }}" = "3.6" ]
110+
then
111+
twine upload dist/*.tar.gz
112+
fi
113+
twine upload dist/*.whl

.github/workflows/test.yml

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ name: test
22
on: [push]
33

44
env:
5-
LIBZIM_RELEASE: libzim_linux-x86_64-6.1.5
6-
LIBZIM_LIBRARY_PATH: lib/x86_64-linux-gnu/libzim.so.6.1.5
5+
LIBZIM_VERSION: 6.1.6
76
LIBZIM_INCLUDE_PATH: include/zim
87
CYTHON_VERSION: 0.29.6
98
MAX_LINE_LENGTH: 110
@@ -37,7 +36,7 @@ jobs:
3736
runs-on: ${{ matrix.os }}
3837
strategy:
3938
matrix:
40-
os: [ubuntu-latest]
39+
os: [ubuntu-latest, macos-latest]
4140
# TODO: expand this once macos and windows libzim releases become available
4241
# os: [ubuntu-latest, windows-latest, macos-latest]
4342
# alternatively we can compile libzim in docker and use the container as an action
@@ -52,37 +51,60 @@ jobs:
5251
python-version: ${{ matrix.python }}
5352
architecture: x64
5453

54+
- name: set macOS environ
55+
if: matrix.os == 'macos-latest'
56+
run: |
57+
echo ::set-env name=LIBZIM_EXT::dylib
58+
echo ::set-env name=LIBZIM_RELEASE::libzim_macos-x86_64-$LIBZIM_VERSION
59+
echo ::set-env name=LIBZIM_LIBRARY_PATH::lib/libzim.${LIBZIM_VERSION:0:1}.dylib
60+
61+
- name: set linux environ
62+
if: matrix.os == 'ubuntu-latest'
63+
run: |
64+
echo ::set-env name=LIBZIM_EXT::so
65+
echo ::set-env name=LIBZIM_RELEASE::libzim_linux-x86_64-$LIBZIM_VERSION
66+
echo ::set-env name=LIBZIM_LIBRARY_PATH::lib/x86_64-linux-gnu/libzim.so.$LIBZIM_VERSION
67+
5568
- name: Cache libzim dylib & headers
5669
uses: actions/cache@master
5770
id: cache-libzim
5871
with:
59-
path: libzim_linux
72+
path: libzim_dist
6073
key: ${{ env.LIBZIM_RELEASE }}-libzim-cache
6174

6275
- name: Download libzim dylib & headers from OpenZIM.org releases
6376
if: steps.cache-libzim.outputs.cache-hit != 'true'
6477
run: |
6578
wget -q https://download.openzim.org/release/libzim/$LIBZIM_RELEASE.tar.gz
6679
tar --gunzip --extract --file=$LIBZIM_RELEASE.tar.gz
67-
mv $LIBZIM_RELEASE libzim_linux
80+
mv $LIBZIM_RELEASE libzim_dist
6881
6982
- name: Link libzim dylib & headers into workspace lib and include folders
7083
run: |
71-
cp -p $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_LIBRARY_PATH lib/libzim.so
72-
cp -p $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_LIBRARY_PATH lib/
73-
sudo ldconfig $GITHUB_WORKSPACE/lib
74-
ln -s $GITHUB_WORKSPACE/libzim_linux/$LIBZIM_INCLUDE_PATH include/zim
75-
84+
cp -p $GITHUB_WORKSPACE/libzim_dist/$LIBZIM_LIBRARY_PATH lib/libzim.$LIBZIM_EXT
85+
cp -p $GITHUB_WORKSPACE/libzim_dist/$LIBZIM_LIBRARY_PATH lib/
86+
ln -s $GITHUB_WORKSPACE/libzim_dist/$LIBZIM_INCLUDE_PATH include/zim
87+
export LD_LIBRARY_PATH="$PWD/lib:$LD_LIBRARY_PATH"
88+
89+
- name: update Linux shared objects cache
90+
if: matrix.os == 'ubuntu-latest'
91+
run: |
92+
sudo ldconfig $PWD/lib
93+
94+
- name: update macOS shared objects cache
95+
if: matrix.os == 'macos-latest'
96+
run: |
97+
export DYLD_LIBRARY_PATH="$PWD/lib:$DYLD_LIBRARY_PATH"
98+
7699
- name: Build cython, sdist, and bdist_wheel
77100
run: |
78101
pip install --upgrade cython==$CYTHON_VERSION setuptools pip wheel
79102
python3 setup.py build_ext
80103
python3 setup.py sdist bdist_wheel
81-
104+
82105
- name: Test built package with pytest
83106
run: |
84-
export LD_LIBRARY_PATH=$PWD/lib:$LD_LIBRARY_PATH
85-
sudo ldconfig
86107
pip install pytest
87108
pip install -e .
109+
export DYLD_LIBRARY_PATH="$PWD/lib:$DYLD_LIBRARY_PATH"
88110
pytest .

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ See [example](examples/basic_writer.py) for a basic usage of the writer API.
4242

4343
## User Documentation
4444

45-
### Setup: Ubuntu/Debian `x86_64` (Recommended)
45+
### Setup: Ubuntu/Debian and macOS `x86_64` (Recommended)
4646

4747
Install the python `libzim` package from PyPI.
4848

4949
```bash
5050
pip3 install libzim
5151
```
5252

53-
The `x86_64` linux wheel automatically includes the `libzim.so` dylib and headers, but other platforms may need to install `libzim` and its headers manually.
53+
The `x86_64` linux and macOS wheels automatically includes the `libzim.(so|dylib)` dylib and headers, but other platforms may need to install `libzim` and its headers manually.
5454

5555

5656
### Installing the `libzim` dylib and headers manually
5757

58-
If you are not on a linux `x86_64` platform, you will have to install libzim manually.
58+
If you are not on a linux or macOS `x86_64` platform, you will have to install libzim manually.
5959

6060
Either by get a prebuilt binary at https://download.openzim.org/release/libzim
6161
or [compile `libzim` from source](https://github.com/openzim/libzim).

lib/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Put your libzim.so file in here.
1+
Put your libzim.(so|dylib) file in here.

setup.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
$ export LDFLAGS="-L/tmp/libzim_linux-x86_64-6.1.1/lib/x86_64-linux-gnu"
2929
$ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/tmp/libzim_linux-x86_64-6.1.1/lib/x86_64-linux-gnu"
3030
"""
31+
import platform
3132
from pathlib import Path
3233
from ctypes.util import find_library
3334

@@ -38,6 +39,7 @@
3839
BASE_DIR = Path(__file__).parent
3940
LIBZIM_INCLUDE_DIR = 'include' # the libzim C++ header src dir (containing zim/*.h)
4041
LIBZIM_LIBRARY_DIR = 'lib' # the libzim .so binary lib dir (containing libzim.so)
42+
LIBZIM_DYLIB = 'libzim.{ext}'.format(ext='dylib' if platform.system() == 'Darwin' else 'so')
4143

4244

4345
# Check for the CPP Libzim library headers in expected directory
@@ -50,12 +52,12 @@
5052
)
5153

5254
# Check for the CPP Libzim shared library in expected directory or system paths
53-
if not ((BASE_DIR / LIBZIM_LIBRARY_DIR / 'libzim.so').exists() or find_library('zim')):
55+
if not ((BASE_DIR / LIBZIM_LIBRARY_DIR / LIBZIM_DYLIB).exists() or find_library('zim')):
5456
print(
55-
f"[!] Warning: Couldn't find libzim.so in ./{LIBZIM_LIBRARY_DIR} or system library paths!"
57+
f"[!] Warning: Couldn't find {LIBZIM_DYLIB} in ./{LIBZIM_LIBRARY_DIR} or system library paths!"
5658
f" Hint: You can install it from source from https://github.com/openzim/libzim\n"
57-
f" or download a prebuilt zimlib.so release into ./lib.\n"
58-
f" (or set LDFLAGS='-L<library_path>/lib/x86_64-linux-gnu')"
59+
f" or download a prebuilt {LIBZIM_DYLIB} release into ./lib.\n"
60+
f" (or set LDFLAGS='-L<library_path>/lib/[x86_64-linux-gnu]')"
5961
)
6062

6163
def get_long_description():

0 commit comments

Comments
 (0)