本地打包每次都要等很久,其中编译这一段有两处纯粹的重复劳动。 Visual Studio 生成器把 ZERO_CHECK 接进了每个目标,CMakeLists.txt 变化时 构建会自己重新生成,所以已有 CMake 缓存时前置的 cmake --preset 不改变任何 结果,只是每个构建目录白等约 10 秒,三个目录就是 30 秒。改成缓存存在就跳过, 需要强制重跑(改了 preset、换了工具链)时传 -Reconfigure。 构建目标也从 ALL_BUILD 收窄到 MetasequoiaImeServer / MetasequoiaImeTsf。 原先会一并构建 MetasequoiaImeServerTests、test_webview_contract、 test_windows_ipc_contract,而 Prepare-PackageFiles.ps1 随后又把它们从包里 删掉。server 目标的依赖闭包已经覆盖 Watchdog、三个面板、Settings、 DictionaryReplay 和 OpenCC 词典,产物一个不少。要连测试一起构建(比如为了 跑 ctest)传 -Target ALL_BUILD,server/AGENTS.md 里的 ctest 段落已注明。 顺带给 cmake --build 加上 --parallel,真正有代码改动时也能并行。 无改动时的增量编译:TSF 18.0s -> 3.7s,Server 21.9s -> 10.9s。 CI 不受影响,它直接调 cmake,不经过这些脚本。
32 lines
1.9 KiB
PowerShell
32 lines
1.9 KiB
PowerShell
# Configure and build the Server; do not reuse old binaries after a failed build.
|
|
[CmdletBinding()]
|
|
param(
|
|
[string]$ManifestTool = 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\mt.exe',
|
|
# ALL_BUILD also builds MetasequoiaImeServerTests and test_webview_contract, which the packaging
|
|
# step deletes again. The server target already depends on the watchdog, the three panels,
|
|
# Settings, DictionaryReplay and the OpenCC dictionaries, so it produces exactly the packaged
|
|
# set. The test jobs still build everything by passing -Target ALL_BUILD.
|
|
[string]$Target = 'MetasequoiaImeServer',
|
|
# The Visual Studio generator wires ZERO_CHECK into every target, so a build regenerates itself
|
|
# whenever CMakeLists.txt changes. Re-running configure up front only costs ~10s without
|
|
# changing the result, so do it once and let ZERO_CHECK handle the rest.
|
|
[switch]$Reconfigure
|
|
)
|
|
$ErrorActionPreference = 'Stop'
|
|
$projectRoot = Split-Path -Parent $PSScriptRoot
|
|
$buildDirectory = Join-Path $projectRoot 'build-release'
|
|
Push-Location $projectRoot
|
|
try {
|
|
if ($Reconfigure -or -not (Test-Path -LiteralPath (Join-Path $buildDirectory 'CMakeCache.txt'))) {
|
|
cmake --preset=vcpkg-release
|
|
if ($LASTEXITCODE -ne 0) { throw "Server configure failed ($LASTEXITCODE)" }
|
|
}
|
|
cmake --build $buildDirectory --config Release --target $Target --parallel
|
|
if ($LASTEXITCODE -ne 0) { throw "Server build failed ($LASTEXITCODE)" }
|
|
# Keep the local SDK selection; the complete resource argument must reach mt.exe as one value.
|
|
$binary = Join-Path $buildDirectory 'bin/Release/MetasequoiaImeServer.exe'
|
|
& $ManifestTool `
|
|
-manifest (Join-Path $projectRoot 'MetasequoiaImeServer.manifest') "-outputresource:$binary;1"
|
|
if ($LASTEXITCODE -ne 0) { throw "Server manifest embedding failed ($LASTEXITCODE)" }
|
|
} finally { Pop-Location }
|