-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathenv.ps1
More file actions
1373 lines (1222 loc) · 60.7 KB
/
env.ps1
File metadata and controls
1373 lines (1222 loc) · 60.7 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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
[CmdletBinding()]
param()
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
function Get-RepoRoot {
return (Split-Path -Parent $PSCommandPath)
}
function Get-DefaultInstallRoot {
$envInstallRoot = [Environment]::GetEnvironmentVariable("WINDOWS_DIY_INSTALL_ROOT")
if (-not [string]::IsNullOrWhiteSpace($envInstallRoot)) {
return $envInstallRoot.Trim()
}
# Prefer D: drive root when available (more space, avoids C: bloat).
if (Test-Path -LiteralPath "D:\" -PathType Container) {
return "D:\metacraft-dev-deps"
}
$localAppData = [Environment]::GetFolderPath([Environment+SpecialFolder]::LocalApplicationData)
if ([string]::IsNullOrWhiteSpace($localAppData)) {
throw "Could not resolve LocalApplicationData for default WINDOWS_DIY_INSTALL_ROOT."
}
return (Join-Path (Join-Path $localAppData "codetracer") "windows-diy")
}
function ConvertTo-BoolFromEnv {
param(
[string]$Name,
[bool]$Default
)
$raw = [Environment]::GetEnvironmentVariable($Name)
if ([string]::IsNullOrWhiteSpace($raw)) {
return $Default
}
switch ($raw.Trim().ToLowerInvariant()) {
"1" { return $true }
"true" { return $true }
"yes" { return $true }
"on" { return $true }
"0" { return $false }
"false" { return $false }
"no" { return $false }
"off" { return $false }
default { return $Default }
}
}
function Parse-ToolchainVersions {
param([Parameter(Mandatory = $true)][string]$Path)
if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) {
throw "Missing toolchain version file at '$Path'."
}
$map = @{}
foreach ($line in Get-Content -LiteralPath $Path) {
if ($line -match '^\s*#' -or [string]::IsNullOrWhiteSpace($line)) {
continue
}
if ($line -notmatch '^\s*([A-Za-z_][A-Za-z0-9_]*)=(.*)$') {
continue
}
$name = $matches[1]
$value = $matches[2].Trim()
if ($value.StartsWith('"') -and $value.EndsWith('"') -and $value.Length -ge 2) {
$value = $value.Substring(1, $value.Length - 2)
}
$map[$name] = $value
}
return $map
}
function Set-EnvDefault {
param(
[Parameter(Mandatory = $true)][string]$Name,
[Parameter(Mandatory = $true)][string]$Value
)
$existing = [Environment]::GetEnvironmentVariable($Name)
if ([string]::IsNullOrWhiteSpace($existing)) {
[Environment]::SetEnvironmentVariable($Name, $Value, "Process")
}
}
function Resolve-InstallDirFromRelativePathFile {
param(
[Parameter(Mandatory = $true)][string]$InstallRoot,
[Parameter(Mandatory = $true)][string]$RelativePathFile,
[string]$FallbackDir = ""
)
if (Test-Path -LiteralPath $RelativePathFile -PathType Leaf) {
$relative = (Get-Content -LiteralPath $RelativePathFile -Raw).Trim()
if (-not [string]::IsNullOrWhiteSpace($relative)) {
$parts = $relative -split '[\\/]'
return (Join-Path $InstallRoot ([System.IO.Path]::Combine($parts)))
}
}
if (-not [string]::IsNullOrWhiteSpace($FallbackDir)) {
return $FallbackDir
}
return ""
}
function Resolve-DotnetRoot {
param(
[Parameter(Mandatory = $true)][string]$InstallRoot,
[Parameter(Mandatory = $true)][string]$PinnedSdkVersion
)
$candidates = @()
$override = [Environment]::GetEnvironmentVariable("WINDOWS_DIY_DOTNET_ROOT")
if (-not [string]::IsNullOrWhiteSpace($override)) {
$candidates += $override.Trim()
}
$candidates += (Join-Path $InstallRoot ("dotnet\" + $PinnedSdkVersion))
$candidates += (Join-Path ${env:ProgramFiles} "dotnet")
foreach ($candidate in $candidates) {
if ([string]::IsNullOrWhiteSpace($candidate)) { continue }
$exe = Join-Path $candidate "dotnet.exe"
if (Test-Path -LiteralPath $exe -PathType Leaf) {
return $candidate
}
}
# Fall back to the managed install path — Ensure-Dotnet will create it during sync.
return (Join-Path $InstallRoot ("dotnet\" + $PinnedSdkVersion))
}
function Resolve-TtdExe {
$candidates = @()
$override = [Environment]::GetEnvironmentVariable("WINDOWS_DIY_TTD_EXE")
if (-not [string]::IsNullOrWhiteSpace($override)) {
$candidates += $override.Trim()
}
# Check DIY cache first — these are regular files accessible from SSH/CI
$diyRoot = [Environment]::GetEnvironmentVariable("WINDOWS_DIY_INSTALL_ROOT")
if (-not [string]::IsNullOrWhiteSpace($diyRoot)) {
$ttdCacheRoot = Join-Path $diyRoot "ttd"
if (Test-Path -LiteralPath $ttdCacheRoot -PathType Container) {
$versionDirs = Get-ChildItem -LiteralPath $ttdCacheRoot -Directory -ErrorAction SilentlyContinue |
Sort-Object Name -Descending
foreach ($vd in $versionDirs) {
$candidates += (Join-Path $vd.FullName "TTD.exe")
}
}
}
$ttdPackage = Get-AppxPackage -Name "Microsoft.TimeTravelDebugging" -ErrorAction SilentlyContinue | Sort-Object Version -Descending | Select-Object -First 1
if ($null -ne $ttdPackage -and -not [string]::IsNullOrWhiteSpace($ttdPackage.InstallLocation)) {
$candidates += (Join-Path $ttdPackage.InstallLocation "TTD.exe")
}
$ttdCmd = Get-Command ttd.exe -ErrorAction SilentlyContinue
if ($null -ne $ttdCmd -and -not [string]::IsNullOrWhiteSpace($ttdCmd.Source)) {
$candidates += $ttdCmd.Source
}
$ttdCmd = Get-Command ttd -ErrorAction SilentlyContinue
if ($null -ne $ttdCmd -and -not [string]::IsNullOrWhiteSpace($ttdCmd.Source)) {
$candidates += $ttdCmd.Source
}
$localAppData = [Environment]::GetFolderPath([Environment+SpecialFolder]::LocalApplicationData)
if (-not [string]::IsNullOrWhiteSpace($localAppData)) {
$candidates += (Join-Path $localAppData "Microsoft\WindowsApps\ttd.exe")
}
$candidates += (Join-Path ${env:USERPROFILE} "AppData\Local\Microsoft\WindowsApps\ttd.exe")
foreach ($candidate in $candidates) {
if ([string]::IsNullOrWhiteSpace($candidate)) { continue }
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
return $candidate
}
}
return ""
}
function Resolve-AppxPackageInfo {
param([Parameter(Mandatory = $true)][string]$Name)
$pkg = Get-AppxPackage -Name $Name -ErrorAction SilentlyContinue | Sort-Object Version -Descending | Select-Object -First 1
if ($null -eq $pkg) {
return $null
}
return $pkg
}
function Parse-VersionOrNull {
param([string]$Value)
if ([string]::IsNullOrWhiteSpace($Value)) {
return $null
}
try {
return [version]$Value.Trim()
} catch {
return $null
}
}
function Assert-MinVersion {
param(
[Parameter(Mandatory = $true)][string]$DisplayName,
[Parameter(Mandatory = $true)][string]$ActualVersion,
[Parameter(Mandatory = $true)][string]$MinVersion,
[Parameter(Mandatory = $true)][string]$InstallHint
)
$actualParsed = Parse-VersionOrNull -Value $ActualVersion
$minParsed = Parse-VersionOrNull -Value $MinVersion
if ($null -eq $actualParsed -or $null -eq $minParsed) {
throw "Could not parse version check inputs for '$DisplayName'. actual='$ActualVersion', min='$MinVersion'."
}
if ($actualParsed -lt $minParsed) {
throw "$DisplayName version '$ActualVersion' is below required minimum '$MinVersion'. Install/upgrade with: $InstallHint"
}
}
function Resolve-MsvcToolsetVersion {
$envVersion = [Environment]::GetEnvironmentVariable("VCToolsVersion")
if (-not [string]::IsNullOrWhiteSpace($envVersion)) {
return $envVersion.Trim().TrimEnd('\')
}
$toolsDir = [Environment]::GetEnvironmentVariable("VCToolsInstallDir")
if (-not [string]::IsNullOrWhiteSpace($toolsDir)) {
$leaf = Split-Path -Leaf ($toolsDir.Trim().TrimEnd('\'))
if (-not [string]::IsNullOrWhiteSpace($leaf)) {
return $leaf
}
}
$msvcBinDir = [Environment]::GetEnvironmentVariable("MSVC_BIN_DIR")
if (-not [string]::IsNullOrWhiteSpace($msvcBinDir)) {
$normalized = $msvcBinDir.Replace("/", "\")
$match = [regex]::Match($normalized, "\\MSVC\\([^\\]+)\\bin\\", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
if ($match.Success) {
return $match.Groups[1].Value
}
}
return ""
}
function Assert-MsvcToolsetVersion {
param(
[Parameter(Mandatory = $true)][string]$ActualVersion,
[Parameter(Mandatory = $true)][string]$PinnedVersion
)
if ([string]::IsNullOrWhiteSpace($ActualVersion)) {
throw "Could not resolve MSVC toolset version from VCToolsVersion/VCToolsInstallDir."
}
$actual = $ActualVersion.Trim()
$pinned = $PinnedVersion.Trim()
$pinnedPrefix = $pinned + "."
if ($actual -ne $pinned -and -not $actual.StartsWith($pinnedPrefix)) {
throw "MSVC toolset version '$actual' does not match pinned '$pinned'. Install the pinned Build Tools/MSVC toolset."
}
}
function Assert-DotnetSdkPresent {
param(
[Parameter(Mandatory = $true)][string]$DotnetExe,
[Parameter(Mandatory = $true)][string]$PinnedSdkVersion
)
$sdkLines = & $DotnetExe --list-sdks 2>$null
if ($LASTEXITCODE -ne 0) {
throw "Failed to query installed .NET SDKs via '$DotnetExe --list-sdks'."
}
$installedVersions = @()
foreach ($line in $sdkLines) {
if ([string]$line -match "^\s*([0-9]+\.[0-9]+\.[0-9]+)\s") {
$installedVersions += $matches[1]
}
}
if ($installedVersions -contains $PinnedSdkVersion) {
[Environment]::SetEnvironmentVariable("DOTNET_SDK_VERSION_EFFECTIVE", $PinnedSdkVersion, "Process")
return
}
$allowFeatureRollForward = ConvertTo-BoolFromEnv -Name "WINDOWS_DIY_DOTNET_ROLL_FORWARD_FEATURE" -Default $true
if ($allowFeatureRollForward) {
$majorMinorMatch = [regex]::Match($PinnedSdkVersion, '^([0-9]+\.[0-9]+)\.')
if ($majorMinorMatch.Success) {
$pinnedMajorMinor = $majorMinorMatch.Groups[1].Value
$featureBandMatches = @()
foreach ($v in $installedVersions) {
if ($v -match "^$([regex]::Escape($pinnedMajorMinor))\.[0-9]+$") {
$featureBandMatches += $v
}
}
if ($featureBandMatches.Count -gt 0) {
$effective = $featureBandMatches | Sort-Object {[version]$_} -Descending | Select-Object -First 1
[Environment]::SetEnvironmentVariable("DOTNET_SDK_VERSION_EFFECTIVE", $effective, "Process")
Write-Warning "Pinned .NET SDK '$PinnedSdkVersion' not found; using feature-band roll-forward '$effective' from '$DotnetExe'."
return
}
}
}
$available = if ($installedVersions.Count -gt 0) { $installedVersions -join ", " } else { "<none>" }
throw "Pinned .NET SDK '$PinnedSdkVersion' is not installed for '$DotnetExe'. Installed SDKs: $available. Install with: winget install --id Microsoft.DotNet.SDK.9 --exact --source winget"
}
function Resolve-TtdRuntimeInfo {
$ttdPackage = Resolve-AppxPackageInfo -Name "Microsoft.TimeTravelDebugging"
$windbgPackage = Resolve-AppxPackageInfo -Name "Microsoft.WinDbg"
$ttdExe = Resolve-TtdExe
$ttdInstallDir = ""
$ttdVersion = ""
# Prefer DIY cache directory (works from SSH/CI sessions)
if (-not [string]::IsNullOrWhiteSpace($ttdExe)) {
$ttdExeDir = Split-Path -Parent $ttdExe
$metaFile = Join-Path $ttdExeDir "ttd.install.meta"
if (Test-Path -LiteralPath $metaFile -PathType Leaf) {
# This is a DIY-cached copy — use its directory and read version from meta
$ttdInstallDir = $ttdExeDir
$meta = Read-KeyValueFile -Path $metaFile
if ($meta.ContainsKey("ttd_version")) {
$ttdVersion = [string]$meta["ttd_version"]
}
}
}
# Fall back to AppX package info if DIY cache didn't provide version
if ([string]::IsNullOrWhiteSpace($ttdVersion) -and $null -ne $ttdPackage) {
$ttdInstallDir = [string]$ttdPackage.InstallLocation
$ttdVersion = [string]$ttdPackage.Version
}
$windbgInstallDir = ""
$windbgVersion = ""
if ($null -ne $windbgPackage) {
$windbgInstallDir = [string]$windbgPackage.InstallLocation
$windbgVersion = [string]$windbgPackage.Version
}
$ttdReplayDll = ""
$ttdReplayCpuDll = ""
if (-not [string]::IsNullOrWhiteSpace($ttdInstallDir)) {
$replayCandidate = Join-Path $ttdInstallDir "TTDReplay.dll"
if (Test-Path -LiteralPath $replayCandidate -PathType Leaf) {
$ttdReplayDll = $replayCandidate
}
$replayCpuCandidate = Join-Path $ttdInstallDir "TTDReplayCPU.dll"
if (Test-Path -LiteralPath $replayCpuCandidate -PathType Leaf) {
$ttdReplayCpuDll = $replayCpuCandidate
}
}
$cdbExe = ""
$dbgengDll = ""
$dbgmodelDll = ""
$dbghelpDll = ""
if (-not [string]::IsNullOrWhiteSpace($windbgInstallDir)) {
$archKey = [Environment]::GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
$subdirs = @("arm64", "amd64", "x64", "x86")
if (-not [string]::IsNullOrWhiteSpace($archKey)) {
$archLower = $archKey.ToLowerInvariant()
if ($archLower -eq "amd64") {
$subdirs = @("amd64", "x64", "arm64", "x86")
} elseif ($archLower -eq "arm64") {
$subdirs = @("arm64", "amd64", "x64", "x86")
} elseif ($archLower -eq "x86") {
$subdirs = @("x86", "amd64", "x64", "arm64")
}
}
foreach ($sub in $subdirs) {
if ([string]::IsNullOrWhiteSpace($cdbExe)) {
$candidate = Join-Path $windbgInstallDir ($sub + "\cdb.exe")
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
$cdbExe = $candidate
}
}
if ([string]::IsNullOrWhiteSpace($dbgengDll)) {
$candidate = Join-Path $windbgInstallDir ($sub + "\dbgeng.dll")
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
$dbgengDll = $candidate
}
}
if ([string]::IsNullOrWhiteSpace($dbgmodelDll)) {
$candidate = Join-Path $windbgInstallDir ($sub + "\dbgmodel.dll")
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
$dbgmodelDll = $candidate
}
}
if ([string]::IsNullOrWhiteSpace($dbghelpDll)) {
$candidate = Join-Path $windbgInstallDir ($sub + "\dbghelp.dll")
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
$dbghelpDll = $candidate
}
}
}
}
$systemRoot = [Environment]::GetEnvironmentVariable("SystemRoot")
if ([string]::IsNullOrWhiteSpace($systemRoot)) {
$systemRoot = "C:\Windows"
}
$system32 = Join-Path $systemRoot "System32"
$candidate = Join-Path $system32 "dbgeng.dll"
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
$dbgengDll = $candidate
}
$candidate = Join-Path $system32 "dbgmodel.dll"
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
$dbgmodelDll = $candidate
}
$candidate = Join-Path $system32 "dbghelp.dll"
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
$dbghelpDll = $candidate
}
return [ordered]@{
ttdExe = $ttdExe
ttdInstallDir = $ttdInstallDir
ttdVersion = $ttdVersion
ttdReplayDll = $ttdReplayDll
ttdReplayCpuDll = $ttdReplayCpuDll
windbgInstallDir = $windbgInstallDir
windbgVersion = $windbgVersion
cdbExe = $cdbExe
dbgengDll = $dbgengDll
dbgmodelDll = $dbgmodelDll
dbghelpDll = $dbghelpDll
}
}
function Ensure-NodeTooling {
param(
[Parameter(Mandatory = $true)][string]$RepoRoot,
[Parameter(Mandatory = $true)][string]$NodePackagesBin,
[Parameter(Mandatory = $true)][string]$NodeDir
)
$stylusCmd = Join-Path $NodePackagesBin "stylus.cmd"
$webpackCmd = Join-Path $NodePackagesBin "webpack.cmd"
if ((Test-Path -LiteralPath $stylusCmd -PathType Leaf) -and (Test-Path -LiteralPath $webpackCmd -PathType Leaf)) {
return
}
$setupNodeDeps = ConvertTo-BoolFromEnv -Name "WINDOWS_DIY_SETUP_NODE_DEPS" -Default $true
if (-not $setupNodeDeps) {
Write-Warning "Node deps are missing (stylus/webpack) and WINDOWS_DIY_SETUP_NODE_DEPS=0. Run 'cd node-packages; npx yarn install'."
return
}
$npxExe = Join-Path $NodeDir "npx.cmd"
if (-not (Test-Path -LiteralPath $npxExe -PathType Leaf)) {
throw "npx not found at '$npxExe'. Ensure Node.js is installed (Ensure-Node)."
}
Write-Host "Windows DIY: Node deps missing, running yarn install in node-packages..."
$nodePackagesDir = Join-Path $RepoRoot "node-packages"
# Temporarily put NodeDir on PATH so child processes (yarn -> node) can find node.exe.
$savedPath = $env:PATH
$env:PATH = "$NodeDir;$env:PATH"
Push-Location $nodePackagesDir
try {
$lockFile = Join-Path $nodePackagesDir "yarn.lock"
if (Test-Path -LiteralPath $lockFile -PathType Leaf) {
& $npxExe yarn install --frozen-lockfile
} else {
& $npxExe yarn install
}
} finally {
Pop-Location
$env:PATH = $savedPath
}
if ((-not (Test-Path -LiteralPath $stylusCmd -PathType Leaf)) -or (-not (Test-Path -LiteralPath $webpackCmd -PathType Leaf))) {
throw "Node dependency setup finished but stylus/webpack commands are still missing under '$NodePackagesBin'."
}
}
# Mirror of env.sh:600-601 — `ln -s node-packages/node_modules ./node_modules`.
#
# `scripts/build-once.sh` and other build scripts hard-code
# `node_modules/.bin/webpack` relative to the repo root, but yarn installs the
# JS deps under `node-packages/node_modules/`. On POSIX env.sh creates a
# symlink. On Windows we use an NTFS junction (works without symlink privilege
# and is transparent to all consumers, including bash and Node's CommonJS
# resolver).
#
# Idempotent: re-running this is a no-op when the junction already exists and
# points at the right target. If something else owns `node_modules` (a real
# directory, a stale junction pointing elsewhere, or a symlink), we leave it
# alone and emit a warning rather than risk destroying real state.
function Ensure-NodeModulesJunction {
param([Parameter(Mandatory = $true)][string]$RepoRoot)
$repoNodeModules = Join-Path $RepoRoot "node_modules"
$packagesNodeModules = Join-Path (Join-Path $RepoRoot "node-packages") "node_modules"
if (-not (Test-Path -LiteralPath $packagesNodeModules -PathType Container)) {
# yarn install hasn't run yet — Ensure-NodeTooling handles that path. We
# skip silently because the junction target doesn't exist yet; a follow-up
# source of env.ps1 (after yarn install) will create the link.
return
}
$expectedTarget = [System.IO.Path]::GetFullPath($packagesNodeModules)
if (Test-Path -LiteralPath $repoNodeModules) {
try {
$existing = Get-Item -LiteralPath $repoNodeModules -Force -ErrorAction Stop
} catch {
Write-Warning "Could not stat '$repoNodeModules': $($_.Exception.Message). Skipping node_modules junction creation."
return
}
$isReparse = $false
try {
$isReparse = (([int]$existing.Attributes) -band [int][System.IO.FileAttributes]::ReparsePoint) -ne 0
} catch {}
if ($isReparse) {
$currentTarget = ""
try {
$currentTarget = [string]$existing.Target
} catch {}
if ([string]::IsNullOrWhiteSpace($currentTarget) -and $null -ne $existing.PSObject.Properties["LinkTarget"]) {
$currentTarget = [string]$existing.LinkTarget
}
if (-not [string]::IsNullOrWhiteSpace($currentTarget)) {
try {
$resolvedTarget = [System.IO.Path]::GetFullPath($currentTarget)
} catch {
$resolvedTarget = $currentTarget
}
if ($resolvedTarget.TrimEnd('\','/') -ieq $expectedTarget.TrimEnd('\','/')) {
# Already pointing at the right place — idempotent no-op.
return
}
Write-Warning "node_modules at '$repoNodeModules' is a reparse point pointing at '$resolvedTarget' (expected '$expectedTarget'). Leaving it in place; please remove it manually if you want env.ps1 to manage the junction."
return
}
Write-Warning "node_modules at '$repoNodeModules' is a reparse point but its target could not be resolved. Leaving it in place."
return
}
# Real directory or file — don't clobber.
Write-Warning "node_modules at '$repoNodeModules' already exists as a regular path. Skipping junction creation. Remove it and re-source env.ps1 to let the bootstrap manage the junction."
return
}
try {
New-Item -ItemType Junction -Path $repoNodeModules -Target $packagesNodeModules | Out-Null
Write-Host "Created node_modules junction: $repoNodeModules -> $packagesNodeModules"
} catch {
Write-Warning "Failed to create node_modules junction '$repoNodeModules' -> '$packagesNodeModules': $($_.Exception.Message)"
}
}
# Materialize the GoldenLayout CSS directory inside the *build output*
# so the runtime `<link>` references resolve on Windows.
#
# `src/public/third_party/golden-layout/dist` is a git mode-120000 POSIX
# symlink into `node_modules/golden-layout/dist`. On a Windows checkout
# with `core.symlinks=false` it materializes as a ~44-byte text-file
# stub. The Tup rule `: third_party/golden-layout/dist |> !tup_preserve
# |> %f` treats that stub as a single opaque leaf — exactly the way the
# sibling `third_party/monaco-editor/min`, `@exuanbo`, `mousetrap`,
# `vex-js`, and `xterm` stubs are handled. This MUST stay a plain-file
# stub in the source tree: if it is materialized as a real directory
# (junction or directory symlink) Tup's scanner registers `dist` as a
# directory node and the leaf `!tup_preserve` rule then fails with
# "Attempting to insert '.../dist' as a generated node when it already
# exists as a different type (directory)". We therefore DO NOT touch
# the source stub here.
#
# Tup `!tup_preserve` copies that stub verbatim to
# `build-debug/public/third_party/golden-layout/dist`, so the build
# output also ends up with a useless text stub and the `<link>` to
# `goldenlayout-base.css` from index.html / server_index.ejs 404s,
# leaving GoldenLayout unstyled (collapsed, unclickable tab headers).
#
# The fix: after Tup has produced the build tree, replace the build-only
# stub with a real directory symlink into the actual
# `node_modules/golden-layout/dist`. This is a build-output-only change
# — the tup-scanned source tree stays a plain stub, so the leaf rule
# keeps parsing cleanly on every platform. A directory symlink is
# preferred (resolves with relative `<link>` paths exactly like a Linux
# symlink); a junction is the fallback when the symlink privilege is
# unavailable. When the build output does not exist yet (first shell
# activation before any `tup upd`), this is a silent no-op and the next
# activation after a build installs the link.
function Ensure-GoldenLayoutAsset {
param([Parameter(Mandatory = $true)][string]$RepoRoot)
$target = [System.IO.Path]::GetFullPath(
(Join-Path $RepoRoot "node_modules/golden-layout/dist"))
if (-not (Test-Path -LiteralPath $target -PathType Container)) {
return
}
$buildDistParent = Join-Path $RepoRoot "src/build-debug/public/third_party/golden-layout"
if (-not (Test-Path -LiteralPath $buildDistParent -PathType Container)) {
# Build output not produced yet — nothing to fix up.
return
}
$linkPath = Join-Path $buildDistParent "dist"
if (Test-Path -LiteralPath $linkPath) {
$item = Get-Item -LiteralPath $linkPath -Force -ErrorAction SilentlyContinue
if ($null -ne $item) {
$isReparse = $false
try {
$isReparse = (([int]$item.Attributes) -band [int][System.IO.FileAttributes]::ReparsePoint) -ne 0
} catch {}
if ($isReparse) {
# Already a junction/symlink directory — idempotent no-op.
return
}
}
# Plain Tup-preserved stub (or stale dir) — replace it.
try {
if (($null -ne $item) -and $item.PSIsContainer -and -not $isReparse) {
Remove-Item -LiteralPath $linkPath -Force -Recurse -ErrorAction Stop
} else {
Remove-Item -LiteralPath $linkPath -Force -ErrorAction Stop
}
} catch {
Write-Warning "Could not remove golden-layout build stub '$linkPath': $($_.Exception.Message)"
return
}
}
try {
New-Item -ItemType SymbolicLink -Path $linkPath -Target $target -ErrorAction Stop | Out-Null
Write-Host "Linked golden-layout CSS into build output: $linkPath -> $target"
} catch {
try {
New-Item -ItemType Junction -Path $linkPath -Target $target -ErrorAction Stop | Out-Null
Write-Host "Linked golden-layout CSS into build output (junction): $linkPath -> $target"
} catch {
Write-Warning "Failed to link golden-layout CSS into build output '$linkPath' -> '$target': $($_.Exception.Message)"
}
}
}
function Prepend-PathEntries {
param([Parameter(Mandatory = $true)][AllowNull()][AllowEmptyString()][AllowEmptyCollection()][string[]]$Entries)
$existing = [Environment]::GetEnvironmentVariable("PATH")
$prefix = @()
foreach ($entry in $Entries) {
if ($null -eq $entry) { continue }
$entryPath = [string]$entry
if ([string]::IsNullOrWhiteSpace($entryPath)) { continue }
if (-not (Test-Path -LiteralPath $entryPath)) { continue }
$prefix += $entryPath
}
if ($prefix.Count -eq 0) { return }
[Environment]::SetEnvironmentVariable("PATH", (($prefix -join ";") + ";" + $existing), "Process")
}
function Resolve-GitBashBinDir {
$candidates = @(
(Join-Path ${env:ProgramFiles} "Git\bin"),
(Join-Path ${env:ProgramFiles} "Git\usr\bin"),
(Join-Path ${env:ProgramFiles(x86)} "Git\bin"),
(Join-Path ${env:ProgramFiles(x86)} "Git\usr\bin")
)
# Also derive candidates from wherever `git` actually resolves on PATH.
# The fixed Program Files paths above miss non-standard installs (scoop,
# winget, portable Git). Without this, `WINDOWS_DIY_GIT_BASH_BIN` stays
# empty and `Get-Command bash` later resolves to WSL's System32 bash,
# which cannot open `D:/...` Windows paths (it needs `/mnt/d/...`).
$gitCmd = Get-Command git -ErrorAction SilentlyContinue
if ($null -ne $gitCmd -and -not [string]::IsNullOrWhiteSpace($gitCmd.Source)) {
$gitExeDir = Split-Path -Parent $gitCmd.Source # ...\cmd or ...\bin
$gitRoot = Split-Path -Parent $gitExeDir # install root
foreach ($root in @($gitRoot, (Split-Path -Parent $gitRoot))) {
if ([string]::IsNullOrWhiteSpace($root)) { continue }
$candidates += (Join-Path $root "bin")
$candidates += (Join-Path $root "usr\bin")
}
}
foreach ($candidate in $candidates) {
if ([string]::IsNullOrWhiteSpace($candidate)) { continue }
$bashExe = Join-Path $candidate "bash.exe"
if (Test-Path -LiteralPath $bashExe -PathType Leaf) {
return $candidate
}
}
return ""
}
function Convert-WindowsPathToMsys {
param([Parameter(Mandatory = $true)][string]$Path)
$normalized = $Path -replace '\\', '/'
if ($normalized -match '^([A-Za-z]):/(.*)$') {
$drive = $matches[1].ToLowerInvariant()
$rest = $matches[2]
if ([string]::IsNullOrWhiteSpace($rest)) {
return "/$drive"
}
return "/$drive/$rest"
}
return $normalized
}
function New-BashExeShim {
param(
[Parameter(Mandatory = $true)][string]$ShimsDir,
[Parameter(Mandatory = $true)][string]$CommandName,
[Parameter(Mandatory = $true)][string]$ExePath
)
if (-not (Test-Path -LiteralPath $ExePath -PathType Leaf)) {
return
}
$exeMsys = Convert-WindowsPathToMsys -Path $ExePath
$shimPath = Join-Path $ShimsDir $CommandName
$shimText = @"
#!/usr/bin/env bash
set -euo pipefail
exe_msys="$exeMsys"
exe_win="$ExePath"
if [ -x "`$exe_msys" ]; then
exec "`$exe_msys" "`$@"
fi
# WSL bash commonly mounts Windows drives under /mnt/<drive>, not /<drive>.
if [[ "`$exe_msys" =~ ^/([A-Za-z])/(.*)$ ]]; then
drive="`${BASH_REMATCH[1],,}"
rest="`${BASH_REMATCH[2]}"
exe_wsl="/mnt/`$drive/`$rest"
if [ -x "`$exe_wsl" ]; then
exec "`$exe_wsl" "`$@"
fi
fi
# Fallback for environments where wslpath is available and mounts are custom.
if command -v wslpath >/dev/null 2>&1; then
exe_wsl_dynamic="`$(wslpath -u "`$exe_win" 2>/dev/null || true)"
if [ -n "`$exe_wsl_dynamic" ] && [ -x "`$exe_wsl_dynamic" ]; then
exec "`$exe_wsl_dynamic" "`$@"
fi
fi
echo "ERROR: could not find executable for '$CommandName'." >&2
echo "Tried: `$exe_msys, `${exe_wsl:-<unset>}, `${exe_wsl_dynamic:-<unset>}, `$exe_win" >&2
exit 127
"@ -replace "`r`n", "`n"
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText($shimPath, $shimText, $utf8NoBom)
}
function Set-ExecutableAliasIfPresent {
param(
[Parameter(Mandatory = $true)][string]$Name,
[Parameter(Mandatory = $true)][string]$ExePath
)
if (Test-Path -LiteralPath $ExePath -PathType Leaf) {
Set-Alias -Name $Name -Value $ExePath -Scope Global
}
}
$repoRoot = Get-RepoRoot
$windowsDir = Join-Path $repoRoot "non-nix-build\windows"
$toolchainPath = Join-Path $windowsDir "toolchain-versions.env"
$toolchain = Parse-ToolchainVersions -Path $toolchainPath
# Dot-source ensure modules for install-on-demand bootstrap.
. "$windowsDir/toolchain-utils.ps1"
. "$windowsDir/ensure-rust.ps1"
. "$windowsDir/ensure-just.ps1"
. "$windowsDir/ensure-nextest.ps1"
. "$windowsDir/ensure-node.ps1"
. "$windowsDir/ensure-uv.ps1"
. "$windowsDir/ensure-nim.ps1"
. "$windowsDir/ensure-capnp.ps1"
. "$windowsDir/ensure-tup.ps1"
. "$windowsDir/ensure-dotnet.ps1"
. "$windowsDir/ensure-ct-remote.ps1"
. "$windowsDir/ensure-nargo.ps1"
. "$windowsDir/ensure-ttd.ps1"
. "$windowsDir/ensure-gcc.ps1"
. "$windowsDir/ensure-gnat.ps1"
. "$windowsDir/ensure-go.ps1"
. "$windowsDir/ensure-ldc.ps1"
. "$windowsDir/ensure-vlang.ps1"
. "$windowsDir/ensure-fpc.ps1"
. "$windowsDir/ensure-zstd.ps1"
. "$windowsDir/ensure-zlib.ps1"
. "$windowsDir/ensure-llvm.ps1"
$preferGitBash = ConvertTo-BoolFromEnv -Name "WINDOWS_DIY_PREFER_GIT_BASH" -Default $true
$gitBashBinDir = ""
if ($preferGitBash) {
$gitBashBinDir = Resolve-GitBashBinDir
if (-not [string]::IsNullOrWhiteSpace($gitBashBinDir)) {
Prepend-PathEntries -Entries @($gitBashBinDir)
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_GIT_BASH_BIN", $gitBashBinDir, "Process")
}
}
$installRoot = Get-DefaultInstallRoot
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_INSTALL_ROOT", $installRoot, "Process")
Set-EnvDefault -Name "NIM_WINDOWS_SOURCE_MODE" -Value "auto"
Set-EnvDefault -Name "NIM_WINDOWS_SOURCE_REPO" -Value $toolchain["NIM_SOURCE_REPO"]
Set-EnvDefault -Name "NIM_WINDOWS_SOURCE_REF" -Value $toolchain["NIM_SOURCE_REF"]
Set-EnvDefault -Name "NIM_WINDOWS_CSOURCES_REPO" -Value $toolchain["NIM_CSOURCES_REPO"]
Set-EnvDefault -Name "NIM_WINDOWS_CSOURCES_REF" -Value $toolchain["NIM_CSOURCES_REF"]
Set-EnvDefault -Name "CAPNP_WINDOWS_SOURCE_MODE" -Value "auto"
Set-EnvDefault -Name "CAPNP_WINDOWS_SOURCE_REPO" -Value $toolchain["CAPNP_SOURCE_REPO"]
Set-EnvDefault -Name "CAPNP_WINDOWS_SOURCE_REF" -Value $toolchain["CAPNP_SOURCE_REF"]
Set-EnvDefault -Name "TUP_WINDOWS_SOURCE_MODE" -Value "prebuilt"
Set-EnvDefault -Name "TUP_WINDOWS_SOURCE_REPO" -Value $toolchain["TUP_SOURCE_REPO"]
Set-EnvDefault -Name "TUP_WINDOWS_SOURCE_REF" -Value $toolchain["TUP_SOURCE_REF"]
Set-EnvDefault -Name "TUP_WINDOWS_SOURCE_BUILD_COMMAND" -Value $toolchain["TUP_SOURCE_BUILD_COMMAND"]
Set-EnvDefault -Name "TUP_WINDOWS_PREBUILT_VERSION" -Value $toolchain["TUP_PREBUILT_VERSION"]
Set-EnvDefault -Name "TUP_WINDOWS_PREBUILT_URL" -Value $toolchain["TUP_PREBUILT_URL"]
Set-EnvDefault -Name "TUP_WINDOWS_PREBUILT_SHA256" -Value $toolchain["TUP_PREBUILT_SHA256"]
Set-EnvDefault -Name "TUP_WINDOWS_MSYS2_BASE_VERSION" -Value $toolchain["TUP_MSYS2_BASE_VERSION"]
Set-EnvDefault -Name "TUP_WINDOWS_MSYS2_PACKAGES" -Value $toolchain["TUP_MSYS2_PACKAGES"]
Set-EnvDefault -Name "CT_REMOTE_WINDOWS_SOURCE_MODE" -Value "auto"
Set-EnvDefault -Name "CT_REMOTE_WINDOWS_SOURCE_REPO" -Value (Join-Path $repoRoot "..\codetracer-ci")
[Environment]::SetEnvironmentVariable("RUSTUP_HOME", (Join-Path $installRoot "rustup"), "Process")
[Environment]::SetEnvironmentVariable("CARGO_HOME", (Join-Path $installRoot "cargo"), "Process")
$doSync = ConvertTo-BoolFromEnv -Name "WINDOWS_DIY_SYNC" -Default $true
if ($doSync) {
$arch = Get-WindowsArch
# Phase 1: No dependencies
if (Test-BootstrapStepEnabled "TTD") { Ensure-Ttd -Root $installRoot }
if (Test-BootstrapStepEnabled "NODE") { Ensure-Node -Root $installRoot -Arch $arch -Toolchain $toolchain }
if (Test-BootstrapStepEnabled "UV") { Ensure-Uv -Root $installRoot -Arch $arch -Toolchain $toolchain }
if (Test-BootstrapStepEnabled "GCC") { Ensure-Gcc -Root $installRoot -Toolchain $toolchain }
if (Test-BootstrapStepEnabled "GNAT") { Ensure-Gnat -Root $installRoot -Toolchain $toolchain }
if (Test-BootstrapStepEnabled "GO") { Ensure-Go -Root $installRoot -Arch $arch -Toolchain $toolchain }
if (Test-BootstrapStepEnabled "LDC") { Ensure-Ldc -Root $installRoot -Arch $arch -Toolchain $toolchain }
if (Test-BootstrapStepEnabled "VLANG") { Ensure-Vlang -Root $installRoot -Arch $arch -Toolchain $toolchain }
if (Test-BootstrapStepEnabled "FPC") { Ensure-Fpc -Root $installRoot -Arch $arch -Toolchain $toolchain }
if (Test-BootstrapStepEnabled "ZSTD") { Ensure-Zstd -Root $installRoot -Arch $arch -Toolchain $toolchain }
# Ensure-Zlib must run after Ensure-Gcc (depends on mingw32-make + gcc).
if (Test-BootstrapStepEnabled "ZLIB") { Ensure-Zlib -Root $installRoot -Arch $arch -Toolchain $toolchain }
if (Test-BootstrapStepEnabled "LLVM") { Ensure-Llvm -Root $installRoot -Arch $arch -Toolchain $toolchain }
# Phase 2: Rust (no deps on other managed tools)
if (Test-BootstrapStepEnabled "RUST") { Ensure-Rust -Root $installRoot -Arch $arch -Toolchain $toolchain }
# Phase 3: Depends on Rust/cargo
if (Test-BootstrapStepEnabled "JUST") { Ensure-Just -Root $installRoot -Toolchain $toolchain }
if (Test-BootstrapStepEnabled "NEXTEST") { Ensure-Nextest -Root $installRoot -Toolchain $toolchain }
# Phase 4: May need MSYS2 for source builds
if (Test-BootstrapStepEnabled "NIM") { Ensure-Nim -Root $installRoot -Arch $arch -Toolchain $toolchain }
if (Test-BootstrapStepEnabled "CAPNP") { Ensure-Capnp -Root $installRoot -Arch $arch -Toolchain $toolchain }
if (Test-BootstrapStepEnabled "TUP") { Ensure-Tup -Root $installRoot -Toolchain $toolchain }
# Phase 5: Depends on Rust + MSYS2
if (Test-BootstrapStepEnabled "NARGO") { Ensure-Nargo -Root $installRoot -Toolchain $toolchain -RepoRoot $repoRoot }
# Phase 6: dotnet and tools that depend on it
if (Test-BootstrapStepEnabled "DOTNET") { Ensure-Dotnet -Root $installRoot -Toolchain $toolchain }
if (Test-BootstrapStepEnabled "CT_REMOTE") { Ensure-CtRemote -Root $installRoot -Arch $arch -Toolchain $toolchain -WindowsDir $windowsDir }
}
$arch = Get-WindowsArch
$nodeArch = ConvertTo-NodeFileArch -Arch $arch
if ([string]::IsNullOrWhiteSpace([Environment]::GetEnvironmentVariable("CT_REMOTE_WINDOWS_SOURCE_RID"))) {
$rid = if ($nodeArch -eq "arm64") { "win-arm64" } else { "win-x64" }
[Environment]::SetEnvironmentVariable("CT_REMOTE_WINDOWS_SOURCE_RID", $rid, "Process")
}
$nodeDir = Join-Path $installRoot ("node\" + $toolchain["NODE_VERSION"] + "\node-v" + $toolchain["NODE_VERSION"] + "-win-" + $nodeArch)
$uvDir = Join-Path $installRoot ("uv\" + $toolchain["UV_VERSION"])
$dotnetPinnedVersion = $toolchain["DOTNET_SDK_VERSION"]
$msvcToolsetPinnedVersion = $toolchain["MSVC_TOOLSET_VERSION"]
$ttdMinVersion = $toolchain["TTD_MIN_VERSION"]
$windbgMinVersion = $toolchain["WINDBG_MIN_VERSION"]
[Environment]::SetEnvironmentVariable("DOTNET_SDK_VERSION", $dotnetPinnedVersion, "Process")
$dotnetRoot = Resolve-DotnetRoot -InstallRoot $installRoot -PinnedSdkVersion $dotnetPinnedVersion
$dotnetExe = Join-Path $dotnetRoot "dotnet.exe"
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_TTD_EXE", "", "Process")
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_TTD_DIR", "", "Process")
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_TTD_VERSION", "", "Process")
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_TTD_REPLAY_DLL", "", "Process")
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_TTD_REPLAY_CPU_DLL", "", "Process")
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_WINDBG_DIR", "", "Process")
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_WINDBG_VERSION", "", "Process")
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_CDB_EXE", "", "Process")
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_DBGENG_DLL", "", "Process")
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_DBGMODEL_DLL", "", "Process")
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_DBGHELP_DLL", "", "Process")
[Environment]::SetEnvironmentVariable("TTD_MIN_VERSION", $ttdMinVersion, "Process")
[Environment]::SetEnvironmentVariable("WINDBG_MIN_VERSION", $windbgMinVersion, "Process")
$ttdRuntime = Resolve-TtdRuntimeInfo
$ttdExe = [string]$ttdRuntime["ttdExe"]
$cdbExe = [string]$ttdRuntime["cdbExe"]
$dbgengDll = [string]$ttdRuntime["dbgengDll"]
$dbgmodelDll = [string]$ttdRuntime["dbgmodelDll"]
$dbghelpDll = [string]$ttdRuntime["dbghelpDll"]
if (-not [string]::IsNullOrWhiteSpace($ttdExe)) {
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_TTD_EXE", $ttdExe, "Process")
}
if (-not [string]::IsNullOrWhiteSpace([string]$ttdRuntime["ttdInstallDir"])) {
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_TTD_DIR", [string]$ttdRuntime["ttdInstallDir"], "Process")
}
if (-not [string]::IsNullOrWhiteSpace([string]$ttdRuntime["ttdVersion"])) {
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_TTD_VERSION", [string]$ttdRuntime["ttdVersion"], "Process")
}
if (-not [string]::IsNullOrWhiteSpace([string]$ttdRuntime["ttdReplayDll"])) {
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_TTD_REPLAY_DLL", [string]$ttdRuntime["ttdReplayDll"], "Process")
}
if (-not [string]::IsNullOrWhiteSpace([string]$ttdRuntime["ttdReplayCpuDll"])) {
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_TTD_REPLAY_CPU_DLL", [string]$ttdRuntime["ttdReplayCpuDll"], "Process")
}
if (-not [string]::IsNullOrWhiteSpace([string]$ttdRuntime["windbgInstallDir"])) {
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_WINDBG_DIR", [string]$ttdRuntime["windbgInstallDir"], "Process")
}
if (-not [string]::IsNullOrWhiteSpace([string]$ttdRuntime["windbgVersion"])) {
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_WINDBG_VERSION", [string]$ttdRuntime["windbgVersion"], "Process")
}
if (-not [string]::IsNullOrWhiteSpace([string]$ttdRuntime["cdbExe"])) {
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_CDB_EXE", [string]$ttdRuntime["cdbExe"], "Process")
}
if (-not [string]::IsNullOrWhiteSpace([string]$ttdRuntime["dbgengDll"])) {
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_DBGENG_DLL", [string]$ttdRuntime["dbgengDll"], "Process")
}
if (-not [string]::IsNullOrWhiteSpace([string]$ttdRuntime["dbgmodelDll"])) {
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_DBGMODEL_DLL", [string]$ttdRuntime["dbgmodelDll"], "Process")
}
if (-not [string]::IsNullOrWhiteSpace([string]$ttdRuntime["dbghelpDll"])) {
[Environment]::SetEnvironmentVariable("WINDOWS_DIY_DBGHELP_DLL", [string]$ttdRuntime["dbghelpDll"], "Process")
}
$ensureTtd = ConvertTo-BoolFromEnv -Name "WINDOWS_DIY_ENSURE_TTD" -Default $true
if ($ensureTtd) {
if ([string]::IsNullOrWhiteSpace($ttdExe)) {
throw "Microsoft Time Travel Debugging is not available. Install with: winget install --id Microsoft.TimeTravelDebugging --exact --source winget"
}
if ([string]::IsNullOrWhiteSpace([string]$ttdRuntime["ttdReplayDll"])) {
throw "TTDReplay.dll was not found. Ensure Microsoft.TimeTravelDebugging is correctly installed from winget."
}
if ([string]::IsNullOrWhiteSpace([string]$ttdRuntime["ttdVersion"])) {
throw "Could not determine installed Microsoft.TimeTravelDebugging package version via Get-AppxPackage."
}
Assert-MinVersion -DisplayName "Microsoft.TimeTravelDebugging" -ActualVersion ([string]$ttdRuntime["ttdVersion"]) -MinVersion $ttdMinVersion -InstallHint "winget install --id Microsoft.TimeTravelDebugging --exact --source winget"
if ([string]::IsNullOrWhiteSpace([string]$ttdRuntime["windbgVersion"])) {
throw "Could not determine installed Microsoft.WinDbg package version via Get-AppxPackage. Install with: winget install --id Microsoft.WinDbg --exact --source winget"
}
Assert-MinVersion -DisplayName "Microsoft.WinDbg" -ActualVersion ([string]$ttdRuntime["windbgVersion"]) -MinVersion $windbgMinVersion -InstallHint "winget install --id Microsoft.WinDbg --exact --source winget"
}
[Environment]::SetEnvironmentVariable("DOTNET_SDK_VERSION_EFFECTIVE", $dotnetPinnedVersion, "Process")
$ensureDotnet = ConvertTo-BoolFromEnv -Name "WINDOWS_DIY_ENSURE_DOTNET" -Default $true
if ($ensureDotnet) {
Assert-DotnetSdkPresent -DotnetExe $dotnetExe -PinnedSdkVersion $dotnetPinnedVersion
}
[Environment]::SetEnvironmentVariable("DOTNET_ROOT", $dotnetRoot, "Process")
$nodePackagesBin = Join-Path (Join-Path $repoRoot "node-packages") "node_modules\.bin"
$nimVersionRoot = Join-Path $installRoot ("nim\" + $toolchain["NIM_VERSION"])
$nimDir = Resolve-InstallDirFromRelativePathFile -InstallRoot $installRoot -RelativePathFile (Join-Path $nimVersionRoot "nim.install.relative-path")
if ([string]::IsNullOrWhiteSpace($nimDir)) {
$prebuiltNim = Join-Path $nimVersionRoot ("prebuilt\nim-" + $toolchain["NIM_VERSION"])
if (Test-Path -LiteralPath $prebuiltNim -PathType Container) {