Skip to content

Commit

Permalink
add github-workflow building wheels
Browse files Browse the repository at this point in the history
  • Loading branch information
betaboon committed Apr 13, 2023
1 parent e184c62 commit 4f47f77
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Build

on:
push:
tags:
- "v*.*.*"

workflow_dispatch:

jobs:
build_wheels:
name: Build wheel for ${{ matrix.config.platform }} ${{ matrix.config.arch }}

runs-on: ${{ matrix.config.os }}
strategy:
matrix:
config:
- { os: ubuntu-22.04, platform: manylinux, arch: x86_64 }
- { os: ubuntu-22.04, platform: musllinux, arch: x86_64 }
- { os: macos-12, platform: macosx, arch: x86_64 }
- { os: macos-12, platform: macosx, arch: arm64 }

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Build wheel
uses: pypa/cibuildwheel@v2.12.1
env:
CIBW_ARCHS: "${{ matrix.config.arch }}"
CIBW_BUILD: "cp*-${{ matrix.config.platform }}_${{ matrix.config.arch }}"
CIBW_SKIP: "cp36* cp37*"

- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl

build_sdist:
name: Build sdist
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.8"

- name: Build sdist
run: python setup.py sdist

- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
path: ./dist/*
15 changes: 15 additions & 0 deletions build-scripts/common-install-tesseract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -ex

LEPTONICA_VERSION="1.83.1"
TESSERACT_VERSION="5.3.1"

PREFIX="${PREFIX:-/usr/local}"

curl -L -O "https://github.com/DanBloomberg/leptonica/releases/download/${LEPTONICA_VERSION}/leptonica-${LEPTONICA_VERSION}.tar.gz"

tar -xzf leptonica-${LEPTONICA_VERSION}.tar.gz

curl -L -o "tesseract-${TESSERACT_VERSION}.tar.gz" "https://github.com/tesseract-ocr/tesseract/archive/refs/tags/${TESSERACT_VERSION}.tar.gz"

tar -xzf tesseract-${TESSERACT_VERSION}.tar.gz
37 changes: 37 additions & 0 deletions build-scripts/linux-install-tesseract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
set -ex

source $(dirname -- "$0")/common-install-tesseract.sh

# build leptonica
cd leptonica-${LEPTONICA_VERSION}

cmake \
-B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="${PREFIX}" \
-DBUILD_SHARED_LIBS=ON

cmake \
--build build \
--config Release \
--target install

cd ..

# build tesseract
cd tesseract-${TESSERACT_VERSION}

cmake \
-B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="${PREFIX}" \
-DBUILD_SHARED_LIBS=ON \
-DOPENMP_BUILD=OFF

cmake \
--build build \
--config Release \
--target install

cd ..
19 changes: 19 additions & 0 deletions build-scripts/macos-install-build-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -ex

# leptonica dependencies
brew install \
giflib \
jpeg-turbo \
libpng \
libtiff \
openjpeg \
webp \
zlib

# tesseract dependencies
brew install \
pango \
cairo \
icu4c
brew link icu4c
44 changes: 44 additions & 0 deletions build-scripts/macos-install-tesseract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
set -ex

source $(dirname -- "$0")/common-install-tesseract.sh

# build leptonica
cd leptonica-${LEPTONICA_VERSION}

cmake \
-B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="${PREFIX}" \
-DCMAKE_OSX_DEPLOYMENT_TARGET="12.0" \
-DCMAKE_FIND_FRAMEWORK=NEVER \
-DBUILD_SHARED_LIBS=ON

cmake \
--build build \
--config Release \
--target install

cd ..

# build tesseract
# see https://github.com/orgs/Homebrew/discussions/4031#discussioncomment-4348867
export PKG_CONFIG_PATH=$(brew --prefix)/opt/icu4c/lib/pkgconfig:$PKG_CONFIG_PATH

cd tesseract-${TESSERACT_VERSION}

cmake \
-B build \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="${PREFIX}" \
-DCMAKE_OSX_DEPLOYMENT_TARGET="12.0" \
-DCMAKE_FIND_FRAMEWORK=NEVER \
-DBUILD_SHARED_LIBS=ON \
-DOPENMP_BUILD=OFF

cmake \
--build build \
--config Release \
--target install

cd ..
18 changes: 18 additions & 0 deletions build-scripts/manylinux-install-build-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -ex

# leptonica dependencies
yum install -y \
giflib-devel \
libjpeg-devel \
libpng-devel \
libtiff-devel \
libwebp-devel \
openjpeg2-devel \
zlib-devel

# tesseract dependencies
yum install -y \
cairo-devel \
libicu-devel \
pango-devel
19 changes: 19 additions & 0 deletions build-scripts/musllinux-install-build-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -ex

# leptonica dependencies
apk add \
giflib-dev\
libjpeg-turbo-dev\
libpng-dev\
libwebp-dev\
openjpeg-dev\
openjpeg-tools\
tiff-dev\
zlib-dev

# tesseract dependencies
apk add \
cairo-dev \
icu-dev \
pango-dev
24 changes: 24 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[tool.cibuildwheel]
build-verbosity = "1"

manylinux-x86_64-image = "manylinux_2_28"
manylinux-aarch64-image = "manylinux_2_28"

[tool.cibuildwheel.linux]
before-all = [
"bash build-scripts/manylinux-install-build-dependencies.sh",
"bash build-scripts/linux-install-tesseract.sh",
]

[[tool.cibuildwheel.overrides]]
select = "*-musllinux*"
before-all = [
"bash build-scripts/musllinux-install-build-dependencies.sh",
"bash build-scripts/linux-install-tesseract.sh",
]

[tool.cibuildwheel.macos]
before-all = [
"bash build-scripts/macos-install-build-dependencies.sh",
"bash build-scripts/macos-install-tesseract.sh",
]

0 comments on commit 4f47f77

Please sign in to comment.