From 0a9672d91021cad6021d8fe1d7300495c254dfd5 Mon Sep 17 00:00:00 2001 From: Nickolay Shmyrev Date: Fri, 15 Jul 2022 00:40:38 +0200 Subject: [PATCH] Attempt to build manylinux wheel --- python/setup.py | 2 ++ travis/Dockerfile.dockcross-manylinux | 39 +++++++++++++++++++++++++++ travis/Dockerfile.manylinux | 1 + travis/build-dockcross-manylinux.sh | 7 +++++ travis/build-dockcross.sh | 6 +++-- travis/build-wheels-dockcross.sh | 2 +- 6 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 travis/Dockerfile.dockcross-manylinux create mode 100755 travis/build-dockcross-manylinux.sh diff --git a/python/setup.py b/python/setup.py index 249863e8..2330573d 100644 --- a/python/setup.py +++ b/python/setup.py @@ -32,6 +32,8 @@ def get_tag(self): oses = 'win_amd64' elif system == 'Linux' and architecture == '64bit': oses = 'linux_x86_64' + elif system == 'Linux' and architecture == 'aarch64': + oses = 'manylinux2014_aarch64' elif system == 'Linux': oses = 'linux_' + architecture else: diff --git a/travis/Dockerfile.dockcross-manylinux b/travis/Dockerfile.dockcross-manylinux new file mode 100644 index 00000000..0403a3bc --- /dev/null +++ b/travis/Dockerfile.dockcross-manylinux @@ -0,0 +1,39 @@ +ARG DOCKCROSS_IMAGE=dockcross/manylinux2014-aarch64 +FROM ${DOCKCROSS_IMAGE} + +LABEL description="A docker image for building portable Python linux binary wheels and Kaldi on other architectures" +LABEL maintainer="contact@alphacephei.com" + +RUN yum -y install \ + automake \ + autoconf \ + libtool \ + libffi-devel \ + && yum clean all + +ARG OPENBLAS_ARGS= +RUN cd /opt \ + && git clone -b vosk --single-branch https://github.com/alphacep/kaldi \ + && cd kaldi/tools \ + && git clone -b v0.3.20 --single-branch https://github.com/xianyi/OpenBLAS \ + && git clone -b v3.2.1 --single-branch https://github.com/alphacep/clapack \ + && echo ${OPENBLAS_ARGS} \ + && make -C OpenBLAS ONLY_CBLAS=1 ${OPENBLAS_ARGS} HOSTCC=gcc USE_LOCKING=1 USE_THREAD=0 all \ + && make -C OpenBLAS ${OPENBLAS_ARGS} HOSTCC=gcc USE_LOCKING=1 USE_THREAD=0 PREFIX=$(pwd)/OpenBLAS/install install \ + && mkdir -p clapack/BUILD && cd clapack/BUILD && cmake .. \ + && make -j 10 -C F2CLIBS \ + && make -j 10 -C BLAS \ + && make -j 10 -C SRC \ + && find . -name "*.a" | xargs cp -t ../../OpenBLAS/install/lib \ + && cd /opt/kaldi/tools \ + && git clone --single-branch https://github.com/alphacep/openfst openfst \ + && cd openfst \ + && autoreconf -i \ + && CFLAGS="-g -O3" ./configure --prefix=/opt/kaldi/tools/openfst --enable-static --enable-shared --enable-far --enable-ngram-fsts --enable-lookahead-fsts --with-pic --disable-bin --host=${CROSS_TRIPLE} --build=x86-linux-gnu \ + && make -j 10 && make install \ + && cd /opt/kaldi/src \ + && sed -i "s:TARGET_ARCH=\"\`uname -m\`\":TARGET_ARCH=$(echo $CROSS_TRIPLE|cut -d - -f 1):g" configure \ + && sed -i "s: -O1 : -O3 :g" makefiles/linux_openblas_arm.mk \ + && ./configure --mathlib=OPENBLAS_CLAPACK --shared --use-cuda=no \ + && make -j 10 online2 lm rnnlm \ + && find /opt/kaldi -name "*.o" -exec rm {} \; diff --git a/travis/Dockerfile.manylinux b/travis/Dockerfile.manylinux index 42ca249c..05cb474b 100644 --- a/travis/Dockerfile.manylinux +++ b/travis/Dockerfile.manylinux @@ -9,6 +9,7 @@ RUN yum -y update && yum -y install \ autoconf \ libtool \ cmake \ + libffi-devel \ && yum clean all RUN cd /opt \ diff --git a/travis/build-dockcross-manylinux.sh b/travis/build-dockcross-manylinux.sh new file mode 100755 index 00000000..5eb4f64b --- /dev/null +++ b/travis/build-dockcross-manylinux.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -e +set -x + +docker build --build-arg="DOCKCROSS_IMAGE=dockcross/manylinux2014-aarch64" --build-arg="OPENBLAS_ARGS=TARGET=ARMV8" --file Dockerfile.dockcross-manylinux --tag alphacep/kaldi-dockcross-aarch64:latest . +docker run --rm -v /home/shmyrev/travis/vosk-api/:/io alphacep/kaldi-dockcross-aarch64 /io/travis/build-wheels-dockcross.sh diff --git a/travis/build-dockcross.sh b/travis/build-dockcross.sh index 8be0af13..5ad70e36 100755 --- a/travis/build-dockcross.sh +++ b/travis/build-dockcross.sh @@ -4,11 +4,13 @@ set -e set -x docker build --build-arg="DOCKCROSS_IMAGE=alphacep/dockcross-linux-armv7" --build-arg="OPENBLAS_ARGS=TARGET=ARMV7" --file Dockerfile.dockcross --tag alphacep/kaldi-dockcross-armv7:latest . -docker build --build-arg="DOCKCROSS_IMAGE=dockcross/linux-arm64" --build-arg="OPENBLAS_ARGS=TARGET=ARMV8" --file Dockerfile.dockcross --tag alphacep/kaldi-dockcross-arm64:latest . docker build --build-arg="DOCKCROSS_IMAGE=dockcross/linux-x86" --build-arg="OPENBLAS_ARGS=TARGET=CORE2\ DYNAMIC_ARCH=1" --file Dockerfile.dockcross --tag alphacep/kaldi-dockcross-x86:latest . docker build --build-arg="DOCKCROSS_IMAGE=dockcross/linux-riscv64" --build-arg="OPENBLAS_ARGS=TARGET=RISCV64_GENERIC\ ARCH=riscv64" --file Dockerfile.dockcross --tag alphacep/kaldi-dockcross-riscv:latest . docker run --rm -v /home/shmyrev/travis/vosk-api/:/io alphacep/kaldi-dockcross-armv7 /io/travis/build-wheels-dockcross.sh -docker run --rm -v /home/shmyrev/travis/vosk-api/:/io alphacep/kaldi-dockcross-arm64 /io/travis/build-wheels-dockcross.sh docker run --rm -v /home/shmyrev/travis/vosk-api/:/io alphacep/kaldi-dockcross-x86 /io/travis/build-wheels-dockcross.sh docker run --rm -v /home/shmyrev/travis/vosk-api/:/io alphacep/kaldi-dockcross-riscv /io/travis/build-wheels-dockcross.sh + +# We use manylinux (Centos-based image) for aarch64 instead +# docker build --build-arg="DOCKCROSS_IMAGE=dockcross/linux-arm64" --build-arg="OPENBLAS_ARGS=TARGET=ARMV8" --file Dockerfile.dockcross --tag alphacep/kaldi-dockcross-arm64:latest . +# docker run --rm -v /home/shmyrev/travis/vosk-api/:/io alphacep/kaldi-dockcross-arm64 /io/travis/build-wheels-dockcross.sh diff --git a/travis/build-wheels-dockcross.sh b/travis/build-wheels-dockcross.sh index 118dd928..6f27a661 100755 --- a/travis/build-wheels-dockcross.sh +++ b/travis/build-wheels-dockcross.sh @@ -29,5 +29,5 @@ mkdir -p /io/wheelhouse/vosk-linux-$VOSK_ARCHITECTURE cp /opt/vosk-api/src/*.so /opt/vosk-api/src/vosk_api.h /io/wheelhouse/vosk-linux-$VOSK_ARCHITECTURE # Build wheel -python3 -m pip install requests tqdm srt +python3 -m pip install requests tqdm srt wheel python3 -m pip wheel /opt/vosk-api/python --no-deps -w /io/wheelhouse