Skip to content

Commit 4eb848b

Browse files
shanselmanCopilot
andcommitted
fix(release): run TTS probe under dotnet
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4ff5166 commit 4eb848b

1 file changed

Lines changed: 75 additions & 35 deletions

File tree

scripts/Test-ReleaseNativeDependencies.ps1

Lines changed: 75 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -161,57 +161,97 @@ function Add-TtsNativeStackProbeErrors {
161161
return
162162
}
163163

164-
$pwsh = Get-Command pwsh -ErrorAction SilentlyContinue
165-
if (-not $pwsh) {
166-
$errors.Add("Cannot run isolated TTS native stack probe because pwsh was not found.")
164+
$dotnet = Get-Command dotnet -ErrorAction SilentlyContinue
165+
if (-not $dotnet) {
166+
$errors.Add("Cannot run isolated TTS native stack probe because dotnet was not found.")
167167
return
168168
}
169169

170-
$probeScript = @'
171-
param(
172-
[Parameter(Mandatory = $true)]
173-
[string]$PayloadRoot
174-
)
170+
$probeProject = @'
171+
<Project Sdk="Microsoft.NET.Sdk">
172+
<PropertyGroup>
173+
<OutputType>Exe</OutputType>
174+
<TargetFramework>net10.0</TargetFramework>
175+
<ImplicitUsings>enable</ImplicitUsings>
176+
<Nullable>enable</Nullable>
177+
</PropertyGroup>
178+
</Project>
179+
'@
175180

176-
Set-StrictMode -Version Latest
177-
$ErrorActionPreference = "Stop"
178-
Set-Location $PayloadRoot
181+
$probeProgram = @'
182+
using System.Reflection;
179183
180-
$sherpaAsm = [System.Reflection.Assembly]::LoadFrom((Join-Path $PayloadRoot "sherpa-onnx.dll"))
181-
$versionType = $sherpaAsm.GetType("SherpaOnnx.VersionInfo", $true)
182-
$version = $versionType.GetProperty("Version").GetValue($null)
183-
if ([string]::IsNullOrWhiteSpace($version)) {
184-
throw "SherpaOnnx.VersionInfo.Version returned an empty version."
184+
if (args.Length != 1)
185+
{
186+
Console.Error.WriteLine("Expected payload root argument.");
187+
return 2;
185188
}
186189
187-
$onnxAsm = [System.Reflection.Assembly]::LoadFrom((Join-Path $PayloadRoot "Microsoft.ML.OnnxRuntime.dll"))
188-
$ortType = $onnxAsm.GetType("Microsoft.ML.OnnxRuntime.OrtEnv", $true)
189-
$instanceMethod = $ortType.GetMethod(
190-
"Instance",
191-
[System.Reflection.BindingFlags]::Public -bor [System.Reflection.BindingFlags]::Static,
192-
$null,
193-
[Type[]]@(),
194-
$null)
195-
if ($instanceMethod) {
196-
$env = $instanceMethod.Invoke($null, @())
197-
} else {
198-
$env = $ortType.GetProperty("Instance").GetValue($null)
190+
var payloadRoot = Path.GetFullPath(args[0]);
191+
Directory.SetCurrentDirectory(payloadRoot);
192+
193+
AppDomain.CurrentDomain.AssemblyResolve += (_, eventArgs) =>
194+
{
195+
var assemblyName = new AssemblyName(eventArgs.Name).Name;
196+
if (string.IsNullOrWhiteSpace(assemblyName))
197+
{
198+
return null;
199+
}
200+
201+
var candidate = Path.Combine(payloadRoot, assemblyName + ".dll");
202+
return File.Exists(candidate) ? Assembly.LoadFrom(candidate) : null;
203+
};
204+
205+
var sherpaAsm = Assembly.LoadFrom(Path.Combine(payloadRoot, "sherpa-onnx.dll"));
206+
var versionType = sherpaAsm.GetType("SherpaOnnx.VersionInfo", true)!;
207+
var version = versionType.GetProperty("Version")!.GetValue(null)?.ToString();
208+
if (string.IsNullOrWhiteSpace(version))
209+
{
210+
throw new InvalidOperationException("SherpaOnnx.VersionInfo.Version returned an empty version.");
199211
}
200212
201-
if ($null -eq $env) {
202-
throw "Microsoft.ML.OnnxRuntime.OrtEnv did not initialize."
213+
var onnxAsm = Assembly.LoadFrom(Path.Combine(payloadRoot, "Microsoft.ML.OnnxRuntime.dll"));
214+
var ortType = onnxAsm.GetType("Microsoft.ML.OnnxRuntime.OrtEnv", true)!;
215+
var instanceMethod = ortType.GetMethod(
216+
"Instance",
217+
BindingFlags.Public | BindingFlags.Static,
218+
binder: null,
219+
types: Type.EmptyTypes,
220+
modifiers: null);
221+
var env = instanceMethod is not null
222+
? instanceMethod.Invoke(null, null)
223+
: ortType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static)?.GetValue(null);
224+
225+
if (env is null)
226+
{
227+
throw new InvalidOperationException("Microsoft.ML.OnnxRuntime.OrtEnv did not initialize.");
203228
}
204229
205-
Write-Host "TTS native stack probe passed (Sherpa $version, ONNX Runtime initialized)."
230+
Console.WriteLine($"TTS native stack probe passed (Sherpa {version}, ONNX Runtime initialized).");
231+
return 0;
206232
'@
207233

208-
$probePath = Join-Path ([System.IO.Path]::GetTempPath()) ("openclaw-tts-native-probe-{0}.ps1" -f [Guid]::NewGuid().ToString("N"))
234+
$probeDir = Join-Path ([System.IO.Path]::GetTempPath()) ("openclaw-tts-native-probe-{0}" -f [Guid]::NewGuid().ToString("N"))
209235
try {
210-
Set-Content -LiteralPath $probePath -Value $probeScript -Encoding UTF8
211-
$output = & $pwsh.Source -NoProfile -ExecutionPolicy Bypass -File $probePath -PayloadRoot $payloadRoot 2>&1
236+
New-Item -ItemType Directory -Path $probeDir | Out-Null
237+
$projectPath = Join-Path $probeDir "OpenClaw.TtsNativeProbe.csproj"
238+
$programPath = Join-Path $probeDir "Program.cs"
239+
Set-Content -LiteralPath $projectPath -Value $probeProject -Encoding UTF8
240+
Set-Content -LiteralPath $programPath -Value $probeProgram -Encoding UTF8
241+
242+
$buildOutput = & $dotnet.Source build $projectPath -c Release -v:q 2>&1
243+
$buildExitCode = $LASTEXITCODE
244+
if ($buildExitCode -ne 0) {
245+
$tail = @($buildOutput | Select-Object -Last 12) -join " "
246+
$errors.Add("TTS native stack probe build failed with exit code $buildExitCode. $tail")
247+
return
248+
}
249+
250+
$probeDll = Join-Path $probeDir "bin\Release\net10.0\OpenClaw.TtsNativeProbe.dll"
251+
$output = & $dotnet.Source $probeDll $payloadRoot 2>&1
212252
$exitCode = $LASTEXITCODE
213253
} finally {
214-
try { if (Test-Path -LiteralPath $probePath) { Remove-Item -LiteralPath $probePath -Force } } catch { }
254+
try { if (Test-Path -LiteralPath $probeDir) { Remove-Item -LiteralPath $probeDir -Recurse -Force } } catch { }
215255
}
216256

217257
if ($exitCode -ne 0) {

0 commit comments

Comments
 (0)