95 lines
2.6 KiB
PowerShell
95 lines
2.6 KiB
PowerShell
# Builds the whole package in the right order:
|
|
# 1. stage payload DLL
|
|
# 2. copy it next to the project so the loader can pack it as a resource
|
|
# 3. loader executable
|
|
#
|
|
# powershell -ExecutionPolicy Bypass -File build.ps1 [-Configuration Release] [-SkipPayload]
|
|
#
|
|
# Without -SkipPayload the result is a single self-contained ArDrvLoader.exe that
|
|
# carries ardrvstage.dll inside it and drops it into the stage dir at runtime.
|
|
|
|
param(
|
|
[ValidateSet("Debug", "Release")]
|
|
[string]$Configuration = "Release",
|
|
[switch]$SkipPayload,
|
|
[switch]$NoEmbed
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$msbuild = "C:\Program Files\Microsoft Visual Studio\18\Community\MSBuild\Current\Bin\MSBuild.exe"
|
|
|
|
if (-not (Test-Path -LiteralPath $msbuild))
|
|
{
|
|
throw "MSBuild not found: $msbuild"
|
|
}
|
|
|
|
$root = $PSScriptRoot
|
|
$payload = Join-Path $root "ardrvstage.dll"
|
|
|
|
if (-not $SkipPayload -and -not $NoEmbed)
|
|
{
|
|
Write-Host "== building stage payload ($Configuration) =="
|
|
& $msbuild (Join-Path $root "StageDll.vcxproj") /p:Configuration=$Configuration /p:Platform=x64 /m /v:minimal
|
|
|
|
if ($LASTEXITCODE -ne 0)
|
|
{
|
|
throw "stage payload build failed"
|
|
}
|
|
|
|
$built = Join-Path $root "x64\$Configuration\ardrvstage.dll"
|
|
|
|
if (-not (Test-Path -LiteralPath $built))
|
|
{
|
|
throw "payload not produced: $built"
|
|
}
|
|
|
|
Copy-Item -LiteralPath $built -Destination $payload -Force
|
|
Write-Host "== payload staged at $payload =="
|
|
}
|
|
else
|
|
{
|
|
Write-Host "== payload build skipped =="
|
|
}
|
|
|
|
Write-Host "== building loader ($Configuration) =="
|
|
|
|
$extra = @()
|
|
if ($NoEmbed) { $extra += "/p:EmbedPayload=false" }
|
|
|
|
& $msbuild (Join-Path $root "ArDrvLoader.vcxproj") /p:Configuration=$Configuration /p:Platform=x64 /m /v:minimal @extra
|
|
|
|
if ($LASTEXITCODE -ne 0)
|
|
{
|
|
throw "loader build failed"
|
|
}
|
|
|
|
$exe = Join-Path $root "x64\$Configuration\ArDrvLoader.exe"
|
|
|
|
if (-not (Test-Path -LiteralPath $exe))
|
|
{
|
|
throw "loader not produced: $exe"
|
|
}
|
|
|
|
$dll = Join-Path $root "x64\$Configuration\ardrvstage.dll"
|
|
|
|
# The payload only exists to be embedded. Drop the per-config copy so the output
|
|
# folder is not mistaken for something that has to ship alongside the exe.
|
|
if (Test-Path -LiteralPath $dll)
|
|
{
|
|
Remove-Item -LiteralPath $dll -Force -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
# Single-file deliverable.
|
|
$dist = Join-Path $root "dist\$Configuration"
|
|
New-Item -ItemType Directory -Force -Path $dist | Out-Null
|
|
Copy-Item -LiteralPath $exe -Destination (Join-Path $dist "ArDrvLoader.exe") -Force
|
|
|
|
$exeSize = (Get-Item -LiteralPath $exe).Length
|
|
|
|
Write-Host ""
|
|
Write-Host "single file : $dist\ArDrvLoader.exe ($exeSize bytes)"
|
|
Write-Host "build output: $exe (plus .pdb/.ipdb artifacts)"
|
|
|
|
exit 0
|