Files
baiqing 3414e1ff5e chore(release-prep): 修 P2 + 清理 noop bundle.resources override
完整审查 CI 流程后发现两类问题:

1. windows-build-gnu.ps1 不 build OpenLessIme.dll 也不 export
   OPENLESS_IME_DLL_X64 / _X86 env,但 NSIS hook (nsis/openless-ime-hooks.nsh)
   PREINSTALL 用 File "$%OPENLESS_IME_DLL_X64%" / _X86 引用 dll,
   makensis 编译时 env 为空 → File 路径无效 → NSIS bundle 失败。
   补 IME dll 双平台 (x64 / Win32) build + Set-Item Env:。
   (Codex PR #280 P2 review)

2. build-mac.sh 之前为绕过 bundle.resources 占位 dll 加的
   --config '{"bundle":{"resources":{}}}' override,
   PR #280 已删除 bundle.resources,此 override 退化为 noop,删除让命令更干净。

release-tauri.yml 还有 2 处同源遗留("复制 dll 到 openless-ime-payload"
死步骤、Linux build 同样的 noop override)需要 workflow scope 才能动,
留待下一个 PR。
2026-05-06 11:20:24 +08:00

109 lines
4.9 KiB
PowerShell

param(
[string]$MirrorRoot = "$env:TEMP\openless-windows-gnu",
[string]$ArtifactsRoot = "",
[switch]$KeepMirror
)
$ErrorActionPreference = "Stop"
$appRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
$buildRoot = $appRoot
$usedMirror = $false
if ([string]::IsNullOrWhiteSpace($ArtifactsRoot)) {
$ArtifactsRoot = Join-Path $appRoot ".artifacts\windows-gnu"
}
if ($appRoot -match "\s") {
Write-Host "[info] App path contains spaces: $appRoot"
Write-Host "[info] Mirroring to no-space scratch build root: $MirrorRoot"
New-Item -ItemType Directory -Force -Path $MirrorRoot | Out-Null
robocopy $appRoot $MirrorRoot /MIR /XD "$appRoot\.artifacts" "$appRoot\node_modules" "$appRoot\dist" "$appRoot\src-tauri\target" "$MirrorRoot\.artifacts" "$MirrorRoot\node_modules" "$MirrorRoot\dist" "$MirrorRoot\src-tauri\target" | Out-Host
if ($LASTEXITCODE -gt 7) {
throw "robocopy failed with exit code $LASTEXITCODE"
}
$buildRoot = (Resolve-Path $MirrorRoot).Path
$usedMirror = $true
}
$env:PATH = "$env:USERPROFILE\.cargo\bin;$env:USERPROFILE\scoop\persist\rustup\.cargo\bin;$env:USERPROFILE\scoop\apps\rustup\current\.cargo\bin;$env:USERPROFILE\scoop\apps\mingw\current\bin;$env:PATH"
$env:RUSTUP_TOOLCHAIN = "stable-x86_64-pc-windows-gnu"
$env:CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu"
function Resolve-WebView2Loader {
$cargoHome = if ($env:CARGO_HOME) { $env:CARGO_HOME } else { Join-Path $env:USERPROFILE ".cargo" }
$registrySrc = Join-Path $cargoHome "registry\src"
$loader = Get-ChildItem -Path $registrySrc -Recurse -Filter WebView2Loader.dll -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -match "\\x64\\WebView2Loader\.dll$" } |
Select-Object -First 1
if ($null -eq $loader) {
throw "WebView2Loader.dll x64 not found under $registrySrc"
}
return $loader.FullName
}
Push-Location $buildRoot
try {
if (-not (Test-Path "node_modules")) {
npm ci
}
npm run tauri build -- --target x86_64-pc-windows-gnu --no-bundle
$releaseRoot = Join-Path $buildRoot "src-tauri\target\x86_64-pc-windows-gnu\release"
$artifactDevRoot = Join-Path $ArtifactsRoot "dev"
New-Item -ItemType Directory -Force -Path $artifactDevRoot | Out-Null
Copy-Item -LiteralPath (Join-Path $releaseRoot "openless.exe") -Destination (Join-Path $artifactDevRoot "openless.exe") -Force
Copy-Item -LiteralPath (Resolve-WebView2Loader) -Destination (Join-Path $artifactDevRoot "WebView2Loader.dll") -Force
# Build OpenLessIme.dll (x64 + x86) 并导出绝对路径 env var——
# nsis/openless-ime-hooks.nsh 的 PREINSTALL 用 File "$%OPENLESS_IME_DLL_X64%" / _X86
# 在 makensis 编译时把 dll 嵌入 NSIS 包;wix/openless-ime.wxs 也用同一对 env 解析
# candle/light 的绝对路径(CI release-tauri.yml 同款做法)。
foreach ($t in @(
@{ Platform = 'x64'; Folder = 'x64'; EnvName = 'OPENLESS_IME_DLL_X64' },
@{ Platform = 'Win32'; Folder = 'x86'; EnvName = 'OPENLESS_IME_DLL_X86' }
)) {
$out = Join-Path $buildRoot "src-tauri\target\windows-ime-msvc\$($t.Folder)\Release"
$obj = Join-Path $buildRoot "src-tauri\target\windows-ime-msvc\obj\$($t.Folder)\Release"
& ./scripts/windows-ime-build.ps1 -Configuration Release -Platform $t.Platform -OutputDirectory $out -IntermediateDirectory $obj
if ($LASTEXITCODE -ne 0) {
throw "OpenLessIme $($t.Platform) build failed with exit $LASTEXITCODE"
}
$dll = (Resolve-Path (Join-Path $out 'OpenLessIme.dll')).Path
if (-not (Test-Path $dll)) {
throw "OpenLessIme.dll not produced at $dll"
}
Set-Item -Path "Env:$($t.EnvName)" -Value $dll
Write-Host "[ok] built $dll (exported $($t.EnvName))"
}
npm run tauri build -- --target x86_64-pc-windows-gnu --bundles msi nsis
} finally {
Pop-Location
}
$releaseRoot = Join-Path $buildRoot "src-tauri\target\x86_64-pc-windows-gnu\release"
$artifactReleaseRoot = Join-Path $ArtifactsRoot "release"
New-Item -ItemType Directory -Force -Path $artifactReleaseRoot | Out-Null
Remove-Item -LiteralPath (Join-Path $artifactReleaseRoot "openless.exe") -Force -ErrorAction SilentlyContinue
if (Test-Path (Join-Path $releaseRoot "bundle")) {
Copy-Item -LiteralPath (Join-Path $releaseRoot "bundle") -Destination $artifactReleaseRoot -Recurse -Force
}
if ($usedMirror -and (-not $KeepMirror)) {
$resolvedMirror = (Resolve-Path $MirrorRoot).Path
$resolvedTemp = (Resolve-Path $env:TEMP).Path
if ($resolvedMirror.StartsWith($resolvedTemp, [System.StringComparison]::OrdinalIgnoreCase) -and
((Split-Path $resolvedMirror -Leaf) -eq "openless-windows-gnu")) {
Write-Host "[info] Removing scratch build root: $resolvedMirror"
Remove-Item -LiteralPath $resolvedMirror -Recurse -Force
} else {
Write-Warning "Refusing to remove unexpected mirror path: $resolvedMirror"
}
}
Write-Host ""
Write-Host "Windows GNU artifacts:"
Write-Host "$ArtifactsRoot\dev\openless.exe"
Write-Host "$artifactReleaseRoot\bundle\msi"
Write-Host "$artifactReleaseRoot\bundle\nsis"