Build: add server-linux target for cross-compiling the Go server
`build server-linux` now builds the Go server as a Linux/amd64 binary at Bin\server_linux_amd64 instead of the Windows YamaGo_x64.exe, so the artifact can be copied to a Linux host as-is. It reuses the go-server flow: web asset sync, Release builds strip with -s -w (debug keeps symbols), and the caller's GOOS/GOARCH/CGO_ENABLED are restored afterwards so a direct .\build.ps1 run does not leak the cross-compile environment into later builds. UPX compression is skipped for Linux output (the script only ships upx.exe for the Windows build) and logs a warning instead. Verified: the generated binary is a stripped static ELF that runs under WSL and prints its flags. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
81f0d6c031
commit
23fb50b7d4
2 files changed
+38
-10
No files matched your search
@@ -1,8 +1,9 @@
|
|||||||
@echo off
|
@echo off
|
||||||
:: SimpleRemoter Quick Build Script
|
:: SimpleRemoter Quick Build Script
|
||||||
:: Usage: build.cmd [release|debug] [x64|x86|all] [server|clean|publish|go-server|serverd|client]
|
:: Usage: build.cmd [release|debug] [x64|x86|all] [server|clean|publish|go-server|server-linux|serverd|client]
|
||||||
:: go-server Build Go fallback server only -> Bin\YamaGo_x64.exe
|
:: go-server Build Go fallback server only -> Bin\YamaGo_x64.exe
|
||||||
:: go-server publish Same, plus UPX --best compression
|
:: go-server publish Same, plus UPX --best compression
|
||||||
|
:: server-linux Cross-compile Go server for Linux -> Bin\server_linux_amd64
|
||||||
:: serverd Debug server only (x64) -> Bin\Yama_x64d.exe
|
:: serverd Debug server only (x64) -> Bin\Yama_x64d.exe
|
||||||
:: client Debug client (x64) -> x64\Debug\ghost.exe
|
:: client Debug client (x64) -> x64\Debug\ghost.exe
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ if /i "%~1"=="server" (set EXTRA_ARGS=!EXTRA_ARGS! -ServerOnly& shift& goto :par
|
|||||||
if /i "%~1"=="clean" (set EXTRA_ARGS=!EXTRA_ARGS! -Clean& shift& goto :parse_args)
|
if /i "%~1"=="clean" (set EXTRA_ARGS=!EXTRA_ARGS! -Clean& shift& goto :parse_args)
|
||||||
if /i "%~1"=="publish" (set EXTRA_ARGS=!EXTRA_ARGS! -Publish& shift& goto :parse_args)
|
if /i "%~1"=="publish" (set EXTRA_ARGS=!EXTRA_ARGS! -Publish& shift& goto :parse_args)
|
||||||
if /i "%~1"=="go-server" (set EXTRA_ARGS=!EXTRA_ARGS! -GoServer& shift& goto :parse_args)
|
if /i "%~1"=="go-server" (set EXTRA_ARGS=!EXTRA_ARGS! -GoServer& shift& goto :parse_args)
|
||||||
|
if /i "%~1"=="server-linux" (set EXTRA_ARGS=!EXTRA_ARGS! -GoServerLinux& shift& goto :parse_args)
|
||||||
:: Debug presets: serverd = debug server x64 only, client = debug ghost x64 only
|
:: Debug presets: serverd = debug server x64 only, client = debug ghost x64 only
|
||||||
if /i "%~1"=="serverd" (set CONFIG=Debug& set PLATFORM=x64& set EXTRA_ARGS=!EXTRA_ARGS! -ServerOnly& shift& goto :parse_args)
|
if /i "%~1"=="serverd" (set CONFIG=Debug& set PLATFORM=x64& set EXTRA_ARGS=!EXTRA_ARGS! -ServerOnly& shift& goto :parse_args)
|
||||||
if /i "%~1"=="client" (set CONFIG=Debug& set PLATFORM=x64& set EXTRA_ARGS=!EXTRA_ARGS! -ClientOnly& shift& goto :parse_args)
|
if /i "%~1"=="client" (set CONFIG=Debug& set PLATFORM=x64& set EXTRA_ARGS=!EXTRA_ARGS! -ClientOnly& shift& goto :parse_args)
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ param(
|
|||||||
[switch]$ClientOnly, # Only build the client executable (ghost), skip server
|
[switch]$ClientOnly, # Only build the client executable (ghost), skip server
|
||||||
[switch]$Clean, # Clean before build
|
[switch]$Clean, # Clean before build
|
||||||
[switch]$Publish, # Publish mode: rebuild all deps + x64 Release + UPX compress
|
[switch]$Publish, # Publish mode: rebuild all deps + x64 Release + UPX compress
|
||||||
[switch]$GoServer # Build Go fallback server (server/go) -> Bin/YamaGo_x64.exe
|
[switch]$GoServer, # Build Go fallback server (server/go) -> Bin/YamaGo_x64.exe
|
||||||
|
[switch]$GoServerLinux # Cross-compile the Go server for Linux -> Bin/server_linux_amd64
|
||||||
)
|
)
|
||||||
|
|
||||||
$ErrorActionPreference = "Stop"
|
$ErrorActionPreference = "Stop"
|
||||||
@@ -32,11 +33,16 @@ $upxPath = Join-Path $rootDir "server\2015Remote\res\3rd\upx.exe"
|
|||||||
function Build-GoServer {
|
function Build-GoServer {
|
||||||
param(
|
param(
|
||||||
[string]$Configuration,
|
[string]$Configuration,
|
||||||
[switch]$Compress
|
[switch]$Compress,
|
||||||
|
# "linux" cross-compiles an ELF binary from Windows (CGO off). Output
|
||||||
|
# name matches the ReadMe/Makefile convention so the artifact can be
|
||||||
|
# scp'd as-is.
|
||||||
|
[ValidateSet("windows", "linux")]
|
||||||
|
[string]$TargetOS = "windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host "Building Go server (server/go)..." -ForegroundColor Magenta
|
Write-Host "Building Go server (server/go) for $TargetOS..." -ForegroundColor Magenta
|
||||||
|
|
||||||
$goCmd = Get-Command go -ErrorAction SilentlyContinue
|
$goCmd = Get-Command go -ErrorAction SilentlyContinue
|
||||||
if (-not $goCmd) {
|
if (-not $goCmd) {
|
||||||
@@ -63,14 +69,27 @@ function Build-GoServer {
|
|||||||
|
|
||||||
if (-not (Test-Path $binDir)) { New-Item -ItemType Directory -Path $binDir -Force | Out-Null }
|
if (-not (Test-Path $binDir)) { New-Item -ItemType Directory -Path $binDir -Force | Out-Null }
|
||||||
|
|
||||||
$outFile = Join-Path $binDir "YamaGo_x64.exe"
|
$outFile = if ($TargetOS -eq "linux") {
|
||||||
|
Join-Path $binDir "server_linux_amd64"
|
||||||
|
} else {
|
||||||
|
Join-Path $binDir "YamaGo_x64.exe"
|
||||||
|
}
|
||||||
# Release strips debug info for smaller binary; Debug keeps symbols.
|
# Release strips debug info for smaller binary; Debug keeps symbols.
|
||||||
$ldflags = if ($Configuration -eq "Debug") { "" } else { "-s -w" }
|
$ldflags = if ($Configuration -eq "Debug") { "" } else { "-s -w" }
|
||||||
|
|
||||||
|
# Save the caller's Go env so a direct .\build.ps1 invocation does not
|
||||||
|
# leave GOOS=linux behind for later builds in the same shell.
|
||||||
|
$oldGoos = $env:GOOS
|
||||||
|
$oldGoarch = $env:GOARCH
|
||||||
|
$oldCgoEnabled = $env:CGO_ENABLED
|
||||||
|
|
||||||
Push-Location $goDir
|
Push-Location $goDir
|
||||||
try {
|
try {
|
||||||
$env:GOOS = "windows"
|
$env:GOOS = $TargetOS
|
||||||
$env:GOARCH = "amd64"
|
$env:GOARCH = "amd64"
|
||||||
|
# Cross-compiling for Linux requires a pure-Go build; the server has
|
||||||
|
# no cgo dependencies, so this is the normal configuration.
|
||||||
|
if ($TargetOS -eq "linux") { $env:CGO_ENABLED = "0" }
|
||||||
if ($ldflags) {
|
if ($ldflags) {
|
||||||
& go build -ldflags $ldflags -o $outFile ./cmd
|
& go build -ldflags $ldflags -o $outFile ./cmd
|
||||||
} else {
|
} else {
|
||||||
@@ -79,6 +98,9 @@ function Build-GoServer {
|
|||||||
$code = $LASTEXITCODE
|
$code = $LASTEXITCODE
|
||||||
} finally {
|
} finally {
|
||||||
Pop-Location
|
Pop-Location
|
||||||
|
$env:GOOS = $oldGoos
|
||||||
|
$env:GOARCH = $oldGoarch
|
||||||
|
$env:CGO_ENABLED = $oldCgoEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($code -ne 0) {
|
if ($code -ne 0) {
|
||||||
@@ -92,7 +114,9 @@ function Build-GoServer {
|
|||||||
# In-place UPX compression. Failure is a warning, not an error — the
|
# In-place UPX compression. Failure is a warning, not an error — the
|
||||||
# uncompressed binary is still usable, and UPX occasionally refuses on
|
# uncompressed binary is still usable, and UPX occasionally refuses on
|
||||||
# certain PE sections.
|
# certain PE sections.
|
||||||
if ($Compress) {
|
if ($Compress -and $TargetOS -ne "windows") {
|
||||||
|
Write-Host "WARNING: UPX compression is skipped for $TargetOS output (script ships upx.exe only for the Windows build)." -ForegroundColor Yellow
|
||||||
|
} elseif ($Compress) {
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host "UPX compressing Go server..." -ForegroundColor Magenta
|
Write-Host "UPX compressing Go server..." -ForegroundColor Magenta
|
||||||
if (-not (Test-Path $upxPath)) {
|
if (-not (Test-Path $upxPath)) {
|
||||||
@@ -114,9 +138,11 @@ function Build-GoServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Go-only fast path: skip MSBuild entirely. -Publish here means "compress the
|
# Go-only fast path: skip MSBuild entirely. -Publish here means "compress the
|
||||||
# Go binary too" (not the full C++ publish flow).
|
# Go binary too" (not the full C++ publish flow). -GoServerLinux cross-compiles
|
||||||
if ($GoServer) {
|
# the same server for Linux into Bin\server_linux_amd64.
|
||||||
$ok = Build-GoServer -Configuration $Config -Compress:$Publish
|
if ($GoServer -or $GoServerLinux) {
|
||||||
|
$targetOS = if ($GoServerLinux) { "linux" } else { "windows" }
|
||||||
|
$ok = Build-GoServer -Configuration $Config -Compress:$Publish -TargetOS $targetOS
|
||||||
if (-not $ok) { exit 1 }
|
if (-not $ok) { exit 1 }
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user