Skip to content

Commit

Permalink
Merge branch 'feature/mac-m1-builds'
Browse files Browse the repository at this point in the history
  • Loading branch information
polm committed Sep 22, 2023
2 parents d42e1e1 + 81b7445 commit 0eeb809
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 62 deletions.
58 changes: 58 additions & 0 deletions .github/macos-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
set -eou pipefail

FLAGS="--enable-utf8-only"
X86_TRIPLET=x86_64-apple-macos10.9
ARM_TRIPLET=arm64-apple-macos11


git clone --depth=1 https://github.com/taku910/mecab.git
cd mecab/mecab

rm -rf src/.libs-arm64 src/.libs-x86_64 src/.libs.combined

./configure $FLAGS --host="arm-apple-darwin22.1.0 " CXX="clang++ -target $ARM_TRIPLET" CC="clang"

make clean
# nproc doesnt exist on the runner
make -j$(sysctl -n hw.logicalcpu_max)

mv src/.libs src/.libs-arm64

./configure $FLAGS --host="x86_64-apple-darwin22.1.0 " CXX="clang++ -target $X86_TRIPLET" CC="clang"

make clean
make -j$(sysctl -n hw.logicalcpu_max)

mv src/.libs src/.libs-x86_64

rm -rf src/.libs.combined
mkdir src/.libs.combined

# lipo is an osx utility to create universal binaries
lipo -create src/.libs-arm64/libmecab.2.dylib src/.libs-x86_64/libmecab.2.dylib -output src/.libs.combined/libmecab.2.dylib

lipo -create src/.libs-arm64/libmecab.a src/.libs-x86_64/libmecab.a -output src/.libs.combined/libmecab.a

cp src/.libs-arm64/libmecab.lai src/.libs.combined/libmecab.lai

ls src/.libs-arm64/*.o src/.libs-arm64/mecab* | while read line; do
echo $line
lipo -create $line src/.libs-x86_64/$(basename $line) -output src/.libs.combined/$(basename $line)
done

cd src/.libs.combined
ln -s ../libmecab.la libmecab.la
ln -s libmecab.2.dylib libmecab.dylib
cd ../..
mv src/.libs.combined src/.libs

sudo make install
cd ../..

python -m pip install --upgrade setuptools wheel pip setuptools-scm
python -m pip install cibuildwheel==2.14.1

# don't bother with pypy wheels
export CIBW_SKIP="pp*"
python -m cibuildwheel --platform macos --archs x86_64,arm64,universal2 --output-dir dist
57 changes: 2 additions & 55 deletions .github/workflows/osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,21 @@ on: [push]
jobs:
build_osx:
runs-on: macos-latest
strategy:
max-parallel: 5
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11"]
include:
- python-version: 3.6
py-short: 36
py-short2: 36m
- python-version: 3.7
py-short: 37
py-short2: 37m
- python-version: 3.8
py-short: 38
py-short2: 38
- python-version: 3.9
py-short: 39
py-short2: 39
- python-version: "3.10"
py-short: 310
py-short2: 310
- python-version: "3.11"
py-short: 311
py-short2: 311

steps:
- uses: actions/checkout@v3
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: x64
python-version: '3.x'
- name: Download and build MeCab
shell: bash
run: |
git clone --depth=1 https://github.com/taku910/mecab.git
cd mecab/mecab
./configure --enable-utf8-only
make
sudo make install
cd ../..
python -m pip install --upgrade setuptools wheel pip setuptools-scm
python setup.py bdist_wheel
# Fix the wheel #18
pip install delocate
VERSION=$(python setup.py --version)
path_to_wheel=$(find -f dist/mecab_python3-${VERSION}-cp${{ matrix.py-short }}-cp${{ matrix.py-short2 }}-macosx*.whl)
# Unzip the wheel and copy the dylib
mkdir tmp; cd tmp
unzip ../$path_to_wheel
delocate-path -L mecab-python3.dylibs .
# Zip the wheel
zip -r -D ../$path_to_wheel *
cd -; rm -rf tmp
# Check if libmecab.2.dylib is included
unzip -t $path_to_wheel
.github/macos-build.sh
- name: Upload Wheels
uses: actions/upload-artifact@v1
with:
name: osx-wheels
path: dist
- name: Check wheels
shell: bash
run: |
ls -la dist
VERSION=$(python setup.py --version)
pip install dist/mecab_python3-${VERSION}-cp${{ matrix.py-short }}-cp${{ matrix.py-short2 }}-macosx*.whl
- name: Publish to PyPI if tagged
if: startsWith(github.ref, 'refs/tags') && github.repository_owner == 'polm'
env:
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11"]
python-version: [3.8, 3.9, "3.10", "3.11"]
include:
- python-version: 3.6
py-short: 36
py-short2: 36m
- python-version: 3.7
py-short: 37
py-short2: 37m
- python-version: 3.8
py-short: 38
py-short2: 38
Expand Down

0 comments on commit 0eeb809

Please sign in to comment.