Initial commit
This commit is contained in:
38
tools/package.ps1
Normal file
38
tools/package.ps1
Normal file
@@ -0,0 +1,38 @@
|
||||
param(
|
||||
[ValidatePattern('^[A-Za-z0-9_]+(-[A-Za-z0-9_]+)+$')]
|
||||
[string]$Target = "x86_64-pc-windows-msvc"
|
||||
)
|
||||
$ErrorActionPreference = "Stop"
|
||||
$project = Split-Path $PSScriptRoot -Parent
|
||||
Push-Location $project
|
||||
try {
|
||||
$rustInfo = rustc -vV
|
||||
if ($LASTEXITCODE -ne 0) { throw "Could not determine Rust host target" }
|
||||
$hostTarget = (($rustInfo | Select-String '^host: ').ToString() -replace '^host: ', '')
|
||||
$targetDir = if ($env:CARGO_TARGET_DIR) { $env:CARGO_TARGET_DIR } else { "target" }
|
||||
$executable = if ($Target -match '-windows-') { "first_person_maze.exe" } else { "first_person_maze" }
|
||||
if ($Target -eq $hostTarget) {
|
||||
cargo build --release --locked
|
||||
$binary = Join-Path $targetDir "release/$executable"
|
||||
} else {
|
||||
cargo build --release --locked --target $Target
|
||||
$binary = Join-Path $targetDir "$Target/release/$executable"
|
||||
}
|
||||
if ($LASTEXITCODE -ne 0) { throw "Cargo build failed" }
|
||||
if (-not (Test-Path -LiteralPath $binary -PathType Leaf)) { throw "Missing binary: $binary" }
|
||||
$releaseRoot = [System.IO.Path]::GetFullPath((Join-Path $project "release"))
|
||||
$destination = [System.IO.Path]::GetFullPath((Join-Path $releaseRoot "$Target/first_person_maze"))
|
||||
if (-not $destination.StartsWith($releaseRoot + [System.IO.Path]::DirectorySeparatorChar, [System.StringComparison]::OrdinalIgnoreCase)) {
|
||||
throw "Package destination is outside the release directory"
|
||||
}
|
||||
if (Test-Path -LiteralPath $destination) {
|
||||
Remove-Item -LiteralPath $destination -Recurse -Force
|
||||
}
|
||||
New-Item -ItemType Directory -Force -Path $destination | Out-Null
|
||||
Copy-Item -LiteralPath $binary -Destination $destination
|
||||
$audioDestination = Join-Path $destination "assets/audio"
|
||||
New-Item -ItemType Directory -Force -Path $audioDestination | Out-Null
|
||||
Get-ChildItem -LiteralPath "assets/audio" -Filter "*.wav" -File | Copy-Item -Destination $audioDestination
|
||||
Copy-Item -LiteralPath "README.md" -Destination $destination
|
||||
Write-Host "Package: $destination"
|
||||
} finally { Pop-Location }
|
||||
Reference in New Issue
Block a user