Merge pull request #236313 from NixOS/kaldi-fix

kaldi: fix build
This commit is contained in:
Jan Tojnar 2023-07-11 17:20:17 +02:00 committed by GitHub
commit 65dbea59a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,6 @@
, openblas
, blas
, lapack
, openfst
, icu
, cmake
, pkg-config
@ -11,27 +10,23 @@
, git
, python3
, Accelerate
, _experimental-update-script-combinators
, common-updater-scripts
, ripgrep
, unstableGitUpdater
, writeShellScript
}:
assert blas.implementation == "openblas" && lapack.implementation == "openblas";
let
# rev from https://github.com/kaldi-asr/kaldi/blob/master/cmake/third_party/openfst.cmake
openfst = fetchFromGitHub {
owner = "kkm000";
repo = "openfst";
rev = "338225416178ac36b8002d70387f5556e44c8d05";
sha256 = "sha256-MGEUuw7ex+WcujVdxpO2Bf5sB6Z0edcAeLGqW/Lo1Hs=";
};
in
stdenv.mkDerivation {
stdenv.mkDerivation (finalAttrs: {
pname = "kaldi";
version = "unstable-2022-09-26";
version = "unstable-2023-05-02";
src = fetchFromGitHub {
owner = "kaldi-asr";
repo = "kaldi";
rev = "f6f4ccaf213f0fe8b26e633a7dc0c802150626a0";
sha256 = "sha256-ybW2J4lWf6YaQGZZvxEVDUMAg84DC17W+yX6ZsuBDac=";
rev = "71f38e62cad01c3078555bfe78d0f3a527422d75";
sha256 = "sha256-2xm0F80cjovy/G9Ytq/iwa1eexZk0mromv6PPuNIT8U=";
};
cmakeFlags = [
@ -39,42 +34,11 @@ stdenv.mkDerivation {
"-DBUILD_SHARED_LIBS=on"
"-DBLAS_LIBRARIES=-lblas"
"-DLAPACK_LIBRARIES=-llapack"
"-DFETCHCONTENT_SOURCE_DIR_OPENFST:PATH=${finalAttrs.passthru.sources.openfst}"
];
enableParallelBuilding = true;
preConfigure = ''
mkdir bin
cat > bin/git <<'EOF'
#!${stdenv.shell}
if [[ "$1" == "--version" ]]; then
# cmake checks this
${git}/bin/git --version
elif [[ "$1" == "clone" ]]; then
# mock this call:
# https://github.com/kaldi-asr/kaldi/blob/c9d8b9ad3fef89237ba5517617d977b7d70a7ed5/cmake/third_party/openfst.cmake#L5
cp -r ${openfst} ''${@: -1}
chmod -R +w ''${@: -1}
elif [[ "$1" == "rev-list" ]]; then
# fix up this call:
# https://github.com/kaldi-asr/kaldi/blob/c9d8b9ad3fef89237ba5517617d977b7d70a7ed5/cmake/VersionHelper.cmake#L8
echo 0
elif [[ "$1" == "rev-parse" ]]; then
echo ${openfst.rev}
echo 0
fi
true
EOF
chmod +x bin/git
export PATH=$(pwd)/bin:$PATH
'';
outputs = [ "out" "dev" ];
buildInputs = [
openblas
openfst
icu
] ++ lib.optionals stdenv.isDarwin [
Accelerate
@ -86,11 +50,46 @@ stdenv.mkDerivation {
python3
];
preConfigure = ''
cmakeFlagsArray+=(
# Extract version without the need for git.
# https://github.com/kaldi-asr/kaldi/blob/71f38e62cad01c3078555bfe78d0f3a527422d75/cmake/VersionHelper.cmake
# Patch number is not actually used by default so we can just ignore it.
# https://github.com/kaldi-asr/kaldi/blob/71f38e62cad01c3078555bfe78d0f3a527422d75/CMakeLists.txt#L214
"-DKALDI_VERSION=$(cat src/.version)"
)
'';
postInstall = ''
mkdir -p $out/share/kaldi
cp -r ../egs $out/share/kaldi
'';
passthru = {
sources = {
# rev from https://github.com/kaldi-asr/kaldi/blob/master/cmake/third_party/openfst.cmake
openfst = fetchFromGitHub {
owner = "kkm000";
repo = "openfst";
rev = "338225416178ac36b8002d70387f5556e44c8d05";
hash = "sha256-MGEUuw7ex+WcujVdxpO2Bf5sB6Z0edcAeLGqW/Lo1Hs=";
};
};
updateScript =
let
updateSource = unstableGitUpdater {};
updateOpenfst = writeShellScript "update-openfst" ''
hash=$(${ripgrep}/bin/rg --multiline --pcre2 --only-matching 'FetchContent_Declare\(\s*openfst[^)]*GIT_TAG\s*([0-9a-f]{40})' --replace '$1' "${finalAttrs.src}/cmake/third_party/openfst.cmake")
${common-updater-scripts}/bin/update-source-version kaldi.sources.openfst "$hash" --source-key=out "--version-key=rev"
'';
in
_experimental-update-script-combinators.sequence [
updateSource
updateOpenfst
];
};
meta = with lib; {
description = "Speech Recognition Toolkit";
homepage = "https://kaldi-asr.org";
@ -98,4 +97,4 @@ stdenv.mkDerivation {
maintainers = with maintainers; [ mic92 ];
platforms = platforms.unix;
};
}
})