Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macOS build script for arm64 wheel #34

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/macos-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

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

brew install automake libtool autoconf

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

autoreconf -i
./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 | while 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 ..

swig -Wall -c++ -python -shadow -I./kytea/src/include lib/kytea/mykytea.i
python -m cibuildwheel --archs x86_64,arm64,universal2 --output-dir wheelhouse
35 changes: 30 additions & 5 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ name: Build and upload to PyPI

on:
push:
pull_request:
release:
types:
- published

jobs:
build_wheels:
name: Build wheels for cp${{ matrix.python }}-${{ matrix.platform_id }}-${{ matrix.manylinux_image }}
name: Build wheels for cp${{ matrix.python }}-${{ matrix.platform_id }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -85,6 +84,24 @@ jobs:
python: 312
platform_id: macosx_x86_64

# macOS arm64
- os: macos-latest
bitness: 64
python: 39
platform_id: macosx_arm64
- os: macos-latest
bitness: 64
python: 310
platform_id: macosx_arm64
- os: macos-latest
bitness: 64
python: 311
platform_id: macosx_arm64
- os: macos-latest
bitness: 64
python: 312
platform_id: macosx_arm64

steps:
- uses: actions/checkout@v4
- name: Get history and tags for SCM versioning to work
Expand All @@ -109,13 +126,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 +146,16 @@ 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_PLATFORM: macos
CIBW_BUILD_VERBOSITY: 3
run: .github/workflows/macos-build.sh

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