forked from zed-industries/zed
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle-windows.ps1
More file actions
378 lines (338 loc) · 14.2 KB
/
bundle-windows.ps1
File metadata and controls
378 lines (338 loc) · 14.2 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
[CmdletBinding()]
Param(
[Parameter()][Alias('i')][switch]$Install,
[Parameter()][Alias('h')][switch]$Help,
[Parameter()][Alias('a')][string]$Architecture,
[Parameter()][string]$Name
)
. "$PSScriptRoot/lib/workspace.ps1"
# https://stackoverflow.com/questions/57949031/powershell-script-stops-if-program-fails-like-bash-set-o-errexit
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
$buildSuccess = $false
$OSArchitecture = switch ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture) {
"X64" { "x86_64" }
"Arm64" { "aarch64" }
default { throw "Unsupported architecture" }
}
$Architecture = if ($Architecture) {
$Architecture
} else {
$OSArchitecture
}
$CargoOutDir = "./target/$Architecture-pc-windows-msvc/release"
function Get-VSArch {
param(
[string]$Arch
)
switch ($Arch) {
"x86_64" { "amd64" }
"aarch64" { "arm64" }
}
}
Push-Location
& "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1" -Arch (Get-VSArch -Arch $Architecture) -HostArch (Get-VSArch -Arch $OSArchitecture)
Pop-Location
$target = "$Architecture-pc-windows-msvc"
if ($Help) {
Write-Output "Usage: test.ps1 [-Install] [-Help]"
Write-Output "Build the installer for Windows.\n"
Write-Output "Options:"
Write-Output " -Architecture, -a Which architecture to build (x86_64 or aarch64)"
Write-Output " -Install, -i Run the installer after building."
Write-Output " -Help, -h Show this help message."
exit 0
}
Push-Location -Path crates/zed
$channel = Get-Content "RELEASE_CHANNEL"
$env:ZED_RELEASE_CHANNEL = $channel
$env:RELEASE_CHANNEL = $channel
Pop-Location
function CheckEnvironmentVariables {
if(-not $env:CI) {
return
}
$requiredVars = @(
'ZED_WORKSPACE', 'RELEASE_VERSION', 'ZED_RELEASE_CHANNEL',
'AZURE_TENANT_ID', 'AZURE_CLIENT_ID', 'AZURE_CLIENT_SECRET',
'ACCOUNT_NAME', 'CERT_PROFILE_NAME', 'ENDPOINT',
'FILE_DIGEST', 'TIMESTAMP_DIGEST', 'TIMESTAMP_SERVER'
)
foreach ($var in $requiredVars) {
if (-not (Test-Path "env:$var")) {
Write-Error "$var is not set"
exit 1
}
}
}
function PrepareForBundle {
if (Test-Path "$innoDir") {
Remove-Item -Path "$innoDir" -Recurse -Force
}
New-Item -Path "$innoDir" -ItemType Directory -Force
Copy-Item -Path "$env:ZED_WORKSPACE\crates\zed\resources\windows\*" -Destination "$innoDir" -Recurse -Force
New-Item -Path "$innoDir\make_appx" -ItemType Directory -Force
New-Item -Path "$innoDir\appx" -ItemType Directory -Force
New-Item -Path "$innoDir\bin" -ItemType Directory -Force
New-Item -Path "$innoDir\tools" -ItemType Directory -Force
rustup target add $target
}
function GenerateLicenses {
$oldErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = 'Continue'
. $PSScriptRoot/generate-licenses.ps1
$ErrorActionPreference = $oldErrorActionPreference
}
function BuildZedAndItsFriends {
Write-Output "Building Zed and its friends, for channel: $channel"
# Build zed.exe, cli.exe and auto_update_helper.exe
cargo build --release --package zed --package cli --package auto_update_helper --target $target
Copy-Item -Path ".\$CargoOutDir\zed.exe" -Destination "$innoDir\Zed.exe" -Force
Copy-Item -Path ".\$CargoOutDir\cli.exe" -Destination "$innoDir\cli.exe" -Force
Copy-Item -Path ".\$CargoOutDir\auto_update_helper.exe" -Destination "$innoDir\auto_update_helper.exe" -Force
# Build explorer_command_injector.dll
switch ($channel) {
"stable" {
cargo build --release --features stable --no-default-features --package explorer_command_injector --target $target
}
"preview" {
cargo build --release --features preview --no-default-features --package explorer_command_injector --target $target
}
default {
cargo build --release --package explorer_command_injector --target $target
}
}
Copy-Item -Path ".\$CargoOutDir\explorer_command_injector.dll" -Destination "$innoDir\zed_explorer_command_injector.dll" -Force
}
function ZipZedAndItsFriendsDebug {
$items = @(
".\$CargoOutDir\zed.pdb",
".\$CargoOutDir\cli.pdb",
".\$CargoOutDir\auto_update_helper.pdb",
".\$CargoOutDir\explorer_command_injector.pdb"
)
Compress-Archive -Path $items -DestinationPath ".\$CargoOutDir\zed-$env:RELEASE_VERSION-$env:ZED_RELEASE_CHANNEL.dbg.zip" -Force
}
function UploadToSentry {
if (-not (Get-Command "sentry-cli" -ErrorAction SilentlyContinue)) {
Write-Output "sentry-cli not found. skipping sentry upload."
Write-Output "install with: 'winget install -e --id=Sentry.sentry-cli'"
return
}
if (-not (Test-Path "env:SENTRY_AUTH_TOKEN")) {
Write-Output "missing SENTRY_AUTH_TOKEN. skipping sentry upload."
return
}
Write-Output "Uploading zed debug symbols to sentry..."
for ($i = 1; $i -le 3; $i++) {
try {
sentry-cli debug-files upload --include-sources --wait -p zed -o zed-dev $CargoOutDir
break
}
catch {
Write-Output "Sentry upload attempt $i failed: $_"
if ($i -eq 3) {
Write-Output "All sentry upload attempts failed"
throw
}
Start-Sleep -Seconds 2
}
}
}
function MakeAppx {
switch ($channel) {
"stable" {
$manifestFile = "$env:ZED_WORKSPACE\crates\explorer_command_injector\AppxManifest.xml"
}
"preview" {
$manifestFile = "$env:ZED_WORKSPACE\crates\explorer_command_injector\AppxManifest-Preview.xml"
}
default {
$manifestFile = "$env:ZED_WORKSPACE\crates\explorer_command_injector\AppxManifest-Nightly.xml"
}
}
Copy-Item -Path "$manifestFile" -Destination "$innoDir\make_appx\AppxManifest.xml"
# Add makeAppx.exe to Path
$sdk = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64"
$env:Path += ';' + $sdk
makeAppx.exe pack /d "$innoDir\make_appx" /p "$innoDir\zed_explorer_command_injector.appx" /nv
}
function SignZedAndItsFriends {
if (-not $env:CI) {
return
}
$files = "$innoDir\Zed.exe,$innoDir\cli.exe,$innoDir\auto_update_helper.exe,$innoDir\zed_explorer_command_injector.dll,$innoDir\zed_explorer_command_injector.appx"
& "$innoDir\sign.ps1" $files
}
function DownloadAMDGpuServices {
# If you update the AGS SDK version, please also update the version in `crates/gpui/src/platform/windows/directx_renderer.rs`
$url = "https://codeload.github.com/GPUOpen-LibrariesAndSDKs/AGS_SDK/zip/refs/tags/v6.3.0"
$zipPath = ".\AGS_SDK_v6.3.0.zip"
# Download the AGS SDK zip file
Invoke-WebRequest -Uri $url -OutFile $zipPath
# Extract the AGS SDK zip file
Expand-Archive -Path $zipPath -DestinationPath "." -Force
}
function DownloadConpty {
$url = "https://github.com/microsoft/terminal/releases/download/v1.23.13503.0/Microsoft.Windows.Console.ConPTY.1.23.251216003.nupkg"
$zipPath = ".\Microsoft.Windows.Console.ConPTY.1.23.251216003.nupkg"
Invoke-WebRequest -Uri $url -OutFile $zipPath
Expand-Archive -Path $zipPath -DestinationPath ".\conpty" -Force
}
function CollectFiles {
Move-Item -Path "$innoDir\zed_explorer_command_injector.appx" -Destination "$innoDir\appx\zed_explorer_command_injector.appx" -Force
Move-Item -Path "$innoDir\zed_explorer_command_injector.dll" -Destination "$innoDir\appx\zed_explorer_command_injector.dll" -Force
Move-Item -Path "$innoDir\cli.exe" -Destination "$innoDir\bin\zed.exe" -Force
Move-Item -Path "$innoDir\zed.sh" -Destination "$innoDir\bin\zed" -Force
Move-Item -Path "$innoDir\auto_update_helper.exe" -Destination "$innoDir\tools\auto_update_helper.exe" -Force
if($Architecture -eq "aarch64") {
New-Item -Type Directory -Path "$innoDir\arm64" -Force
Move-Item -Path ".\conpty\build\native\runtimes\arm64\OpenConsole.exe" -Destination "$innoDir\arm64\OpenConsole.exe" -Force
Move-Item -Path ".\conpty\runtimes\win-arm64\native\conpty.dll" -Destination "$innoDir\conpty.dll" -Force
}
else {
New-Item -Type Directory -Path "$innoDir\x64" -Force
New-Item -Type Directory -Path "$innoDir\arm64" -Force
Move-Item -Path ".\AGS_SDK-6.3.0\ags_lib\lib\amd_ags_x64.dll" -Destination "$innoDir\amd_ags_x64.dll" -Force
Move-Item -Path ".\conpty\build\native\runtimes\x64\OpenConsole.exe" -Destination "$innoDir\x64\OpenConsole.exe" -Force
Move-Item -Path ".\conpty\build\native\runtimes\arm64\OpenConsole.exe" -Destination "$innoDir\arm64\OpenConsole.exe" -Force
Move-Item -Path ".\conpty\runtimes\win-x64\native\conpty.dll" -Destination "$innoDir\conpty.dll" -Force
}
}
function BuildInstaller {
$issFilePath = "$innoDir\zed.iss"
switch ($channel) {
"stable" {
$appId = "{{2DB0DA96-CA55-49BB-AF4F-64AF36A86712}"
$appIconName = "app-icon"
$appName = "Zed"
$appDisplayName = "Zed"
$appSetupName = "Zed-$Architecture"
# The mutex name here should match the mutex name in crates\zed\src\zed\windows_only_instance.rs
$appMutex = "Zed-Stable-Instance-Mutex"
$appExeName = "Zed"
$regValueName = "Zed"
$appUserId = "ZedIndustries.Zed"
$appShellNameShort = "Z&ed"
$appAppxFullName = "ZedIndustries.Zed_1.0.0.0_neutral__japxn1gcva8rg"
}
"preview" {
$appId = "{{F70E4811-D0E2-4D88-AC99-D63752799F95}"
$appIconName = "app-icon-preview"
$appName = "Zed Preview"
$appDisplayName = "Zed Preview"
$appSetupName = "Zed-$Architecture"
# The mutex name here should match the mutex name in crates\zed\src\zed\windows_only_instance.rs
$appMutex = "Zed-Preview-Instance-Mutex"
$appExeName = "Zed"
$regValueName = "ZedPreview"
$appUserId = "ZedIndustries.Zed.Preview"
$appShellNameShort = "Z&ed Preview"
$appAppxFullName = "ZedIndustries.Zed.Preview_1.0.0.0_neutral__japxn1gcva8rg"
}
"nightly" {
$appId = "{{1BDB21D3-14E7-433C-843C-9C97382B2FE0}"
$appIconName = "app-icon-nightly"
$appName = "Zed Nightly"
$appDisplayName = "Zed Nightly"
$appSetupName = "Zed-$Architecture"
# The mutex name here should match the mutex name in crates\zed\src\zed\windows_only_instance.rs
$appMutex = "Zed-Nightly-Instance-Mutex"
$appExeName = "Zed"
$regValueName = "ZedNightly"
$appUserId = "ZedIndustries.Zed.Nightly"
$appShellNameShort = "Z&ed Editor Nightly"
$appAppxFullName = "ZedIndustries.Zed.Nightly_1.0.0.0_neutral__japxn1gcva8rg"
}
"dev" {
$appId = "{{8357632E-24A4-4F32-BA97-E575B4D1FE5D}"
$appIconName = "app-icon-dev"
$appName = "Zed Dev"
$appDisplayName = "Zed Dev"
$appSetupName = "Zed-$Architecture"
# The mutex name here should match the mutex name in crates\zed\src\zed\windows_only_instance.rs
$appMutex = "Zed-Dev-Instance-Mutex"
$appExeName = "Zed"
$regValueName = "ZedDev"
$appUserId = "ZedIndustries.Zed.Dev"
$appShellNameShort = "Z&ed Dev"
$appAppxFullName = "ZedIndustries.Zed.Dev_1.0.0.0_neutral__japxn1gcva8rg"
}
default {
Write-Error "can't bundle installer for $channel."
exit 1
}
}
# Windows runner 2022 default has iscc in PATH, https://github.com/actions/runner-images/blob/main/images/windows/Windows2022-Readme.md
# Currently, we are using Windows 2022 runner.
# Windows runner 2025 doesn't have iscc in PATH for now, https://github.com/actions/runner-images/issues/11228
$innoSetupPath = "C:\Program Files (x86)\Inno Setup 6\ISCC.exe"
$definitions = @{
"AppId" = $appId
"AppIconName" = $appIconName
"OutputDir" = "$env:ZED_WORKSPACE\target"
"AppSetupName" = $appSetupName
"AppName" = $appName
"AppDisplayName" = $appDisplayName
"RegValueName" = $regValueName
"AppMutex" = $appMutex
"AppExeName" = $appExeName
"ResourcesDir" = "$innoDir"
"ShellNameShort" = $appShellNameShort
"AppUserId" = $appUserId
"Version" = "$env:RELEASE_VERSION"
"SourceDir" = "$env:ZED_WORKSPACE"
"AppxFullName" = $appAppxFullName
}
$defs = @()
foreach ($key in $definitions.Keys) {
$defs += "/d$key=`"$($definitions[$key])`""
}
$innoArgs = @($issFilePath) + $defs
if($env:CI) {
$signTool = "powershell.exe -ExecutionPolicy Bypass -File $innoDir\sign.ps1 `$f"
$innoArgs += "/sDefaultsign=`"$signTool`""
}
# Execute Inno Setup
Write-Host "🚀 Running Inno Setup: $innoSetupPath $innoArgs"
$process = Start-Process -FilePath $innoSetupPath -ArgumentList $innoArgs -NoNewWindow -Wait -PassThru
if ($process.ExitCode -eq 0) {
Write-Host "✅ Inno Setup successfully compiled the installer"
Write-Output "SETUP_PATH=target/$appSetupName.exe" >> $env:GITHUB_ENV
$script:buildSuccess = $true
}
else {
Write-Host "❌ Inno Setup failed: $($process.ExitCode)"
$script:buildSuccess = $false
}
}
ParseZedWorkspace
$innoDir = "$env:ZED_WORKSPACE\inno\$Architecture"
$debugArchive = "$CargoOutDir\zed-$env:RELEASE_VERSION-$env:ZED_RELEASE_CHANNEL.dbg.zip"
$debugStoreKey = "$env:ZED_RELEASE_CHANNEL/zed-$env:RELEASE_VERSION-$env:ZED_RELEASE_CHANNEL.dbg.zip"
CheckEnvironmentVariables
PrepareForBundle
GenerateLicenses
BuildZedAndItsFriends
MakeAppx
SignZedAndItsFriends
ZipZedAndItsFriendsDebug
DownloadAMDGpuServices
DownloadConpty
CollectFiles
BuildInstaller
if($env:CI) {
UploadToSentry
}
if ($buildSuccess) {
Write-Output "Build successful"
if ($Install) {
Write-Output "Installing Zed..."
Start-Process -FilePath "$env:ZED_WORKSPACE/target/ZedEditorUserSetup-x64-$env:RELEASE_VERSION.exe"
}
exit 0
}
else {
Write-Output "Build failed"
exit 1
}