diff --git a/Skills.md b/Skills.md index 304cb74..980fd23 100644 --- a/Skills.md +++ b/Skills.md @@ -9,6 +9,8 @@ - build.cmd publish:编译YAMA.exe且通过upx压缩,所生成的可执行文件较小。 - buld.cmd server:只编译YAMA.exe,需保证所依赖的客户端程序已经编译。 - build.cmd go-server:编译 Go 服务端,可以选择带publish 参数进行upx压缩。 +- build.cmd serverd:编译 Debug 版服务端(x64),输出 Bin\Yama_x64d.exe。 +- build.cmd client:编译 Debug 版客户端(x64),输出 x64\Debug\ghost.exe。 ## Go 服务端 diff --git a/build.cmd b/build.cmd index fefbb0d..6ca59d9 100644 --- a/build.cmd +++ b/build.cmd @@ -1,8 +1,10 @@ @echo off :: SimpleRemoter Quick Build Script -:: Usage: build.cmd [release|debug] [x64|x86|all] [server|clean|publish|go-server] +:: Usage: build.cmd [release|debug] [x64|x86|all] [server|clean|publish|go-server|serverd|client] :: go-server Build Go fallback server only -> Bin\YamaGo_x64.exe :: go-server publish Same, plus UPX --best compression +:: serverd Debug server only (x64) -> Bin\Yama_x64d.exe +:: client Debug client (x64) -> x64\Debug\ghost.exe setlocal enabledelayedexpansion @@ -21,6 +23,9 @@ 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) +:: 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) echo Unknown argument: %~1 shift goto :parse_args diff --git a/build.ps1 b/build.ps1 index 179b440..638b99d 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,9 +1,10 @@ -# SimpleRemoter Build Script -# Usage: .\build.ps1 [-Config Release|Debug] [-Platform x64|x86|all] [-ServerOnly] [-Clean] [-Publish] +# SimpleRemoter Build Script +# Usage: .\build.ps1 [-Config Release|Debug] [-Platform x64|x86|all] [-ServerOnly] [-ClientOnly] [-Clean] [-Publish] # # Requirements: # - Visual Studio 2019 or 2022 # - v142 toolset (MSVC v142 - VS 2019 C++ build tools) +# - ATL (C++ ATL for v142 build tools) # - MFC libraries (C++ MFC for v142 build tools) param( @@ -14,6 +15,7 @@ param( [string]$Platform = "x64", [switch]$ServerOnly, # Only build main server (Yama), skip client projects + [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 @@ -119,8 +121,27 @@ if ($GoServer) { exit 0 } +# 判断某个 VS 安装是否带 ATL/MFC 组件。ATL 头文件用 #pragma comment(lib, "atls.lib") +# 自动链接,只装了编译工具(BuildTools)的实例常常没有这一块:编译能过、链接报 +# LNK1104 无法打开 atls.lib。同机既装 BuildTools 又装 IDE 时,按路径取第一个会挑错。 +function Test-VcAtlPresent { + param([string]$VsRoot) + if (-not $VsRoot) { return $false } + $atlLib = Join-Path $VsRoot "VC\Tools\MSVC\*\atlmfc\lib\x86\atls.lib" + return [bool](Get-ChildItem $atlLib -ErrorAction SilentlyContinue | Select-Object -First 1) +} + +# 从 ...\MSBuild\Current\Bin\MSBuild.exe 反推 VS 安装根目录。 +function Get-VsRootFromMsBuild { + param([string]$MsBuildPath) + $idx = $MsBuildPath.IndexOf("\MSBuild\", [System.StringComparison]::OrdinalIgnoreCase) + if ($idx -lt 0) { return $null } + return $MsBuildPath.Substring(0, $idx) +} + # Find MSBuild (VS2019 or VS2022, including Insiders/Preview) -# Order: Prefer installations with v142 toolset (VS2019) over VS2022 BuildTools +# Order: Prefer installations with v142 toolset (VS2019) over VS2022 BuildTools, +# and within that prefer instances that actually carry ATL/MFC. $msBuildPaths = @( # VS2019 Insiders/Preview (non-standard path) - has v142 + MFC "${env:ProgramFiles}\Microsoft Visual Studio\18\*\MSBuild\Current\Bin\MSBuild.exe", @@ -134,12 +155,17 @@ $msBuildPaths = @( ) $msBuild = $null +$fallbackMsBuild = $null # 第一个找到的候选(可能不带 ATL),仅在没有带 ATL 的实例时兜底 foreach ($pattern in $msBuildPaths) { - $found = Get-ChildItem $pattern -ErrorAction SilentlyContinue | Select-Object -First 1 - if ($found) { - $msBuild = $found.FullName - break + foreach ($found in @(Get-ChildItem $pattern -ErrorAction SilentlyContinue)) { + if (-not $fallbackMsBuild) { $fallbackMsBuild = $found.FullName } + if (Test-VcAtlPresent (Get-VsRootFromMsBuild $found.FullName)) { + $msBuild = $found.FullName + break + } + Write-Host "Skipping MSBuild without ATL/MFC: $($found.FullName)" -ForegroundColor DarkYellow } + if ($msBuild) { break } } # 兜底:默认路径找不到(例如 VS 装在 D 盘)时,用 vswhere 反查。 @@ -147,19 +173,34 @@ foreach ($pattern in $msBuildPaths) { if (-not $msBuild) { $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" if (Test-Path $vswhere) { - $found = & $vswhere -latest -products * -requires Microsoft.Component.MSBuild ` - -find "MSBuild\**\Bin\MSBuild.exe" 2>$null | - Select-Object -First 1 - if ($found) { $msBuild = $found } + # 不能用 -requires Microsoft.VisualStudio.Component.VC.ATL 过滤组件 id: + # 各 VS 版本的 id 不一样(v142/v143/预览版),且预览实例可能根本查不到。 + # 因此列出全部实例,再逐个用 atls.lib 落地校验(上面那条 glob 只看得到 C 盘, + # VS 装在 D 盘时只能靠这里找到)。 + $hits = @(& $vswhere -products * -requires Microsoft.Component.MSBuild ` + -find "MSBuild\**\Bin\MSBuild.exe" 2>$null) + foreach ($hit in $hits) { + if (-not $hit) { continue } + if (-not $fallbackMsBuild) { $fallbackMsBuild = $hit } + if (Test-VcAtlPresent (Get-VsRootFromMsBuild $hit)) { $msBuild = $hit; break } + } } } +# 一个带 ATL 的实例都没有:仍用兜底候选,让 MSBuild 报出更具体的错误。 +if (-not $msBuild -and $fallbackMsBuild) { + Write-Host "WARNING: no VS instance with ATL/MFC found, using $fallbackMsBuild" -ForegroundColor Yellow + Write-Host " Install 'C++ ATL for v142 build tools' if linking fails on atls.lib." -ForegroundColor DarkGray + $msBuild = $fallbackMsBuild +} + if (-not $msBuild) { Write-Host "ERROR: MSBuild not found." -ForegroundColor Red Write-Host "" Write-Host "Please install Visual Studio 2019 or 2022 with:" -ForegroundColor Yellow Write-Host " - Desktop development with C++" -ForegroundColor White Write-Host " - MSVC v142 - VS 2019 C++ x64/x86 build tools" -ForegroundColor White + Write-Host " - C++ ATL for v142 build tools" -ForegroundColor White Write-Host " - C++ MFC for v142 build tools" -ForegroundColor White exit 1 } @@ -218,6 +259,9 @@ function Build-Project { Write-Host "If you see 'v142 build tools cannot be found':" -ForegroundColor Yellow Write-Host " Install 'MSVC v142 - VS 2019 C++ build tools' via VS Installer" -ForegroundColor White Write-Host "" + Write-Host "If you see 'LNK1104: cannot open file atls.lib':" -ForegroundColor Yellow + Write-Host " Install 'C++ ATL for v142 build tools' via VS Installer" -ForegroundColor White + Write-Host "" Write-Host "If you see 'MFC libraries are required':" -ForegroundColor Yellow Write-Host " Install 'C++ MFC for v142 build tools' via VS Installer" -ForegroundColor White exit 1 @@ -226,6 +270,54 @@ function Build-Project { Write-Host "OK: $Project" -ForegroundColor Green } +# Debug client fast path: build the client executable and stop. +# Only ghost is built — the other client projects (ServerDll, TestRun, TinyRun, +# SCLoader) exist to be embedded in the server and are irrelevant when the goal +# is debugging the client itself. +if ($ClientOnly) { + $clientProject = "ghost" + $clientPlatforms = if ($Platform -eq "all") { @("x86", "x64") } else { @($Platform) } + $startTime = Get-Date + + Write-Host "" + Write-Host "========================================" -ForegroundColor Cyan + Write-Host " SimpleRemoter Client Build" -ForegroundColor Cyan + Write-Host " Config: $Config" -ForegroundColor Cyan + Write-Host " Platform: $Platform" -ForegroundColor Cyan + Write-Host " VS: $vsYear" -ForegroundColor Cyan + Write-Host " Clean: $Clean" -ForegroundColor Cyan + Write-Host "========================================" -ForegroundColor Cyan + + foreach ($plat in $clientPlatforms) { + Build-Project -Project $clientProject -Configuration $Config -Platform $plat -ForceClean $Clean + } + + $elapsed = (Get-Date) - $startTime + + Write-Host "" + Write-Host "========================================" -ForegroundColor Green + Write-Host " Build Completed!" -ForegroundColor Green + Write-Host " Time: $($elapsed.TotalSeconds.ToString('F1')) seconds" -ForegroundColor Green + Write-Host "========================================" -ForegroundColor Green + + Write-Host "" + Write-Host "Output files:" -ForegroundColor Cyan + # VS default OutDir for this project: $(SolutionDir)$(Platform)\$(Configuration)\ + # x86 output lands in \Debug, x64 in \x64\Debug. + foreach ($plat in $clientPlatforms) { + $outDir = if ($plat -eq "x64") { Join-Path (Join-Path $rootDir "x64") $Config } else { Join-Path $rootDir $Config } + $clientOut = Join-Path $outDir "ghost.exe" + if (Test-Path $clientOut) { + $size = (Get-Item $clientOut).Length / 1MB + Write-Host " $clientOut ($($size.ToString('F2')) MB)" -ForegroundColor White + } else { + Write-Host " WARNING: expected output not found at $clientOut" -ForegroundColor Yellow + } + } + + exit 0 +} + # Determine platforms to build $platforms = if ($Platform -eq "all") { @("x86", "x64") } else { @($Platform) }