diff --git a/build.cmd b/build.cmd index 6ca59d9..1b0e0bf 100644 --- a/build.cmd +++ b/build.cmd @@ -1,8 +1,9 @@ @echo off :: 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 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 :: 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"=="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"=="server-linux" (set EXTRA_ARGS=!EXTRA_ARGS! -GoServerLinux& shift& goto :parse_args) :: 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"=="client" (set CONFIG=Debug& set PLATFORM=x64& set EXTRA_ARGS=!EXTRA_ARGS! -ClientOnly& shift& goto :parse_args) diff --git a/build.ps1 b/build.ps1 index 638b99d..cb2649a 100644 --- a/build.ps1 +++ b/build.ps1 @@ -18,7 +18,8 @@ param( [switch]$ClientOnly, # Only build the client executable (ghost), skip server [switch]$Clean, # Clean before build [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" @@ -32,11 +33,16 @@ $upxPath = Join-Path $rootDir "server\2015Remote\res\3rd\upx.exe" function Build-GoServer { param( [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 "Building Go server (server/go)..." -ForegroundColor Magenta + Write-Host "Building Go server (server/go) for $TargetOS..." -ForegroundColor Magenta $goCmd = Get-Command go -ErrorAction SilentlyContinue if (-not $goCmd) { @@ -63,14 +69,27 @@ function Build-GoServer { 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. $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 try { - $env:GOOS = "windows" + $env:GOOS = $TargetOS $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) { & go build -ldflags $ldflags -o $outFile ./cmd } else { @@ -79,6 +98,9 @@ function Build-GoServer { $code = $LASTEXITCODE } finally { Pop-Location + $env:GOOS = $oldGoos + $env:GOARCH = $oldGoarch + $env:CGO_ENABLED = $oldCgoEnabled } if ($code -ne 0) { @@ -92,7 +114,9 @@ function Build-GoServer { # In-place UPX compression. Failure is a warning, not an error — the # uncompressed binary is still usable, and UPX occasionally refuses on # 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 "UPX compressing Go server..." -ForegroundColor Magenta 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 binary too" (not the full C++ publish flow). -if ($GoServer) { - $ok = Build-GoServer -Configuration $Config -Compress:$Publish +# Go binary too" (not the full C++ publish flow). -GoServerLinux cross-compiles +# the same server for Linux into Bin\server_linux_amd64. +if ($GoServer -or $GoServerLinux) { + $targetOS = if ($GoServerLinux) { "linux" } else { "windows" } + $ok = Build-GoServer -Configuration $Config -Compress:$Publish -TargetOS $targetOS if (-not $ok) { exit 1 } exit 0 }