Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions scripts/stage-runtime.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Puts the sherpa-onnx DLLs where Tauri and the test binaries expect them.
#
# They are not in the repository. The `sherpa-onnx-sys` build script downloads
# them into `target/sherpa-onnx-prebuilt`; `tauri.conf.json` bundles
# them into `<target>/sherpa-onnx-prebuilt`; `tauri.conf.json` bundles
# `src-tauri/runtime/*.dll`, and a test binary loads them from beside itself.
# On a fresh checkout both places are empty until this has run.
param(
Expand All @@ -13,11 +13,18 @@ $ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $PSScriptRoot
$tauri = Join-Path $root 'src-tauri'
$manifest = Join-Path $tauri 'Cargo.toml'
$prebuilt = Join-Path $tauri 'target\sherpa-onnx-prebuilt'

# Asked, not assumed: CARGO_TARGET_DIR or a config file can move it.
$target = (cargo metadata --manifest-path $manifest --format-version 1 --no-deps | ConvertFrom-Json).target_directory
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Write-Host "Cargo target directory: $target"

function Find-Dlls {
if (-not (Test-Path $prebuilt)) { return @() }
Get-ChildItem $prebuilt -Recurse -Filter '*.dll' | Where-Object { $_.Name -match '^(onnxruntime|sherpa-onnx)' }
$dirs = @((Join-Path $target 'sherpa-onnx-prebuilt'), (Join-Path $target $Profile)) | Where-Object { Test-Path $_ }
if (-not $dirs) { return @() }
Get-ChildItem $dirs -Recurse -Filter '*.dll' |
Where-Object { $_.Name -match '^(onnxruntime|sherpa-onnx)' -and $_.FullName -notmatch '\\(deps|examples)\\' } |
Sort-Object Name -Unique
}

$cargoArgs = @('build', '--manifest-path', $manifest, '-p', 'sherpa-onnx-sys')
Expand All @@ -29,18 +36,22 @@ $dlls = Find-Dlls
if (-not $dlls) {
# A cached build script that does not rerun leaves the download directory empty.
cargo clean --manifest-path $manifest -p sherpa-onnx-sys
cargo @cargoArgs
cargo @cargoArgs -vv
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
$dlls = Find-Dlls
}
if (-not $dlls) { throw "No sherpa-onnx DLLs under $prebuilt" }
if (-not $dlls) {
Get-ChildItem $target -Recurse -Filter '*.dll' -ErrorAction SilentlyContinue | Select-Object -First 20 FullName | Format-Table -AutoSize | Out-String | Write-Host
throw "No sherpa-onnx DLLs under $target"
}

$runtime = Join-Path $tauri 'runtime'
New-Item -ItemType Directory -Force -Path $runtime | Out-Null
$dlls | Copy-Item -Destination $runtime -Force
Write-Host "Staged: $(($dlls.Name) -join ', ')"

if ($Profile -eq 'debug') {
$deps = Join-Path $tauri 'target\debug\deps'
$deps = Join-Path $target 'debug\deps'
New-Item -ItemType Directory -Force -Path $deps | Out-Null
$dlls | Copy-Item -Destination $deps -Force
}
Loading