From 0f9149511a75862f74b4e0f2f0f9442d933ff880 Mon Sep 17 00:00:00 2001 From: Aki Ariga Date: Sun, 14 Jan 2024 15:35:51 -0800 Subject: [PATCH] Add macOS build script for wheel This is based on @nikitalita's script on fugashi's repo. See details in https://github.com/polm/fugashi/pull/80 --- .github/workflows/macos-build.sh | 53 ++++++++++++++++++++++++++++++++ .github/workflows/wheels.yml | 35 ++++++++++++++++++--- 2 files changed, 83 insertions(+), 5 deletions(-) create mode 100755 .github/workflows/macos-build.sh diff --git a/.github/workflows/macos-build.sh b/.github/workflows/macos-build.sh new file mode 100755 index 0000000..862f0b0 --- /dev/null +++ b/.github/workflows/macos-build.sh @@ -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 diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 298bc9e..c1d9916 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -2,7 +2,6 @@ name: Build and upload to PyPI on: push: - pull_request: release: types: - published @@ -72,7 +71,7 @@ jobs: bitness: 64 python: 39 platform_id: macosx_x86_64 - - os: macos-latest + - os: macos-latest bitness: 64 python: 310 platform_id: macosx_x86_64 @@ -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 @@ -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 && @@ -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: