1515 build-linux :
1616 runs-on : ubuntu-latest
1717 if : true
18+ env :
19+ MKL_URL : " "
20+ # MKL_URL: "https://registrationcenter-download.intel.com/akdlm/irc_nas/tec/16917/l_mkl_2020.4.304.tgz"
1821 steps :
1922 - name : Checkout repository
2023 uses : actions/checkout@v5
@@ -26,29 +29,86 @@ jobs:
2629 export TAG=$(git tag --points-at HEAD)
2730 echo "TAG: $TAG"
2831 if [[ $TAG ]]; then
32+ echo "KALDI_BRANCH: kag-$TAG"
2933 echo "KALDI_BRANCH=kag-$TAG" >> $GITHUB_ENV
3034 echo "KALDI_BRANCH=kag-$TAG" >> $GITHUB_OUTPUT
3135 else
36+ echo "KALDI_BRANCH: ${GITHUB_REF/refs\/heads\//}"
3237 echo "KALDI_BRANCH=${GITHUB_REF/refs\/heads\//}" >> $GITHUB_ENV
3338 echo "KALDI_BRANCH=${GITHUB_REF/refs\/heads\//}" >> $GITHUB_OUTPUT
3439 fi
3540
41+ - name : Get Kaldi commit hash
42+ id : get-kaldi-commit
43+ run : |
44+ KALDI_COMMIT=$(git ls-remote https://github.com/daanzu/kaldi-fork-active-grammar.git $KALDI_BRANCH | cut -f1)
45+ echo "KALDI_COMMIT: $KALDI_COMMIT"
46+ echo "KALDI_COMMIT=$KALDI_COMMIT" >> $GITHUB_OUTPUT
47+
48+ - name : Restore cached native binaries
49+ id : cache-native-binaries-restore
50+ uses : actions/cache/restore@v4
51+ with :
52+ key : native-${{ runner.os }}-${{ steps.get-kaldi-commit.outputs.KALDI_COMMIT }}-${{ env.MKL_URL }}-v1
53+ path : |
54+ kaldi_active_grammar/exec/linux
55+ kaldi_active_grammar.libs
56+
3657 - name : Setup just
3758 run : |
3859 ls -al $HOME
3960 mkdir $HOME/bin
4061 curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to $HOME/bin/
4162 echo "$HOME/bin" >> $GITHUB_PATH
4263
43- - name : Build with dockcross
64+ - name : Modify native binaries restored from cache to work with auditwheel repair
65+ if : steps.cache-native-binaries-restore.outputs.cache-hit == 'true'
66+ run : |
67+ patchelf --force-rpath --set-rpath "$(PWD)/kaldi_active_grammar.libs" kaldi_active_grammar/exec/linux/libkaldi-dragonfly.so
68+ readelf -d kaldi_active_grammar/exec/linux/libkaldi-dragonfly.so | egrep 'NEEDED|RUNPATH|RPATH'
69+ LD_DEBUG=libs lddtree kaldi_active_grammar/exec/linux/libkaldi-dragonfly.so
70+
71+ - name : Build with dockcross (native binaries & python wheel)
4472 run : |
4573 echo "KALDI_BRANCH: $KALDI_BRANCH"
4674 echo "MKL_URL: $MKL_URL"
47- # Example MKL_URL: https://registrationcenter-download.intel.com/akdlm/irc_nas/tec/16917/l_mkl_2020.4.304.tgz
48- just build-dockcross $KALDI_BRANCH $MKL_URL
49- # cp dist/* wheelhouse/
75+ just build-dockcross ${{ steps.cache-native-binaries-restore.outputs.cache-hit == 'true' && '--skip-native' || '' }} $KALDI_BRANCH $MKL_URL
5076 ls -al wheelhouse/
5177
78+ - name : Extract native binaries from wheel after auditwheel repair, to save to cache
79+ if : steps.cache-native-binaries-restore.outputs.cache-hit != 'true'
80+ run : |
81+ # Assert there is only one wheel
82+ WHEEL_COUNT=$(ls wheelhouse/*.whl | wc -l)
83+ if [ "$WHEEL_COUNT" -ne 1 ]; then
84+ echo "Error: Expected exactly 1 wheel, found $WHEEL_COUNT"
85+ ls -al wheelhouse/
86+ exit 1
87+ fi
88+ WHEEL_FILE=$(ls wheelhouse/*.whl)
89+ echo "Extracting from wheel: $WHEEL_FILE"
90+ unzip -j -o $WHEEL_FILE 'kaldi_active_grammar/exec/linux/*' -d kaldi_active_grammar/exec/linux/
91+ unzip -o $WHEEL_FILE 'kaldi_active_grammar.libs/*'
92+ ls -al kaldi_active_grammar/exec/linux/
93+ readelf -d kaldi_active_grammar/exec/linux/libkaldi-dragonfly.so | egrep 'NEEDED|RUNPATH|RPATH'
94+
95+ - name : Save cached native binaries
96+ if : steps.cache-native-binaries-restore.outputs.cache-hit != 'true'
97+ uses : actions/cache/save@v4
98+ with :
99+ key : ${{ steps.cache-native-binaries-restore.outputs.cache-primary-key }}
100+ path : |
101+ kaldi_active_grammar/exec/linux
102+ kaldi_active_grammar.libs
103+
104+ - name : Upload native binaries to artifacts
105+ uses : actions/upload-artifact@v4
106+ with :
107+ name : native-linux
108+ path : |
109+ kaldi_active_grammar/exec/linux
110+ kaldi_active_grammar.libs
111+
52112 - name : Upload Linux wheels
53113 uses : actions/upload-artifact@v4
54114 with :
@@ -74,33 +134,54 @@ jobs:
74134 path : main
75135
76136 - name : Get KALDI_BRANCH (kag-$TAG tag if commit is tagged; current branch name if not)
77- id : get_kaldi_branch
137+ id : get-kaldi-branch
138+ working-directory : main
78139 run : |
79140 # Fetch tags on the one fetched commit (shallow clone)
80141 git fetch --depth=1 origin "+refs/tags/*:refs/tags/*"
81142 export TAG=$(git tag --points-at HEAD)
143+ echo "TAG: $TAG"
82144 if [[ $TAG ]]; then
145+ echo "KALDI_BRANCH: kag-$TAG"
83146 echo "KALDI_BRANCH=kag-$TAG" >> $GITHUB_ENV
84147 echo "KALDI_BRANCH=kag-$TAG" >> $GITHUB_OUTPUT
85148 else
149+ echo "KALDI_BRANCH: ${GITHUB_REF/refs\/heads\//}"
86150 echo "KALDI_BRANCH=${GITHUB_REF/refs\/heads\//}" >> $GITHUB_ENV
87151 echo "KALDI_BRANCH=${GITHUB_REF/refs\/heads\//}" >> $GITHUB_OUTPUT
88152 fi
89153
154+ - name : Get Kaldi commit hash
155+ id : get-kaldi-commit
156+ run : |
157+ KALDI_COMMIT=$(git ls-remote https://github.com/daanzu/kaldi-fork-active-grammar.git $KALDI_BRANCH | cut -f1)
158+ echo "KALDI_COMMIT: $KALDI_COMMIT"
159+ echo "KALDI_COMMIT=$KALDI_COMMIT" >> $GITHUB_OUTPUT
160+
161+ - name : Restore cached native binaries
162+ id : cache-native-binaries-restore
163+ uses : actions/cache/restore@v4
164+ with :
165+ key : native-${{ runner.os }}-${{ steps.get-kaldi-commit.outputs.KALDI_COMMIT }}-${{ env.VS_VERSION }}-${{ env.PLATFORM_TOOLSET }}-${{ env.WINDOWS_TARGET_PLATFORM_VERSION }}-${{ env.MKL_VERSION }}-v1
166+ path : main/kaldi_active_grammar/exec/windows
167+
90168 - name : Checkout OpenFST repository
169+ if : steps.cache-native-binaries-restore.outputs.cache-hit != 'true'
91170 uses : actions/checkout@v5
92171 with :
93172 repository : daanzu/openfst
94173 path : openfst
95174
96175 - name : Checkout Kaldi repository
176+ if : steps.cache-native-binaries-restore.outputs.cache-hit != 'true'
97177 uses : actions/checkout@v5
98178 with :
99179 repository : daanzu/kaldi-fork-active-grammar
100180 path : kaldi
101- ref : ${{ steps.get_kaldi_branch .outputs.KALDI_BRANCH }}
181+ ref : ${{ steps.get-kaldi-branch .outputs.KALDI_BRANCH }}
102182
103183 - name : Gather system information
184+ if : steps.cache-native-binaries-restore.outputs.cache-hit != 'true'
104185 run : |
105186 echo $GITHUB_WORKSPACE
106187 df -h
@@ -118,6 +199,7 @@ jobs:
118199 vswhere -find 'VC\Redist\**\VC_redist.x64.exe'
119200
120201 - name : Setup Kaldi build configuration
202+ if : steps.cache-native-binaries-restore.outputs.cache-hit != 'true'
121203 run : |
122204 cd kaldi/windows
123205 cp kaldiwin_mkl.props kaldiwin.props
@@ -136,28 +218,49 @@ jobs:
136218 perl get_version.pl
137219
138220 - name : Add msbuild to PATH
221+ if : steps.cache-native-binaries-restore.outputs.cache-hit != 'true'
139222 uses : microsoft/setup-msbuild@v2
140223
141224 - name : Install MKL
225+ if : steps.cache-native-binaries-restore.outputs.cache-hit != 'true'
142226 run : winget install --id=Intel.oneMKL -v "${MKL_VERSION}" -e --accept-package-agreements --accept-source-agreements --disable-interactivity
143227
144228 - name : Build OpenFST
229+ if : steps.cache-native-binaries-restore.outputs.cache-hit != 'true'
145230 shell : cmd
146231 run : msbuild -t:Build -p:Configuration=Release -p:Platform=x64 -p:PlatformToolset=%PLATFORM_TOOLSET% -maxCpuCount -verbosity:minimal openfst/openfst.sln
147232
148233 - name : Build Kaldi
234+ if : steps.cache-native-binaries-restore.outputs.cache-hit != 'true'
149235 shell : cmd
150236 run : msbuild -t:Build -p:Configuration=Release -p:Platform=x64 -p:PlatformToolset=%PLATFORM_TOOLSET% -p:WindowsTargetPlatformVersion=%WINDOWS_TARGET_PLATFORM_VERSION% -maxCpuCount -verbosity:minimal kaldi/kaldiwin_%VS_VERSION%_MKL/kaldiwin/kaldi-dragonfly/kaldi-dragonfly.vcxproj
151237
238+ - name : Copy native binaries
239+ if : steps.cache-native-binaries-restore.outputs.cache-hit != 'true'
240+ run : |
241+ mkdir -p main/kaldi_active_grammar/exec/windows
242+ cp kaldi/kaldiwin_${VS_VERSION}_MKL/kaldiwin/kaldi-dragonfly/x64/Release/kaldi-dragonfly.dll main/kaldi_active_grammar/exec/windows/
243+
244+ - name : Save cached native binaries
245+ if : steps.cache-native-binaries-restore.outputs.cache-hit != 'true'
246+ uses : actions/cache/save@v4
247+ with :
248+ key : ${{ steps.cache-native-binaries-restore.outputs.cache-primary-key }}
249+ path : main/kaldi_active_grammar/exec/windows
250+
251+ - name : Upload native binaries to artifacts
252+ uses : actions/upload-artifact@v4
253+ with :
254+ name : native-windows
255+ path : main/kaldi_active_grammar/exec/windows
256+
152257 - name : Build Python wheel
258+ working-directory : main
153259 run : |
154- cd main
155260 python -m pip -V
156261 python -m pip install --upgrade setuptools wheel scikit-build cmake ninja
157262 # ls -alR ../
158- mkdir -p kaldi_active_grammar/exec/windows
159- cp ../kaldi/kaldiwin_${VS_VERSION}_MKL/kaldiwin/kaldi-dragonfly/x64/Release/kaldi-dragonfly.dll kaldi_active_grammar/exec/windows/
160- env KALDIAG_SETUP_RAW=1 python setup.py bdist_wheel
263+ env KALDIAG_BUILD_SKIP_NATIVE=1 python setup.py bdist_wheel
161264 ls -al dist/
162265
163266 - name : Upload Windows wheels
@@ -188,27 +291,38 @@ jobs:
188291 uses : actions/checkout@v5
189292
190293 - name : Get KALDI_BRANCH (kag-$TAG tag if commit is tagged; current branch name if not)
294+ id : get-kaldi-branch
191295 run : |
192296 # Fetch tags on the one fetched commit (shallow clone)
193297 git fetch --depth=1 origin "+refs/tags/*:refs/tags/*"
194298 export TAG=$(git tag --points-at HEAD)
299+ echo "TAG: $TAG"
195300 if [[ $TAG ]]; then
301+ echo "KALDI_BRANCH: kag-$TAG"
196302 echo "KALDI_BRANCH=kag-$TAG" >> $GITHUB_ENV
197303 echo "KALDI_BRANCH=kag-$TAG" >> $GITHUB_OUTPUT
198304 else
305+ echo "KALDI_BRANCH: ${GITHUB_REF/refs\/heads\//}"
199306 echo "KALDI_BRANCH=${GITHUB_REF/refs\/heads\//}" >> $GITHUB_ENV
200307 echo "KALDI_BRANCH=${GITHUB_REF/refs\/heads\//}" >> $GITHUB_OUTPUT
201308 fi
202309
203- - name : Install dependencies
310+ - name : Get Kaldi commit hash
311+ id : get-kaldi-commit
204312 run : |
205- python3 -m pip install --break-system-packages --user --upgrade setuptools wheel scikit-build cmake ninja
206- brew install automake sox libtool
207- brew reinstall gfortran # For openblas
208- # brew install autoconf
313+ KALDI_COMMIT=$(git ls-remote https://github.com/daanzu/kaldi-fork-active-grammar.git $KALDI_BRANCH | cut -f1)
314+ echo "KALDI_COMMIT: $KALDI_COMMIT"
315+ echo "KALDI_COMMIT=$KALDI_COMMIT" >> $GITHUB_OUTPUT
316+
317+ - name : Restore cached native binaries
318+ id : cache-native-binaries-restore
319+ uses : actions/cache/restore@v4
320+ with :
321+ key : native-${{ runner.os }}-arm-${{ steps.get-kaldi-commit.outputs.KALDI_COMMIT }}-${{ env.MACOSX_DEPLOYMENT_TARGET }}-${{ env.MKL_URL }}-v1
322+ path : kaldi_active_grammar/exec/macos
209323
210324 - name : Install MKL (if enabled)
211- if : ${{ env.MKL_URL != '' }}
325+ if : ${{ env.MKL_URL != '' && steps.cache-native-binaries-restore.outputs.cache-hit != 'true' }}
212326 run : |
213327 echo "Installing MKL from: $MKL_URL"
214328 export MKL_FILE=${MKL_URL##*/}
@@ -219,12 +333,38 @@ jobs:
219333 sed -i.bak -e 's/decline/accept/g' silent.cfg
220334 sudo /Volumes/${MKL_FILE}/${MKL_FILE}.app/Contents/MacOS/install.sh --silent silent.cfg
221335
336+ - name : Install dependencies for native build
337+ if : steps.cache-native-binaries-restore.outputs.cache-hit != 'true'
338+ run : |
339+ python3 -m pip install --break-system-packages --user --upgrade scikit-build cmake ninja
340+ brew install automake sox libtool
341+ brew reinstall gfortran # For openblas
342+ # brew install autoconf
343+
344+ - name : Install dependencies for python build
345+ run : |
346+ python3 -m pip install --break-system-packages --user --upgrade setuptools wheel
347+
222348 - name : Build Python wheel
223349 run : |
224350 echo "KALDI_BRANCH: $KALDI_BRANCH"
225- python3 setup.py bdist_wheel
351+ echo "MKL_URL: $MKL_URL"
352+ ${{ steps.cache-native-binaries-restore.outputs.cache-hit == 'true' && 'KALDIAG_BUILD_SKIP_NATIVE=1' || '' }} python3 setup.py bdist_wheel
226353 ls -al dist/
227354
355+ - name : Save cached native binaries
356+ if : steps.cache-native-binaries-restore.outputs.cache-hit != 'true'
357+ uses : actions/cache/save@v4
358+ with :
359+ key : ${{ steps.cache-native-binaries-restore.outputs.cache-primary-key }}
360+ path : kaldi_active_grammar/exec/macos
361+
362+ - name : Upload native binaries to artifacts
363+ uses : actions/upload-artifact@v4
364+ with :
365+ name : native-macos-arm
366+ path : kaldi_active_grammar/exec/macos
367+
228368 - name : Upload MacOS ARM wheels
229369 uses : actions/upload-artifact@v4
230370 with :
@@ -243,27 +383,38 @@ jobs:
243383 uses : actions/checkout@v5
244384
245385 - name : Get KALDI_BRANCH (kag-$TAG tag if commit is tagged; current branch name if not)
386+ id : get-kaldi-branch
246387 run : |
247388 # Fetch tags on the one fetched commit (shallow clone)
248389 git fetch --depth=1 origin "+refs/tags/*:refs/tags/*"
249390 export TAG=$(git tag --points-at HEAD)
391+ echo "TAG: $TAG"
250392 if [[ $TAG ]]; then
393+ echo "KALDI_BRANCH: kag-$TAG"
251394 echo "KALDI_BRANCH=kag-$TAG" >> $GITHUB_ENV
252395 echo "KALDI_BRANCH=kag-$TAG" >> $GITHUB_OUTPUT
253396 else
397+ echo "KALDI_BRANCH: ${GITHUB_REF/refs\/heads\//}"
254398 echo "KALDI_BRANCH=${GITHUB_REF/refs\/heads\//}" >> $GITHUB_ENV
255399 echo "KALDI_BRANCH=${GITHUB_REF/refs\/heads\//}" >> $GITHUB_OUTPUT
256400 fi
257401
258- - name : Install dependencies
402+ - name : Get Kaldi commit hash
403+ id : get-kaldi-commit
259404 run : |
260- python3 -m pip install --break-system-packages --user --upgrade setuptools wheel scikit-build cmake ninja
261- brew install automake sox
262- brew reinstall gfortran # For openblas
263- # brew install autoconf libtool
405+ KALDI_COMMIT=$(git ls-remote https://github.com/daanzu/kaldi-fork-active-grammar.git $KALDI_BRANCH | cut -f1)
406+ echo "KALDI_COMMIT: $KALDI_COMMIT"
407+ echo "KALDI_COMMIT=$KALDI_COMMIT" >> $GITHUB_OUTPUT
408+
409+ - name : Restore cached native binaries
410+ id : cache-native-binaries-restore
411+ uses : actions/cache/restore@v4
412+ with :
413+ key : native-${{ runner.os }}-intel-${{ steps.get-kaldi-commit.outputs.KALDI_COMMIT }}-${{ env.MACOSX_DEPLOYMENT_TARGET }}-${{ env.MKL_URL }}-v1
414+ path : kaldi_active_grammar/exec/macos
264415
265416 - name : Install MKL (if enabled)
266- if : ${{ env.MKL_URL != '' }}
417+ if : ${{ env.MKL_URL != '' && steps.cache-native-binaries-restore.outputs.cache-hit != 'true' }}
267418 run : |
268419 echo "Installing MKL from: $MKL_URL"
269420 export MKL_FILE=${MKL_URL##*/}
@@ -274,16 +425,43 @@ jobs:
274425 sed -i.bak -e 's/decline/accept/g' silent.cfg
275426 sudo /Volumes/${MKL_FILE}/${MKL_FILE}.app/Contents/MacOS/install.sh --silent silent.cfg
276427
428+ - name : Install dependencies for native build
429+ if : steps.cache-native-binaries-restore.outputs.cache-hit != 'true'
430+ run : |
431+ python3 -m pip install --break-system-packages --user --upgrade scikit-build cmake ninja
432+ brew install automake sox
433+ brew reinstall gfortran # For openblas
434+ # brew install autoconf libtool
435+
436+ - name : Install dependencies for python build
437+ run : |
438+ python3 -m pip install --break-system-packages --user --upgrade setuptools wheel
439+
277440 - name : Build Python wheel
278441 run : |
279- python3 setup.py bdist_wheel
442+ echo "KALDI_BRANCH: $KALDI_BRANCH"
443+ echo "MKL_URL: $MKL_URL"
444+ ${{ steps.cache-native-binaries-restore.outputs.cache-hit == 'true' && 'KALDIAG_BUILD_SKIP_NATIVE=1' || '' }} python3 setup.py bdist_wheel
280445 ls -al dist/
281446
447+ - name : Save cached native binaries
448+ if : steps.cache-native-binaries-restore.outputs.cache-hit != 'true'
449+ uses : actions/cache/save@v4
450+ with :
451+ key : ${{ steps.cache-native-binaries-restore.outputs.cache-primary-key }}
452+ path : kaldi_active_grammar/exec/macos
453+
454+ - name : Upload native binaries to artifacts
455+ uses : actions/upload-artifact@v4
456+ with :
457+ name : native-macos-intel
458+ path : kaldi_active_grammar/exec/macos
459+
282460 - name : Upload MacOS Intel wheels
283461 uses : actions/upload-artifact@v4
284462 with :
285463 name : wheels-macos-intel
286- path : dist/*
464+ path : dist/*.whl
287465
288466 merge-wheels :
289467 runs-on : ubuntu-latest
0 commit comments