Files
kdletters fdc48aa573
Project CI / AI game creator shell Rust shard 1/4 (push) Failing after 17s
Project CI / AI game creator shell Rust shard 4/4 (push) Failing after 18s
Project CI / AI game creator shell Rust shard 3/4 (push) Failing after 18s
Project CI / AI game creator shell Rust shard 2/4 (push) Failing after 18s
Project CI / Backend tests (push) Failing after 17s
Project CI / AI game creator shell Rust smoke (push) Failing after 19s
Project CI / Native shell tests (push) Failing after 18s
Project CI / AI game creator shell Rust crates (push) Failing after 18s
Project CI / Frontend tests (push) Failing after 6s
Project CI / AI game creator shell web tests (push) Failing after 11s
Project CI / Repository checks (push) Failing after 11s
将 Godot 原生引导迁移到官方 C++ 绑定
使用固定版本 godot-cpp 替换手写 C ABI 引导并保留执行协议
采用 MSVC 与 CMake 构建,校验依赖归档和源码缓存
修复动态卸载时的实例绑定与单例包装生命周期
补充构建缓存测试、实机验收结果及分发文档
2026-09-20 22:00:44 +08:00

74 lines
5.2 KiB
PowerShell

param(
[string]$CMake = 'cmake.exe',
[string]$Python = 'python.exe',
[string]$Generator = 'Visual Studio 17 2022',
[ValidateRange(1, 32)][int]$Jobs = 4
)
$ErrorActionPreference = 'Stop'
$root = $PSScriptRoot
if ([Environment]::OSVersion.Platform -ne [PlatformID]::Win32NT -or -not [Environment]::Is64BitProcess) {
throw 'Godot editor payload requires Windows x64.'
}
$CMake = (Get-Command $CMake -ErrorAction Stop).Source
$Python = (Get-Command $Python -ErrorAction Stop).Source
$build = Join-Path $root '.build/msvc'
$generated = Join-Path $root '.build/generated'
$output = Join-Path $root 'bin/win-x64'
New-Item -ItemType Directory -Path $generated,$output -Force | Out-Null
$utf8 = [Text.UTF8Encoding]::new($false)
$previousBytecode = $env:PYTHONDONTWRITEBYTECODE
try {
$env:PYTHONDONTWRITEBYTECODE = '1'
$dependency = & $Python -X utf8 (Join-Path $root 'prepare_dependencies.py')
if ($LASTEXITCODE -ne 0) { throw 'Pinned godot-cpp dependency verification failed.' }
& $CMake -S $root -B $build -G $Generator -A x64 "-DAGC_GODOT_CPP_SOURCE=$dependency" "-DAGC_GENERATED_DIR=$generated" "-DPython3_EXECUTABLE=$Python"
if ($LASTEXITCODE -ne 0) { throw 'Godot C++ configure failed; install Visual Studio C++ x64, CMake and Python.' }
$compilerRecords = @(Get-ChildItem -LiteralPath (Join-Path $build 'CMakeFiles') -Filter 'CMakeCXXCompiler.cmake' -Recurse -File)
if ($compilerRecords.Count -ne 1) { throw 'MSVC compiler identity is ambiguous.' }
$record = [IO.File]::ReadAllText($compilerRecords[0].FullName)
$compilerMatch = [regex]::Match($record, 'set\(CMAKE_CXX_COMPILER "([^"]+)"\)')
if (-not $compilerMatch.Success -or -not $record.Contains('set(CMAKE_CXX_COMPILER_ID "MSVC")')) { throw 'MSVC compiler identity was not verified.' }
$compiler = $compilerMatch.Groups[1].Value
$inputs = @('src/native.cpp','src/bridge.gd','CMakeLists.txt','build-profile.json','prepare_dependencies.py','vendor/provenance.json','vendor/LICENSE.txt','build.ps1')
$fingerprint = 'agc.godot.editor.v1/windows/x86_64/c++17/msvc/Release/static-crt' + "`n"
$fingerprint += 'compiler:' + (Get-FileHash -LiteralPath $compiler -Algorithm SHA256).Hash.ToLowerInvariant() + "`n"
$fingerprint += 'cmake:' + (Get-FileHash -LiteralPath $CMake -Algorithm SHA256).Hash.ToLowerInvariant() + "`n"
$fingerprint += 'configuration:' + (Get-FileHash -LiteralPath (Join-Path $build 'CMakeCache.txt') -Algorithm SHA256).Hash.ToLowerInvariant() + "`n"
$fingerprint += 'toolchain:' + (Get-FileHash -LiteralPath $compilerRecords[0].FullName -Algorithm SHA256).Hash.ToLowerInvariant() + "`n"
foreach ($relative in $inputs) { $fingerprint += $relative + ':' + (Get-FileHash -LiteralPath (Join-Path $root $relative) -Algorithm SHA256).Hash.ToLowerInvariant() + "`n" }
$hasher = [Security.Cryptography.SHA256]::Create()
try { $buildId = 'sha256:' + ([BitConverter]::ToString($hasher.ComputeHash($utf8.GetBytes($fingerprint))).Replace('-','').ToLowerInvariant()) } finally { $hasher.Dispose() }
$dll = Join-Path $output 'agc_godot_editor.dll'
$metadataPath = Join-Path $output 'metadata.json'
if ((Test-Path -LiteralPath $dll) -and (Test-Path -LiteralPath $metadataPath)) {
$existing = Get-Content -LiteralPath $metadataPath -Raw | ConvertFrom-Json
if ($existing.protocol -eq 'agc.godot.editor.v1' -and $existing.entrySymbol -eq 'agc_godot_editor_init' -and $existing.platform -eq 'windows' -and $existing.arch -eq 'x86_64' -and $existing.minimumGodotVersion -eq '4.7' -and $existing.buildId -eq $buildId -and $existing.sha256 -eq (Get-FileHash -LiteralPath $dll -Algorithm SHA256).Hash.ToLowerInvariant()) {
Write-Output "Native C++ payload is current: $buildId"
return
}
}
$script = [IO.File]::ReadAllBytes((Join-Path $root 'src/bridge.gd'))
$embedded = [Text.StringBuilder]::new()
[void]$embedded.AppendLine('#define AGC_BUILD_ID "' + $buildId + '"')
[void]$embedded.AppendLine('static const unsigned char AGC_EMBEDDED_BRIDGE[] = {')
for ($index = 0; $index -lt $script.Length; $index += 32) {
$last = [Math]::Min($index + 31, $script.Length - 1)
[void]$embedded.AppendLine(($script[$index..$last] -join ',') + ',')
}
[void]$embedded.AppendLine('0};')
$header = Join-Path $generated 'embedded_bridge.h'
if (-not (Test-Path -LiteralPath $header) -or [IO.File]::ReadAllText($header) -ne $embedded.ToString()) { [IO.File]::WriteAllText($header, $embedded.ToString(), $utf8) }
& $CMake --build $build --config Release --target agc_godot_editor --parallel $Jobs
if ($LASTEXITCODE -ne 0) { throw 'Godot C++ MSVC build failed.' }
Copy-Item -LiteralPath (Join-Path $build 'payload/agc_godot_editor.dll') -Destination $dll -Force
$metadata = [ordered]@{
protocol = 'agc.godot.editor.v1'; buildId = $buildId
sha256 = (Get-FileHash -LiteralPath $dll -Algorithm SHA256).Hash.ToLowerInvariant()
platform = 'windows'; arch = 'x86_64'; entrySymbol = 'agc_godot_editor_init'; minimumGodotVersion = '4.7'
}
[IO.File]::WriteAllText($metadataPath, ($metadata | ConvertTo-Json) + "`n", $utf8)
Write-Output "Built C++ payload: $buildId"
} finally {
$env:PYTHONDONTWRITEBYTECODE = $previousBytecode
}