|
12 | 12 | ##
|
13 | 13 | ##===----------------------------------------------------------------------===##
|
14 | 14 |
|
15 |
| -# In newer Visual C++ Tools they've added compiler intrinsics headers in wchar.h |
16 |
| -# that end up creating a cyclic dependency between the `ucrt` and compiler intrinsics modules. |
17 |
| -# Newer versions of swift (6.2) have a fixed modulemap that resolves the issue: https://github.com/swiftlang/swift/pull/79751 |
18 |
| -$windowsSdkVersion = "10.0.22000.0" |
19 |
| -$vcToolsVersion = "14.43.34808" |
20 |
| - |
21 |
| -# As a workaround we can pin the tools/SDK versions to older versions that are present in the GH Actions Windows image. |
22 |
| -# In the future we may only want to apply this workaround to older versions of Swift that don't have the fixed module map. |
23 |
| -$jsonFilePath = "./assets/test/.vscode/settings.json" |
24 |
| -try { |
25 |
| - $jsonContent = Get-Content -Raw -Path $jsonFilePath | ConvertFrom-Json |
26 |
| -} catch { |
27 |
| - Write-Host "Invalid JSON content in $jsonFilePath" |
28 |
| - exit 1 |
29 |
| -} |
30 |
| -if ($jsonContent.PSObject.Properties['swift.buildArguments']) { |
31 |
| - $jsonContent.PSObject.Properties.Remove('swift.buildArguments') |
32 |
| -} |
| 15 | +function Update-SwiftBuildAndPackageArguments { |
| 16 | + param ( |
| 17 | + [string]$jsonFilePath = "./assets/test/.vscode/settings.json", |
| 18 | + [string]$windowsSdkVersion = "10.0.22000.0", |
| 19 | + [string]$vcToolsVersion = "14.43.34808" |
| 20 | + ) |
| 21 | + |
| 22 | + $windowsSdkRoot = "C:\Program Files (x86)\Windows Kits\10\" |
| 23 | + |
| 24 | + try { |
| 25 | + $jsonContent = Get-Content -Raw -Path $jsonFilePath | ConvertFrom-Json |
| 26 | + } catch { |
| 27 | + Write-Host "Invalid JSON content in $jsonFilePath" |
| 28 | + exit 1 |
| 29 | + } |
| 30 | + |
| 31 | + if ($jsonContent.PSObject.Properties['swift.buildArguments']) { |
| 32 | + $jsonContent.PSObject.Properties.Remove('swift.buildArguments') |
| 33 | + } |
| 34 | + |
| 35 | + $jsonContent | Add-Member -MemberType NoteProperty -Name "swift.buildArguments" -Value @( |
| 36 | + "-Xbuild-tools-swiftc", "-windows-sdk-root", "-Xbuild-tools-swiftc", $windowsSdkRoot, |
| 37 | + "-Xbuild-tools-swiftc", "-windows-sdk-version", "-Xbuild-tools-swiftc", $windowsSdkVersion, |
| 38 | + "-Xbuild-tools-swiftc", "-visualc-tools-version", "-Xbuild-tools-swiftc", $vcToolsVersion, |
| 39 | + "-Xswiftc", "-windows-sdk-root", "-Xswiftc", $windowsSdkRoot, |
| 40 | + "-Xswiftc", "-windows-sdk-version", "-Xswiftc", $windowsSdkVersion, |
| 41 | + "-Xswiftc", "-visualc-tools-version", "-Xswiftc", $vcToolsVersion |
| 42 | + ) |
| 43 | + |
| 44 | + if ($jsonContent.PSObject.Properties['swift.packageArguments']) { |
| 45 | + $jsonContent.PSObject.Properties.Remove('swift.packageArguments') |
| 46 | + } |
33 | 47 |
|
34 |
| -$windowsSdkRoot = "C:\Program Files (x86)\Windows Kits\10\" |
| 48 | + $jsonContent | Add-Member -MemberType NoteProperty -Name "swift.packageArguments" -Value @( |
| 49 | + "-Xbuild-tools-swiftc", "-windows-sdk-root", "-Xbuild-tools-swiftc", $windowsSdkRoot, |
| 50 | + "-Xbuild-tools-swiftc", "-windows-sdk-version", "-Xbuild-tools-swiftc", $windowsSdkVersion, |
| 51 | + "-Xbuild-tools-swiftc", "-visualc-tools-version", "-Xbuild-tools-swiftc", $vcToolsVersion, |
| 52 | + "-Xswiftc", "-windows-sdk-root", "-Xswiftc", $windowsSdkRoot, |
| 53 | + "-Xswiftc", "-windows-sdk-version", "-Xswiftc", $windowsSdkVersion, |
| 54 | + "-Xswiftc", "-visualc-tools-version", "-Xswiftc", $vcToolsVersion |
| 55 | + ) |
35 | 56 |
|
36 |
| -$jsonContent | Add-Member -MemberType NoteProperty -Name "swift.buildArguments" -Value @( |
37 |
| - "-Xbuild-tools-swiftc", "-windows-sdk-root", "-Xbuild-tools-swiftc", $windowsSdkRoot, |
38 |
| - "-Xbuild-tools-swiftc", "-windows-sdk-version", "-Xbuild-tools-swiftc", $windowsSdkVersion, |
39 |
| - "-Xbuild-tools-swiftc", "-visualc-tools-version", "-Xbuild-tools-swiftc", $vcToolsVersion, |
40 |
| - "-Xswiftc", "-windows-sdk-root", "-Xswiftc", $windowsSdkRoot, |
41 |
| - "-Xswiftc", "-windows-sdk-version", "-Xswiftc", $windowsSdkVersion, |
42 |
| - "-Xswiftc", "-visualc-tools-version", "-Xswiftc", $vcToolsVersion |
43 |
| -) |
| 57 | + $jsonContent | ConvertTo-Json -Depth 32 | Set-Content -Path $jsonFilePath |
44 | 58 |
|
45 |
| -if ($jsonContent.PSObject.Properties['swift.packageArguments']) { |
46 |
| - $jsonContent.PSObject.Properties.Remove('swift.packageArguments') |
| 59 | + Write-Host "Contents of ${jsonFilePath}:" |
| 60 | + Get-Content -Path $jsonFilePath |
47 | 61 | }
|
48 | 62 |
|
49 |
| -$jsonContent | Add-Member -MemberType NoteProperty -Name "swift.packageArguments" -Value @( |
50 |
| - "-Xbuild-tools-swiftc", "-windows-sdk-root", "-Xbuild-tools-swiftc", $windowsSdkRoot, |
51 |
| - "-Xbuild-tools-swiftc", "-windows-sdk-version", "-Xbuild-tools-swiftc", $windowsSdkVersion, |
52 |
| - "-Xbuild-tools-swiftc", "-visualc-tools-version", "-Xbuild-tools-swiftc", $vcToolsVersion, |
53 |
| - "-Xswiftc", "-windows-sdk-root", "-Xswiftc", $windowsSdkRoot, |
54 |
| - "-Xswiftc", "-windows-sdk-version", "-Xswiftc", $windowsSdkVersion, |
55 |
| - "-Xswiftc", "-visualc-tools-version", "-Xswiftc", $vcToolsVersion |
56 |
| -) |
| 63 | +$swiftVersionOutput = & swift --version |
| 64 | +if ($LASTEXITCODE -ne 0) { |
| 65 | + Write-Host "Failed to execute 'swift --version'" |
| 66 | + exit 1 |
| 67 | +} |
| 68 | + |
| 69 | +Write-Host "Swift version:" |
| 70 | +Write-Host "$swiftVersionOutput" |
| 71 | + |
| 72 | +$versionLine = $swiftVersionOutput[0] |
| 73 | +if ($versionLine -match "Swift version (\d+)\.(\d+)") { |
| 74 | + Write-Host "Matched Swift version: $($matches[0]), $($matches[1]), $($matches[2])" |
57 | 75 |
|
58 |
| -$jsonContent | ConvertTo-Json -Depth 32 | Set-Content -Path $jsonFilePath |
| 76 | + $majorVersion = [int]$matches[1] |
| 77 | + $minorVersion = [int]$matches[2] |
59 | 78 |
|
60 |
| -Write-Host "Contents of ${jsonFilePath}:" |
61 |
| -Get-Content -Path $jsonFilePath |
| 79 | + # In newer Visual C++ Tools they've added compiler intrinsics headers in wchar.h |
| 80 | + # that end up creating a cyclic dependency between the `ucrt` and compiler intrinsics modules. |
| 81 | + |
| 82 | + # Newer versions of swift (>=6.1) have a fixed modulemap that resolves the issue: https://github.com/swiftlang/swift/pull/79751 |
| 83 | + # As a workaround we can pin the tools/SDK versions to older versions that are present in the GH Actions Windows image. |
| 84 | + # In the future we may only want to apply this workaround to older versions of Swift that don't have the fixed module map. |
| 85 | + if ($majorVersion -lt 6 -or ($majorVersion -eq 6 -and $minorVersion -lt 1)) { |
| 86 | + Write-Host "Swift version is < 6.1, injecting windows SDK build arguments" |
| 87 | + Update-SwiftBuildAndPackageArguments |
| 88 | + } |
| 89 | +} else { |
| 90 | + Write-Host "Match failed for output: `"$versionLine`"" |
| 91 | + Write-Host "Unable to determine Swift version" |
| 92 | + exit 1 |
| 93 | +} |
62 | 94 |
|
63 | 95 | npm ci -ignore-script node-pty
|
64 | 96 | npm run lint
|
|
0 commit comments