Package standalone state tool and client plugin

This commit is contained in:
2026-09-21 17:49:51 +08:00
parent c3d59123ce
commit a7c065eaa5
12 changed files with 333 additions and 96 deletions
+60 -24
View File
@@ -1,17 +1,43 @@
[CmdletBinding()]
param([switch]$SkipTests)
param(
[Parameter(Mandatory)]
[string]$GameDir,
[switch]$SkipTests
)
$ErrorActionPreference = 'Stop'
$root = $PSScriptRoot
$goRoot = Join-Path $root 'go'
$haskellRoot = Join-Path $root 'haskell'
$outputDir = Join-Path $root '.build\bin'
$embedDir = Join-Path $goRoot 'internal\statebridge\tool'
$embedTool = Join-Path $embedDir 'bd2-state.exe'
$localIdentityProject = Join-Path $root 'plugins\LocalIdentity\LocalIdentity.csproj'
$buildRoot = Join-Path $root '.build'
$packageParent = Join-Path $buildRoot 'package'
$packageDir = Join-Path $packageParent 'bd2server'
$packagePluginDir = Join-Path $packageDir 'plugins'
$packageGoDir = Join-Path $packageDir 'go'
$packageStateDir = Join-Path $packageDir 'data\state'
$archive = Join-Path $buildRoot 'bd2server-windows-x64.zip'
$GameDir = [IO.Path]::GetFullPath($GameDir)
if (-not (Test-Path -LiteralPath (Join-Path $GameDir 'BrownDust II.exe') -PathType Leaf)) {
throw "GameDir does not contain BrownDust II.exe: $GameDir"
}
$env:GOCACHE = Join-Path $goRoot '.cache\go-build'
New-Item -ItemType Directory -Force -Path $env:GOCACHE, $outputDir, $embedDir | Out-Null
if (Test-Path -LiteralPath $embedTool) { Remove-Item -LiteralPath $embedTool -Force }
New-Item -ItemType Directory -Force -Path $env:GOCACHE, $buildRoot | Out-Null
foreach ($target in @($packageParent, $archive)) {
if (Test-Path -LiteralPath $target) {
$resolved = [IO.Path]::GetFullPath($target)
$expectedRoot = [IO.Path]::GetFullPath($buildRoot) + [IO.Path]::DirectorySeparatorChar
if (-not $resolved.StartsWith($expectedRoot, [StringComparison]::OrdinalIgnoreCase)) {
throw "Refusing to remove unexpected build path: $resolved"
}
Remove-Item -LiteralPath $resolved -Recurse -Force
}
}
New-Item -ItemType Directory -Force -Path $packageDir, $packagePluginDir, $packageGoDir, $packageStateDir | Out-Null
Push-Location $root
try {
@@ -33,25 +59,35 @@ try {
}
$haskellTool = (cabal list-bin exe:bd2-state).Trim()
if ($LASTEXITCODE -ne 0 -or -not (Test-Path -LiteralPath $haskellTool)) {
throw 'cannot locate the Cabal-built bd2-state executable'
throw 'Cannot locate the Cabal-built bd2-state executable.'
}
Copy-Item -LiteralPath $haskellTool -Destination $embedTool -Force
Copy-Item -LiteralPath $haskellTool -Destination (Join-Path $packageDir 'bd2-state.exe') -Force
} finally { Pop-Location }
try {
Push-Location $goRoot
try {
if (-not $SkipTests) {
go test ./...
if ($LASTEXITCODE -ne 0) { throw "go test failed with exit code $LASTEXITCODE" }
go vet ./...
if ($LASTEXITCODE -ne 0) { throw "go vet failed with exit code $LASTEXITCODE" }
}
$output = Join-Path $outputDir 'bd2server.exe'
go build -tags embedded_state_tool -trimpath -ldflags '-s -w' -o $output .\cmd\bd2server
if ($LASTEXITCODE -ne 0) { throw "go build failed with exit code $LASTEXITCODE" }
Write-Host "Built single-file release: $output"
} finally { Pop-Location }
} finally {
if (Test-Path -LiteralPath $embedTool) { Remove-Item -LiteralPath $embedTool -Force }
dotnet build $localIdentityProject -c Release "-p:GameDir=$GameDir" --nologo
if ($LASTEXITCODE -ne 0) { throw "LocalIdentity build failed with exit code $LASTEXITCODE" }
$identityPlugin = Join-Path $root 'plugins\LocalIdentity\bin\Release\netstandard2.1\BD2LocalIdentity.dll'
if (-not (Test-Path -LiteralPath $identityPlugin -PathType Leaf)) {
throw "LocalIdentity build output is missing: $identityPlugin"
}
Copy-Item -LiteralPath $identityPlugin -Destination (Join-Path $packagePluginDir 'BD2LocalIdentity.dll') -Force
Push-Location $goRoot
try {
if (-not $SkipTests) {
go test ./...
if ($LASTEXITCODE -ne 0) { throw "go test failed with exit code $LASTEXITCODE" }
go vet ./...
if ($LASTEXITCODE -ne 0) { throw "go vet failed with exit code $LASTEXITCODE" }
}
go build -trimpath -ldflags '-s -w' -o (Join-Path $packageDir 'bd2server.exe') .\cmd\bd2server
if ($LASTEXITCODE -ne 0) { throw "go build failed with exit code $LASTEXITCODE" }
} finally { Pop-Location }
Copy-Item -LiteralPath (Join-Path $goRoot 'seed') -Destination (Join-Path $packageGoDir 'seed') -Recurse -Force
Copy-Item -LiteralPath (Join-Path $root 'RELEASE.md') -Destination (Join-Path $packageDir 'README.md') -Force
Copy-Item -LiteralPath (Join-Path $root 'LICENSE') -Destination (Join-Path $packageDir 'LICENSE') -Force
Compress-Archive -LiteralPath $packageDir -DestinationPath $archive -CompressionLevel Optimal
Write-Host "Built release directory: $packageDir"
Write-Host "Built release archive: $archive"