-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbuild.ps1
More file actions
204 lines (167 loc) · 6.06 KB
/
Copy pathbuild.ps1
File metadata and controls
204 lines (167 loc) · 6.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<#
.SYNOPSIS
Windows build helpers for the Bevy client. Mirror of the Mac/Linux
Makefile, just the targets that make sense on a Windows host.
.EXAMPLE
.\build.ps1 build-win
.\build.ps1 package-win
.\build.ps1 publish-win
.\build.ps1 publish-win -Version 1.2.3
#>
[CmdletBinding()]
param(
[Parameter(Position = 0)]
[ValidateSet(
'help', 'build', 'run', 'verify',
'build-win', 'package-win',
'publish-win', 'butler-status',
'clean'
)]
[string]$Target = 'help',
[string]$Bin = 'client_bevy',
[string]$Cargo = 'cargo',
[string]$Version,
[string]$ItchUser = 'kalcode',
[string]$ItchGame = 'the-space-project'
)
$ErrorActionPreference = 'Stop'
Set-Location $PSScriptRoot
# ------- Paths -------
$AppName = 'The Space Project'
# Archive filename slug — kebab-case + platform tag + version. The
# extracted folder still uses $AppName so the user sees "The Space
# Project/" in Explorer; only the .zip filename uses the slug. Keep
# in sync with Makefile's ARCHIVE_SLUG.
$ArchiveSlug = 'the-space-project'
$AssetsSrc = 'crates/client_bevy/assets'
$DataSrc = 'priv'
$DistDir = 'dist'
$WinDirRel = "windows/$AppName"
$WinDir = Join-Path $DistDir $WinDirRel
$TargetWin = 'x86_64-pc-windows-msvc'
# Resolve VERSION from workspace Cargo.toml unless overridden.
# Source of truth is [workspace.package] version — keeps the binary
# (env!CARGO_PKG_VERSION) and the butler --userversion in lockstep.
if (-not $Version) {
$cargoToml = Join-Path $PSScriptRoot 'Cargo.toml'
$match = Select-String -Path $cargoToml `
-Pattern '^version\s*=\s*"([^"]+)"' `
-List | Select-Object -First 1
if ($match) { $Version = $match.Matches[0].Groups[1].Value }
else { $Version = 'dev' }
}
$WinZipName = "$ArchiveSlug-windows_$Version.zip"
$WinZip = Join-Path $DistDir "windows/$WinZipName"
$ItchTarget = "$ItchUser/$ItchGame"
# ------- Helpers -------
function Step($msg) { Write-Host "==> $msg" -ForegroundColor Cyan }
function Info($msg) { Write-Host $msg }
function Invoke-Native([string]$exe, [string[]]$argv) {
& $exe @argv
if ($LASTEXITCODE -ne 0) {
throw "$exe exited with code $LASTEXITCODE"
}
}
function Install-RustupTarget([string]$triple) {
$installed = & rustup target list --installed
if ($installed -notcontains $triple) {
Step "rustup target add $triple"
Invoke-Native rustup @('target', 'add', $triple)
}
}
# ------- Targets -------
function Invoke-Help {
@"
spaceproject build helpers (Windows)
Usage: .\build.ps1 <target> [-Version X.Y.Z] [-Bin name]
[-ItchUser u] [-ItchGame g]
Native:
build Release build of $Bin for the host (Windows)
run Debug run of $Bin
verify scripts/verify.sh --strict (requires git-bash)
Windows binary + package:
build-win $TargetWin
package-win $WinDir\ + $WinZip
itch.io publishing (butler):
publish-win butler push $WinZip $ItchTarget`:windows --userversion $Version
butler-status butler status $ItchTarget
Maintenance:
clean Remove target\ and $DistDir\
Resolved version: $Version
"@ | Write-Host
}
function Invoke-Build {
Step "$Cargo build --release -p $Bin"
Invoke-Native $Cargo @('build', '--release', '-p', $Bin)
Info ""
Info "binary at: target\release\$Bin.exe"
Info "(assets/ are read from $AssetsSrc at runtime via Cargo path"
Info " for development; package-win bundles them next to the binary.)"
}
function Invoke-Run {
Invoke-Native $Cargo @('run', '-p', $Bin)
}
function Invoke-Verify {
if (-not (Get-Command bash -ErrorAction SilentlyContinue)) {
throw 'verify needs bash on PATH (install Git for Windows).'
}
Invoke-Native bash @('scripts/verify.sh', '--strict')
}
function Invoke-BuildWin {
Install-RustupTarget $TargetWin
Step "$Cargo build --release -p $Bin --target $TargetWin"
Invoke-Native $Cargo @('build', '--release', '-p', $Bin, '--target', $TargetWin)
Info "==> target\$TargetWin\release\$Bin.exe"
}
function Invoke-PackageWin {
Invoke-BuildWin
if (Test-Path $WinDir) { Remove-Item $WinDir -Recurse -Force }
New-Item -ItemType Directory -Path $WinDir -Force | Out-Null
$exeSrc = Join-Path "target\$TargetWin\release" "$Bin.exe"
$exeDst = Join-Path $WinDir "$Bin.exe"
Copy-Item $exeSrc $exeDst
$assetsDst = Join-Path $WinDir 'assets'
Copy-Item $AssetsSrc $assetsDst -Recurse
# priv/data/ holds the world/faction JSON the seeder reads on
# first boot. resolve_data_dir() walks up from the exe looking
# for `priv/`, so dropping it next to the binary is enough.
$privDst = Join-Path $WinDir 'priv'
Copy-Item $DataSrc $privDst -Recurse
if (Test-Path $WinZip) { Remove-Item $WinZip -Force }
# Zip with $AppName at archive root (matches `cd dist/windows && zip -r`).
Push-Location (Join-Path $DistDir 'windows')
try {
Compress-Archive -Path $AppName -DestinationPath $WinZipName -Force
} finally {
Pop-Location
}
Info ""
Info "==> $WinDir\"
Info "==> $WinZip"
}
function Invoke-PublishWin {
Invoke-PackageWin
$channel = "$($ItchTarget):windows"
Step "butler push $WinZip $channel --userversion $Version"
Invoke-Native butler @('push', $WinZip, $channel, '--userversion', $Version)
}
function Invoke-ButlerStatus {
Invoke-Native butler @('status', $ItchTarget)
}
function Invoke-Clean {
if (Test-Path 'target') { Remove-Item 'target' -Recurse -Force }
if (Test-Path $DistDir) { Remove-Item $DistDir -Recurse -Force }
Info "==> cleaned target\ and $DistDir\"
}
# ------- Dispatch -------
switch ($Target) {
'help' { Invoke-Help }
'build' { Invoke-Build }
'run' { Invoke-Run }
'verify' { Invoke-Verify }
'build-win' { Invoke-BuildWin }
'package-win' { Invoke-PackageWin }
'publish-win' { Invoke-PublishWin }
'butler-status' { Invoke-ButlerStatus }
'clean' { Invoke-Clean }
}