Skip to content

Commit

Permalink
Add macOS build script for wheel
Browse files Browse the repository at this point in the history
This is based on @nikitalita's script on fugashi's repo.
See details in polm/fugashi#80
  • Loading branch information
chezou committed Jan 14, 2024
1 parent 25df000 commit 02ec939
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/macos-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

X86_TRIPLET=x86_64-apple-macos10.9
ARM_TRIPLET=arm64-apple-macos11

git clone --depth=1 https://github.com/neubig/kytea.git
cd kytea

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

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

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

mv src/lib/.libs src/lib/.libs-arm64

./configure --host="x86_64-apple-darwin20.6.0" CXX="clang++ -target $X86_TRIPLET" CC="clang -target $X86_TRIPLET"

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

mv src/lib/.libs src/lib/.libs-x86_64

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

lipo -create src/lib/.libs-arm64/libkytea.0.dylib src/lib/.libs-x86_64/libkytea.0.dylib -output src/lib/.libs.combined/libkytea.0.dylib

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

cp src/lib/.libs-arm64/libkytea.lai src/lib/.libs.combined/libkytea.lai

ls -l src/lib/.libs-arm64/*.o | wihle read line; do
file=$(basename $file)
echo $file
lipo -create src/lib/.libs-arm64/$file src/lib/.libs-x86_64/$file -output src/lib/.libs.combined/$file
done

cd src/lib/.libs.combined
ln -s libkytea.0.dylib libkytea.dylib
ln -s ../libkytea.a libkytea.a
cd ../../..
mv src/lib/.libs.combined src/lib/.libs

sudo make install
cd ..

python -m cibuildwheel --output-dir wheelhouse
16 changes: 12 additions & 4 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Build and upload to PyPI

on:
push:
pull_request:
release:
types:
- published
Expand Down Expand Up @@ -109,13 +108,11 @@ jobs:
cp kytea\lib\libkytea.lib lib\kytea\
- name: Build wheels
if: runner.os != 'macOS'
env:
CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }}
CIBW_ARCHS: all
CIBW_BUILD_VERBOSITY: 3
CIBW_REPAIR_WHEEL_COMMAND_MACOS: >
delocate-listdeps {wheel} &&
delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}
CIBW_BEFORE_ALL_LINUX: >
yum install -y wget &&
wget http://www.phontron.com/kytea/download/kytea-0.4.7.tar.gz &&
Expand All @@ -131,6 +128,17 @@ jobs:
brew install kytea &&
swig -Wall -c++ -python -shadow -I$(brew --prefix)/include lib/kytea/mykytea.i
run: python -m cibuildwheel --output-dir wheelhouse
- name: Build wheels if macOS
if: runner.os == 'macOS'
env:
CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }}
CIBW_REPAIR_WHEEL_COMMAND_MACOS: >
delocate-listdeps {wheel} &&
delocate-wheel --require-archs {delocate_archs} -w {dest_dir} -v {wheel}
CIBW_ARCHS: x86_64,arm64,universal2
CIBW_PLATFORM: macos
CIBW_BUILD_VERBOSITY: 3
run: .github/workflows/macos-build.sh

- uses: actions/upload-artifact@v4
with:
Expand Down

0 comments on commit 02ec939

Please sign in to comment.