V13
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Windows equivalent of build_core.sh - builds the Go core binaries.
|
||||
|
||||
.DESCRIPTION
|
||||
Cross-compiles the Android ARM64 client (dropped into android\lib\arm64-v8a\
|
||||
as libdragontcp_client.so) and the Linux AMD64/ARM64 servers.
|
||||
CGO is disabled, so no C toolchain or NDK is required.
|
||||
|
||||
.EXAMPLE
|
||||
.\build_core.ps1
|
||||
.\build_core.ps1 -ClientOnly
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
# Only build the Android client .so (skip the Linux servers).
|
||||
[switch]$ClientOnly,
|
||||
# Path to the go executable.
|
||||
[string]$GoBin = $(if ($env:GO_BIN) { $env:GO_BIN } else { 'go' })
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$Root = $PSScriptRoot
|
||||
|
||||
function Invoke-Go {
|
||||
param([hashtable]$Env, [string[]]$GoArgs)
|
||||
$saved = @{}
|
||||
foreach ($k in $Env.Keys) {
|
||||
$saved[$k] = [Environment]::GetEnvironmentVariable($k)
|
||||
[Environment]::SetEnvironmentVariable($k, $Env[$k])
|
||||
}
|
||||
try {
|
||||
& $GoBin @GoArgs
|
||||
if ($LASTEXITCODE -ne 0) { throw "go build failed (exit $LASTEXITCODE)" }
|
||||
} finally {
|
||||
foreach ($k in $saved.Keys) { [Environment]::SetEnvironmentVariable($k, $saved[$k]) }
|
||||
}
|
||||
}
|
||||
|
||||
$go = Get-Command $GoBin -ErrorAction SilentlyContinue
|
||||
if (-not $go) { throw "Go compiler not found. Install from https://go.dev/dl/ or set -GoBin." }
|
||||
|
||||
New-Item -ItemType Directory -Force -Path "$Root\bin", "$Root\android\lib\arm64-v8a" | Out-Null
|
||||
Push-Location "$Root\core"
|
||||
try {
|
||||
$ldflags = '-ldflags=-s -w'
|
||||
|
||||
Write-Host '[core] Android ARM64 client...' -ForegroundColor Cyan
|
||||
Invoke-Go @{ CGO_ENABLED = '0'; GOOS = 'android'; GOARCH = 'arm64' } `
|
||||
@('build', '-trimpath', $ldflags, '-o', "$Root\android\lib\arm64-v8a\libdragontcp_client.so", './cmd/dragontcp-client')
|
||||
|
||||
if (-not $ClientOnly) {
|
||||
Write-Host '[core] Linux AMD64 server...' -ForegroundColor Cyan
|
||||
Invoke-Go @{ CGO_ENABLED = '0'; GOOS = 'linux'; GOARCH = 'amd64' } `
|
||||
@('build', '-trimpath', $ldflags, '-o', "$Root\bin\dragontcp-hybrid-server-linux-amd64", './cmd/dragontcp-server')
|
||||
|
||||
Write-Host '[core] Linux ARM64 server...' -ForegroundColor Cyan
|
||||
Invoke-Go @{ CGO_ENABLED = '0'; GOOS = 'linux'; GOARCH = 'arm64' } `
|
||||
@('build', '-trimpath', $ldflags, '-o', "$Root\bin\dragontcp-hybrid-server-linux-arm64", './cmd/dragontcp-server')
|
||||
}
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
Write-Host 'Core build complete.' -ForegroundColor Green
|
||||
Reference in New Issue
Block a user