Skip to content

Build kaldi on ubuntu & macOS #123

Build kaldi on ubuntu & macOS

Build kaldi on ubuntu & macOS #123

Workflow file for this run

name: Build kaldi on ubuntu & macOS
on: [push, pull_request, workflow_dispatch]
jobs:
build:
name: "Build kaldi"
strategy:
fail-fast: false
matrix:
target: [macos12, macos13, macos14, ubuntu20, ubuntu22]
include:
- target: macos12
os: macos-12
install_dir: /usr/local/opt
pkgconfig_dir: /usr/local/lib/pkgconfig
- target: macos13
os: macos-13
install_dir: /usr/local/opt
pkgconfig_dir: /usr/local/lib/pkgconfig
- target: macos14
os: macos-14
install_dir: /usr/local/opt
pkgconfig_dir: /usr/local/lib/pkgconfig
- target: ubuntu20
os: ubuntu-20.04
install_dir: /opt
pkgconfig_dir: /usr/lib/pkgconfig
- target: ubuntu22
os: ubuntu-22.04
install_dir: /opt
pkgconfig_dir: /usr/lib/pkgconfig
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Install MacPorts on macos
if: startsWith(matrix.os, 'macos')
uses: melusina-org/setup-macports@v1
- name: Install dependencies on macos
if: startsWith(matrix.os, 'macos')
shell: bash
run: |
brew update
brew install gawk automake subversion sox libtool
brew reinstall gcc
port install python27
- name: Install dependencies on ubuntu
if: startsWith(matrix.os, 'ubuntu')
shell: bash
run: |
sudo apt-get update -y --allow-releaseinfo-change
sudo apt-get install --no-install-recommends -y subversion gawk python2.7 python3 automake autoconf git sox gfortran libtool
sudo update-ca-certificates
- name: Install MKL
if: startsWith(matrix.os, 'ubuntu')
shell: bash
run: |
sudo bash tools/extras/install_mkl.sh
- name: Move source code to ${{ matrix.install_dir }}
shell: bash
run: |
sudo mkdir -p ${{ matrix.install_dir }}
cd .. && sudo mv kaldi ${{ matrix.install_dir }}/kaldi && sudo ln -s ${{ matrix.install_dir }}/kaldi kaldi
- id: get-openfst-version
name: Determine OpenFST version
shell: bash
run: |
OPENFST_VERSION=`grep -E '^OPENFST_VERSION \?= ' tools/Makefile | sed -e 's|OPENFST_VERSION ?= ||g'`
echo "::set-output name=OPENFST_VERSION::${OPENFST_VERSION}"
- name: Compile OpenFST
shell: bash
env:
OPENFST_VERSION: ${{ steps.get-openfst-version.outputs.OPENFST_VERSION }}
run: |
cd ${{ matrix.install_dir }}/kaldi/tools
OPENFST_CONFIGURE="--enable-shared --with-pic --disable-bin" make openfst_compiled -j 4
ln -sf openfst-${OPENFST_VERSION} openfst
- name: Build tools
shell: bash
run: |
cd ${{ matrix.install_dir }}/kaldi/tools
bash extras/check_dependencies.sh
make cub sctk_made sph2pipe -j 4
- name: Configure kaldi on macos
if: startsWith(matrix.os, 'macos')
shell: bash
env:
OPENFST_VERSION: ${{ steps.get-openfst-version.outputs.OPENFST_VERSION }}
run: |
cd ${{ matrix.install_dir }}/kaldi/src
OPENFST_VER=${OPENFST_VERSION} ./configure --shared
- name: Configure kaldi on ubuntu
if: startsWith(matrix.os, 'ubuntu')
shell: bash
env:
OPENFST_VERSION: ${{ steps.get-openfst-version.outputs.OPENFST_VERSION }}
run: |
cd ${{ matrix.install_dir }}/kaldi/src
OPENFST_VER=${OPENFST_VERSION} ./configure --shared --mathlib=MKL
- name: Make depend
shell: bash
run: |
cd ${{ matrix.install_dir }}/kaldi/src
make depend -j 4
- name: Build kaldi
shell: bash
run: |
cd ${{ matrix.install_dir }}/kaldi/src
make -j 4
- name: Prepare tarball on macos
if: startsWith(matrix.os, 'macos')
shell: bash
run: |
cd ${{ matrix.install_dir }}/kaldi
VERSION=`sw_vers | grep ProductVersion | awk '{ print $2 }'`
echo "$VERSION-`uname -m`" > release_name
- name: Prepare tarball on ubuntu
if: startsWith(matrix.os, 'ubuntu')
shell: bash
run: |
cd ${{ matrix.install_dir }}/kaldi
. /etc/os-release && echo "$ID$VERSION_ID-`uname -m`" > release_name
- name: Define the release name
id: get-release
run: |
if [ ${GITHUB_REF/refs\/tags\//} != ${GITHUB_REF} ]; then
echo ::set-output name=RELEASE::${GITHUB_REF/refs\/tags\//}
elif [ ${GITHUB_REF/refs\/heads\//} != "${GITHUB_REF}" ]; then
echo ::set-output name=RELEASE::${GITHUB_REF/refs\/heads\//}-`echo ${GITHUB_SHA} | cut -c1-8`
else
echo ::set-output name=RELEASE::${GITHUB_REF//\//-}-`echo ${GITHUB_SHA} | cut -c1-8`
fi
- name: Create tarballs with files
id: create-tarballs
shell: bash
env:
RELEASE: ${{ steps.get-release.outputs.RELEASE }}
OPENFST_VERSION: ${{ steps.get-openfst-version.outputs.OPENFST_VERSION }}
run: |
cd ${{ matrix.install_dir }}/kaldi
mkdir -p dist${{ matrix.install_dir }}/kaldi
cp -a {INSTALL,README.md,COPYING,src} dist${{ matrix.install_dir }}/kaldi/
if [ -e tools/OpenBLAS/install ] ; then
mkdir -p dist${{ matrix.install_dir }}/kaldi/tools/OpenBLAS/
cp -a tools/OpenBLAS/install dist${{ matrix.install_dir }}/kaldi/tools/OpenBLAS/
fi
cp -a tools/openfst-${OPENFST_VERSION} dist${{ matrix.install_dir }}/kaldi/tools/openfst-${OPENFST_VERSION}
cp -a tools/openfst dist${{ matrix.install_dir }}/kaldi/tools/openfst
if [ `uname` = "Linux" ]; then
find dist${{ matrix.install_dir }}/kaldi -regextype posix-extended -type f ! -regex '.*\.(h|so.*)' -delete
else
find -E dist${{ matrix.install_dir }}/kaldi -type f ! -regex '.*\.(h|.*dylib)' -delete
fi
find dist${{ matrix.install_dir }}/kaldi -type d -empty -delete
if [ `uname` = "Linux" ]; then
mkdir -p dist/etc/ld.so.conf.d/
echo "${{ matrix.install_dir }}/kaldi/src/lib" > dist/etc/ld.so.conf.d/kaldi.conf
echo "${{ matrix.install_dir }}/kaldi/tools/openfst/lib/" >> dist/etc/ld.so.conf.d/kaldi.conf
if [ -e tools/OpenBLAS/install ] ; then
echo "${{ matrix.install_dir }}/kaldi/tools/OpenBLAS/install/lib/" >> dist/etc/ld.so.conf.d/kaldi.conf
fi
fi
mkdir -p dist${{ matrix.pkgconfig_dir }}
echo 'kaldi_root=${{ matrix.install_dir }}/kaldi' > dist${{ matrix.pkgconfig_dir }}/kaldi-asr.pc
echo '' >> dist${{ matrix.pkgconfig_dir }}/kaldi-asr.pc
echo 'Name: kaldi-asr' >> dist${{ matrix.pkgconfig_dir }}/kaldi-asr.pc
echo 'Description: kaldi-asr speech recognition toolkit' >> dist${{ matrix.pkgconfig_dir }}/kaldi-asr.pc
echo "Version: ${RELEASE}" >> dist${{ matrix.pkgconfig_dir }}/kaldi-asr.pc
echo 'Libs: -L${kaldi_root}/tools/openfst/lib -L${kaldi_root}/src/lib -lkaldi-decoder -lkaldi-lat -lkaldi-fstext -lkaldi-hmm -lkaldi-feat -lkaldi-transform -lkaldi-gmm -lkaldi-tree -lkaldi-util -lkaldi-matrix -lkaldi-base -lkaldi-nnet3 -lkaldi-online2' >> dist${{ matrix.pkgconfig_dir }}/kaldi-asr.pc
echo 'Cflags: -I${kaldi_root}/src -I${kaldi_root}/tools/openfst/include' >> dist${{ matrix.pkgconfig_dir }}/kaldi-asr.pc
sudo chown -R root:0 dist
release_name=`cat release_name`
os_name=`uname | tr A-Z a-z`
ARCHIVE_NAME_LIB="kaldi-${RELEASE}-${os_name}_${release_name}.tar.xz"
install_dir_root=$(echo "${{ matrix.install_dir }}" | cut -d "/" -f2)
pkgconfig_dir_root=$(echo "${{ matrix.pkgconfig_dir }}" | cut -d "/" -f2)
if [ ${install_dir_root} != ${pkgconfig_dir_root} ]; then
dirs="${install_dir_root} ${pkgconfig_dir_root}"
else
dirs="${install_dir_root}"
fi
if [ `uname` = "Linux" ]; then
dirs="${dirs} etc"
fi
tar cJf ${ARCHIVE_NAME_LIB} -C dist ${dirs}
sudo mkdir -p dist${{ matrix.install_dir }}/kaldi/src/bin/
sudo cp -a src/bin/* dist${{ matrix.install_dir }}/kaldi/src/bin/
sudo find dist${{ matrix.install_dir }}/kaldi/src/bin -type f -name '*.o' -delete
sudo chown -R root:0 dist
ARCHIVE_NAME_WITH_BIN="kaldi-${RELEASE}-${os_name}_${release_name}-with-binaries.tar.xz"
tar cJf ${ARCHIVE_NAME_WITH_BIN} -C dist ${dirs}
echo "::set-output name=ARCHIVE_NAME_LIB::${ARCHIVE_NAME_LIB}"
echo "::set-output name=ARCHIVE_NAME_WITH_BIN::${ARCHIVE_NAME_WITH_BIN}"
- name: Archive tarball with libaries
uses: actions/upload-artifact@v2
with:
name: ${{ steps.create-tarballs.outputs.ARCHIVE_NAME_LIB }}
path: ${{ steps.create-tarballs.outputs.ARCHIVE_NAME_LIB }}
- name: Archive tarball with binaries
uses: actions/upload-artifact@v2
with:
name: ${{ steps.create-tarballs.outputs.ARCHIVE_NAME_WITH_BIN }}
path: ${{ steps.create-tarballs.outputs.ARCHIVE_NAME_WITH_BIN }}