Skip to content

Commit f2e306f

Browse files
committed
Fix build for Apple M1 when running PowerShell 7.2 (arm64)
The previous fix assumed PowerShell was always running in an emulated mode (i.e. running PowerShell (x64) but on an Apple M1). Now that PowerShell 7.2 has a native build for Apple M1 (arm64) the check needs to handle both cases. We must also skip asking `dotnet-install` to install the 3.1 or 5.0 .NET Runtimes on an Apple M1 because they don't exist, but their installer tries to get them anyway. This was a non-breaking bug previously where the macOS x64 runtimes would be installed, but not used.
1 parent fb8ee82 commit f2e306f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

PowerShellEditorServices.build.ps1

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ $script:dotnetTestArgs = @(
2929
)
3030

3131
$script:IsNix = $IsLinux -or $IsMacOS
32-
$script:IsRosetta = $IsMacOS -and (sysctl -n sysctl.proc_translated) -eq 1 # Mac M1
32+
# For Apple M1, pwsh might be getting emulated, in which case we need to check
33+
# for the proc_translated flag, otherwise we can check the architecture.
34+
$script:IsAppleM1 = $IsMacOS -and ((sysctl -n sysctl.proc_translated) -eq 1 -or (uname -m) -eq "arm64")
3335
$script:BuildInfoPath = [System.IO.Path]::Combine($PSScriptRoot, "src", "PowerShellEditorServices.Hosting", "BuildInfo.cs")
3436
$script:PsesCommonProps = [xml](Get-Content -Raw "$PSScriptRoot/PowerShellEditorServices.Common.props")
3537

@@ -110,8 +112,12 @@ task SetupDotNet -Before Clean, Build, TestServerWinPS, TestServerPS7, TestServe
110112

111113
if (!(Test-Path $dotnetExePath)) {
112114
# TODO: Test .NET 5 with PowerShell 7.1
115+
#
116+
# We use the .NET 6 SDK, so we always install it and its runtime.
113117
Install-Dotnet -Channel '6.0' # SDK and runtime
114-
Install-Dotnet -Channel '3.1','5.0' -Runtime # Runtime only
118+
# Anywhere other than on a Mac with an M1 processor, we additionally
119+
# install the .NET 3.1 and 5.0 runtimes (but not their SDKs).
120+
if (!$script:IsAppleM1) { Install-Dotnet -Channel '3.1','5.0' -Runtime }
115121
}
116122

117123
# This variable is used internally by 'dotnet' to know where it's installed
@@ -235,7 +241,7 @@ task TestServerWinPS -If (-not $script:IsNix) {
235241
exec { & $script:dotnetExe $script:dotnetTestArgs $script:NetRuntime.Desktop }
236242
}
237243

238-
task TestServerPS7 -If (-not $script:IsRosetta) {
244+
task TestServerPS7 -If (-not $script:IsAppleM1) {
239245
Set-Location .\test\PowerShellEditorServices.Test\
240246
exec { & $script:dotnetExe $script:dotnetTestArgs $script:NetRuntime.PS7 }
241247
}
@@ -249,7 +255,7 @@ task TestE2E {
249255
Set-Location .\test\PowerShellEditorServices.Test.E2E\
250256

251257
$env:PWSH_EXE_NAME = if ($IsCoreCLR) { "pwsh" } else { "powershell" }
252-
$NetRuntime = if ($IsRosetta) { $script:NetRuntime.PS72 } else { $script:NetRuntime.PS7 }
258+
$NetRuntime = if ($IsAppleM1) { $script:NetRuntime.PS72 } else { $script:NetRuntime.PS7 }
253259
exec { & $script:dotnetExe $script:dotnetTestArgs $NetRuntime }
254260

255261
# Run E2E tests in ConstrainedLanguage mode.

0 commit comments

Comments
 (0)