Repository navigation
Expand file tree
/
Copy pathstart_rust_client.ps1
More file actions
119 lines (108 loc) · 4.36 KB
/
Copy pathstart_rust_client.ps1
File metadata and controls
119 lines (108 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
[CmdletBinding()]
param(
[switch]$Release = $true,
[switch]$BuildOnly
)
$ErrorActionPreference = 'Stop'
$projectRoot = $PSScriptRoot
$manifestPath = Join-Path $projectRoot 'rust-client\Cargo.toml'
$workspaceManifestPath = Join-Path $projectRoot 'Cargo.toml'
$corpusManifestPath = Join-Path $projectRoot 'XR-Corpus\Cargo.toml'
$cargoPath = Join-Path $env:USERPROFILE '.cargo\bin\cargo.exe'
foreach ($path in @($manifestPath, $workspaceManifestPath, $corpusManifestPath)) {
if (-not (Test-Path -LiteralPath $path)) {
throw "Rust workspace manifest was not found: $path"
}
}
if (Test-Path -LiteralPath $cargoPath) {
$cargo = $cargoPath
} elseif (Get-Command cargo -ErrorAction SilentlyContinue) {
$cargo = 'cargo'
} else {
throw 'Cargo was not found. Install Rust with rustup, then restart PowerShell.'
}
# Keep the client and its child backend attached to this console while using
# the development launcher. This makes capture and VAD diagnostics visible
# during reproduction without changing packaged-app behaviour.
if ([string]::IsNullOrWhiteSpace($env:RUST_LOG)) {
$env:RUST_LOG = 'info'
}
$env:XRTRANSLATE_BACKEND_CONSOLE_LOG = '1'
$buildArguments = @(
'build', '--locked', '--manifest-path', $workspaceManifestPath,
'--target-dir', (Join-Path $projectRoot 'target'),
'--package', 'rust-client', '--package', 'xrtranslate-backend',
'--package', 'xrtranslate-account-login', '--package', 'xrtranslate-plugin',
'--features', 'rust-client/mpv,xrtranslate-plugin/host'
)
$runtimeMarker = Join-Path $projectRoot 'runtime\native-runtime.json'
if (Test-Path -LiteralPath $runtimeMarker -PathType Leaf) {
try {
$runtimeSelection = Get-Content -LiteralPath $runtimeMarker -Raw | ConvertFrom-Json
if (-not [string]::IsNullOrWhiteSpace($runtimeSelection.onnx_core_library)) {
$managedCore = $runtimeSelection.onnx_core_library
if (-not [System.IO.Path]::IsPathRooted($managedCore)) {
$managedCore = Join-Path $projectRoot $managedCore
}
if (Test-Path -LiteralPath $managedCore -PathType Leaf) {
$buildArguments += @('--features', 'xrtranslate-backend/managed-ort')
Write-Host "Using managed ONNX Runtime core: $managedCore"
}
}
} catch {
Write-Warning "Ignoring invalid managed runtime marker: $($_.Exception.Message)"
}
}
if ($Release) {
$buildArguments += '--release'
}
Write-Host 'Preparing the application...'
. (Join-Path $projectRoot 'scripts/windows-build-env.ps1')
Initialize-WindowsSpeechLibraries -ProjectRoot $projectRoot
& $cargo @buildArguments
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
$corpusBuildArguments = @(
'build', '--locked', '--manifest-path', $corpusManifestPath,
'--target-dir', (Join-Path $projectRoot 'target'),
'--package', 'xr-corpus-server'
)
if ($Release) {
$corpusBuildArguments += '--release'
}
& $cargo @corpusBuildArguments
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
Write-Host 'Preparing development plugins...'
& (Join-Path $projectRoot 'plugin-src/build.ps1') -Sdk $projectRoot `
-Output (Join-Path $projectRoot 'plugins') -TargetDirectory (Join-Path $projectRoot 'target') `
-DebugBuild:(!$Release) -Locked
$targetSubdir = if ($Release) { 'release' } else { 'debug' }
$targetBinDir = Join-Path $projectRoot "target\$targetSubdir"
& (Join-Path $projectRoot 'scripts/build-development-plugins.ps1') -DebugBuild:(!$Release)
$resourceBinDir = Join-Path $projectRoot 'rust-client\resources\bin'
if (Test-Path -LiteralPath $resourceBinDir) {
if (-not (Test-Path -LiteralPath $targetBinDir)) {
New-Item -ItemType Directory -Path $targetBinDir -Force | Out-Null
}
Get-ChildItem -Path $resourceBinDir -Filter "*.dll" | ForEach-Object {
$destFile = Join-Path $targetBinDir $_.Name
if (-not (Test-Path -LiteralPath $destFile)) {
Copy-Item -LiteralPath $_.FullName -Destination $destFile -Force
}
}
}
if ($BuildOnly) { return }
Write-Host 'Starting XRTranslate...'
Write-Host "Logging enabled (RUST_LOG=$env:RUST_LOG). Press Ctrl+C to stop."
Push-Location -LiteralPath $projectRoot
try {
# A GUI executable must stay in the pipeline for PowerShell to wait for it.
& (Join-Path $targetBinDir 'rust-client.exe') | Out-Host
$clientExitCode = $LASTEXITCODE
} finally {
Pop-Location
}
exit $clientExitCode