Skip to content

Build your personal knowledge base with Trilium Notes

feat(desktop): build sherpa-onnx for Windows arm64 in CI

Elian Doran2b49dada588b
diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml
index 46f518adac..b2b7c3d568 100644
--- a/.github/workflows/nightly.yml
+++ b/.github/workflows/nightly.yml
@@ -12,6 +12,7 @@ on:
paths:
- .github/actions/build-electron/*
- .github/workflows/nightly.yml
+ - .github/workflows/sherpa-onnx-win-arm64.yml
- forge.config.ts
concurrency:
@@ -31,8 +32,13 @@ permissions:
contents: write
jobs:
+ sherpa-onnx-win-arm64:
+ if: ${{ github.repository == vars.REPO_MAIN }}
+ uses: ./.github/workflows/sherpa-onnx-win-arm64.yml
nightly-electron:
if: ${{ github.repository == vars.REPO_MAIN }}
+ needs:
+ - sherpa-onnx-win-arm64
name: Deploy nightly
strategy:
fail-fast: false
@@ -100,6 +106,12 @@ jobs:
# The arm64 macOS runner also packages darwin-x64, which needs that architecture's native
# optional dependencies (sherpa-onnx-darwin-x64) beside the host's.
run: pnpm install --frozen-lockfile ${{ matrix.os.name == 'macos' && '--cpu=x64,arm64' || '' }}
+ - name: Add sherpa-onnx for Windows arm64
+ if: ${{ matrix.os.name == 'windows' && matrix.arch == 'arm64' }}
+ uses: actions/download-artifact@v8
+ with:
+ name: sherpa-onnx-win-arm64
+ path: node_modules/sherpa-onnx-win-arm64
- name: Update nightly version
run: pnpm run chore:ci-update-nightly-version
- name: Run the build
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index c6d1cfb581..90ab34ab3d 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -31,10 +31,13 @@ jobs:
- name: Check version consistency
run: pnpm tsx ${{ github.workspace }}/scripts/check-version-consistency.ts ${{ github.ref_name }}
+ sherpa-onnx-win-arm64:
+ uses: ./.github/workflows/sherpa-onnx-win-arm64.yml
make-electron:
name: Make Electron
needs:
- sanity-check
+ - sherpa-onnx-win-arm64
strategy:
fail-fast: false
matrix:
@@ -86,6 +89,12 @@ jobs:
# The arm64 macOS runner also packages darwin-x64, which needs that architecture's native
# optional dependencies (sherpa-onnx-darwin-x64) beside the host's.
run: pnpm install --frozen-lockfile ${{ matrix.os.name == 'macos' && '--cpu=x64,arm64' || '' }}
+ - name: Add sherpa-onnx for Windows arm64
+ if: ${{ matrix.os.name == 'windows' && matrix.arch == 'arm64' }}
+ uses: actions/download-artifact@v8
+ with:
+ name: sherpa-onnx-win-arm64
+ path: node_modules/sherpa-onnx-win-arm64
- name: Run the build
uses: ./.github/actions/build-electron
with:
diff --git a/.github/workflows/sherpa-onnx-win-arm64.yml b/.github/workflows/sherpa-onnx-win-arm64.yml
new file mode 100644
index 0000000000..7dec6e338a
--- /dev/null
+++ b/.github/workflows/sherpa-onnx-win-arm64.yml
@@ -0,0 +1,111 @@
+name: sherpa-onnx for Windows arm64
+
+# sherpa-onnx publishes no Node addon for Windows on arm64 (no `sherpa-onnx-win-arm64` on npm),
+# so meeting transcription has nothing to load there. This builds that package from upstream's
+# sources at the pinned version, linked against the win-arm64 libraries upstream releases, and
+# uploads it as the `sherpa-onnx-win-arm64` artifact for the Windows arm64 desktop build.
+# Remove it once upstream publishes the package (k2-fsa/sherpa-onnx, npm-addon-win-arm64.yaml).
+
+on:
+ workflow_call:
+
+permissions:
+ contents: read
+
+jobs:
+ build:
+ name: Build sherpa-onnx-win-arm64
+ runs-on: windows-11-arm
+ defaults:
+ run:
+ shell: bash
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ persist-credentials: false
+ sparse-checkout: |
+ apps/desktop/package.json
+ .github/workflows/sherpa-onnx-win-arm64.yml
+ sparse-checkout-cone-mode: false
+
+ - name: Read the pinned version
+ id: version
+ run: |
+ version=$(node -p 'require("./apps/desktop/package.json").dependencies["sherpa-onnx-node"]')
+ echo "version=$version" >> "$GITHUB_OUTPUT"
+
+ - name: Restore a previous build
+ id: cache
+ uses: actions/cache@v5
+ with:
+ path: out/sherpa-onnx-win-arm64
+ key: sherpa-onnx-win-arm64-${{ steps.version.outputs.version }}-${{ hashFiles('.github/workflows/sherpa-onnx-win-arm64.yml') }}
+
+ - uses: actions/setup-node@v7
+ if: steps.cache.outputs.cache-hit != 'true'
+ with:
+ node-version: 24
+
+ - name: Build the addon
+ if: steps.cache.outputs.cache-hit != 'true'
+ env:
+ VERSION: ${{ steps.version.outputs.version }}
+ run: |
+ set -euo pipefail
+ test "$(node -p process.arch)" = arm64
+
+ git clone --quiet --depth 1 --branch "v$VERSION" https://github.com/k2-fsa/sherpa-onnx.git sherpa
+ # The addon's sources are git symlinks, which a checkout without symlink support writes
+ # as files holding the link target.
+ cd sherpa
+ git ls-files -s scripts/node-addon-api | awk '$1 == "120000" { print $4 }' | while read -r link; do
+ if [ ! -L "$link" ]; then
+ cp --remove-destination "$(dirname "$link")/$(cat "$link")" "$link"
+ fi
+ done
+ cd ..
+
+ libs="sherpa-onnx-v$VERSION-win-arm64-shared-MD-Release-lib"
+ curl -sSfL -o libs.tar.bz2 \
+ "https://github.com/k2-fsa/sherpa-onnx/releases/download/v$VERSION/$libs.tar.bz2"
+ tar xjf libs.tar.bz2
+ mkdir -p "$libs/include/sherpa-onnx/c-api"
+ cp sherpa/sherpa-onnx/c-api/c-api.h "$libs/include/sherpa-onnx/c-api/"
+ export SHERPA_ONNX_INSTALL_DIR="$PWD/$libs"
+
+ cd sherpa/scripts/node-addon-api
+ npm install --ignore-scripts --no-audit --no-fund
+ ./node_modules/.bin/cmake-js compile -A ARM64
+ cd ../../..
+
+ out=out/sherpa-onnx-win-arm64
+ mkdir -p "$out"
+ cp sherpa/scripts/node-addon-api/build/Release/sherpa-onnx.node "$libs"/lib/*.dll "$out/"
+ cp sherpa/LICENSE "$out/"
+ cat > "$out/package.json" <<EOF
+ {
+ "name": "sherpa-onnx-win-arm64",
+ "version": "$VERSION",
+ "license": "Apache-2.0",
+ "os": [ "win32" ],
+ "cpu": [ "arm64" ]
+ }
+ EOF
+
+ - name: Load the addon
+ env:
+ VERSION: ${{ steps.version.outputs.version }}
+ run: |
+ node -e '
+ const addon = require("./out/sherpa-onnx-win-arm64/sherpa-onnx.node");
+ if (addon.version !== process.env.VERSION) {
+ throw new Error(`Built ${addon.version}, expected ${process.env.VERSION}`);
+ }
+ console.log(`sherpa-onnx ${addon.version}, onnxruntime ${addon.onnxruntimeVersion}`);
+ '
+
+ - uses: actions/upload-artifact@v7
+ with:
+ name: sherpa-onnx-win-arm64
+ path: out/sherpa-onnx-win-arm64
+ if-no-files-found: error
diff --git a/apps/desktop/scripts/build.ts b/apps/desktop/scripts/build.ts
index af9d0e8501..e229a8f4d2 100644
--- a/apps/desktop/scripts/build.ts
+++ b/apps/desktop/scripts/build.ts
@@ -56,7 +56,9 @@ async function main() {
* Copies `sherpa-onnx-node`, which the meeting transcription worker loads, together with the
* package holding its native addon for the target platform. That package is only an optional
* dependency, so pnpm installs it just for the host's platform; CI installs the others it
- * packages for with `--cpu`. A target with no such package (Windows on arm64) ships neither.
+ * packages for with `--cpu`. Upstream publishes none for Windows on arm64, so CI builds
+ * `sherpa-onnx-win-arm64` itself (`.github/workflows/sherpa-onnx-win-arm64.yml`) and places it in
+ * `node_modules`. A target with no such package ships neither.
*/
function copySherpaOnnx() {
const sherpaDir = join(build.rootDir, "node_modules", "sherpa-onnx-node");
@@ -64,11 +66,12 @@ function copySherpaOnnx() {
const { optionalDependencies } = JSON.parse(sherpaPackageJson);
const platform = process.platform === "win32" ? "win" : process.platform;
const platformPackage = `sherpa-onnx-${platform}-${targetArch()}`;
- if (!(platformPackage in optionalDependencies)) {
+ const isInstalled = existsSync(join(build.rootDir, "node_modules", platformPackage));
+ if (!(platformPackage in optionalDependencies) && !isInstalled) {
console.warn(`sherpa-onnx has no ${platformPackage}; transcription is unavailable there.`);
return;
}
- if (!existsSync(join(build.rootDir, "node_modules", platformPackage))) {
+ if (!isInstalled) {
throw new Error(`${platformPackage} is not installed. Install the target architecture's `
+ `optional dependencies too: pnpm install --cpu=${process.arch},${targetArch()}`);
}