Merge pull request #236313 from NixOS/kaldi-fix

kaldi: fix build

authored by Jan Tojnar and committed by GitHub 65dbea59 88f3aca0

+46 -47
+46 -47
pkgs/tools/audio/kaldi/default.nix
··· 3 3 , openblas 4 4 , blas 5 5 , lapack 6 - , openfst 7 6 , icu 8 7 , cmake 9 8 , pkg-config ··· 11 10 , git 12 11 , python3 13 12 , Accelerate 13 + , _experimental-update-script-combinators 14 + , common-updater-scripts 15 + , ripgrep 16 + , unstableGitUpdater 17 + , writeShellScript 14 18 }: 15 19 16 20 assert blas.implementation == "openblas" && lapack.implementation == "openblas"; 17 - let 18 - # rev from https://github.com/kaldi-asr/kaldi/blob/master/cmake/third_party/openfst.cmake 19 - openfst = fetchFromGitHub { 20 - owner = "kkm000"; 21 - repo = "openfst"; 22 - rev = "338225416178ac36b8002d70387f5556e44c8d05"; 23 - sha256 = "sha256-MGEUuw7ex+WcujVdxpO2Bf5sB6Z0edcAeLGqW/Lo1Hs="; 24 - }; 25 - in 26 - stdenv.mkDerivation { 21 + stdenv.mkDerivation (finalAttrs: { 27 22 pname = "kaldi"; 28 - version = "unstable-2022-09-26"; 23 + version = "unstable-2023-05-02"; 29 24 30 25 src = fetchFromGitHub { 31 26 owner = "kaldi-asr"; 32 27 repo = "kaldi"; 33 - rev = "f6f4ccaf213f0fe8b26e633a7dc0c802150626a0"; 34 - sha256 = "sha256-ybW2J4lWf6YaQGZZvxEVDUMAg84DC17W+yX6ZsuBDac="; 28 + rev = "71f38e62cad01c3078555bfe78d0f3a527422d75"; 29 + sha256 = "sha256-2xm0F80cjovy/G9Ytq/iwa1eexZk0mromv6PPuNIT8U="; 35 30 }; 36 31 37 32 cmakeFlags = [ ··· 39 34 "-DBUILD_SHARED_LIBS=on" 40 35 "-DBLAS_LIBRARIES=-lblas" 41 36 "-DLAPACK_LIBRARIES=-llapack" 37 + "-DFETCHCONTENT_SOURCE_DIR_OPENFST:PATH=${finalAttrs.passthru.sources.openfst}" 42 38 ]; 43 39 44 - enableParallelBuilding = true; 45 - 46 - preConfigure = '' 47 - mkdir bin 48 - cat > bin/git <<'EOF' 49 - #!${stdenv.shell} 50 - if [[ "$1" == "--version" ]]; then 51 - # cmake checks this 52 - ${git}/bin/git --version 53 - elif [[ "$1" == "clone" ]]; then 54 - # mock this call: 55 - 56 - # https://github.com/kaldi-asr/kaldi/blob/c9d8b9ad3fef89237ba5517617d977b7d70a7ed5/cmake/third_party/openfst.cmake#L5 57 - cp -r ${openfst} ''${@: -1} 58 - chmod -R +w ''${@: -1} 59 - elif [[ "$1" == "rev-list" ]]; then 60 - # fix up this call: 61 - # https://github.com/kaldi-asr/kaldi/blob/c9d8b9ad3fef89237ba5517617d977b7d70a7ed5/cmake/VersionHelper.cmake#L8 62 - echo 0 63 - elif [[ "$1" == "rev-parse" ]]; then 64 - echo ${openfst.rev} 65 - echo 0 66 - fi 67 - true 68 - EOF 69 - chmod +x bin/git 70 - export PATH=$(pwd)/bin:$PATH 71 - ''; 72 - 73 - outputs = [ "out" "dev" ]; 74 - 75 40 buildInputs = [ 76 41 openblas 77 - openfst 78 42 icu 79 43 ] ++ lib.optionals stdenv.isDarwin [ 80 44 Accelerate ··· 86 50 python3 87 51 ]; 88 52 53 + preConfigure = '' 54 + cmakeFlagsArray+=( 55 + # Extract version without the need for git. 56 + # https://github.com/kaldi-asr/kaldi/blob/71f38e62cad01c3078555bfe78d0f3a527422d75/cmake/VersionHelper.cmake 57 + # Patch number is not actually used by default so we can just ignore it. 58 + # https://github.com/kaldi-asr/kaldi/blob/71f38e62cad01c3078555bfe78d0f3a527422d75/CMakeLists.txt#L214 59 + "-DKALDI_VERSION=$(cat src/.version)" 60 + ) 61 + ''; 62 + 89 63 postInstall = '' 90 64 mkdir -p $out/share/kaldi 91 65 cp -r ../egs $out/share/kaldi 92 66 ''; 93 67 68 + passthru = { 69 + sources = { 70 + # rev from https://github.com/kaldi-asr/kaldi/blob/master/cmake/third_party/openfst.cmake 71 + openfst = fetchFromGitHub { 72 + owner = "kkm000"; 73 + repo = "openfst"; 74 + rev = "338225416178ac36b8002d70387f5556e44c8d05"; 75 + hash = "sha256-MGEUuw7ex+WcujVdxpO2Bf5sB6Z0edcAeLGqW/Lo1Hs="; 76 + }; 77 + }; 78 + 79 + updateScript = 80 + let 81 + updateSource = unstableGitUpdater {}; 82 + updateOpenfst = writeShellScript "update-openfst" '' 83 + 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") 84 + ${common-updater-scripts}/bin/update-source-version kaldi.sources.openfst "$hash" --source-key=out "--version-key=rev" 85 + ''; 86 + in 87 + _experimental-update-script-combinators.sequence [ 88 + updateSource 89 + updateOpenfst 90 + ]; 91 + }; 92 + 94 93 meta = with lib; { 95 94 description = "Speech Recognition Toolkit"; 96 95 homepage = "https://kaldi-asr.org"; ··· 98 97 maintainers = with maintainers; [ mic92 ]; 99 98 platforms = platforms.unix; 100 99 }; 101 - } 100 + })