Skip to content

Commit 8af84e7

Browse files
Merge pull request #1628 from PowerShell/andschwa/applem1
Fix build for Apple M1 when running PowerShell 7.2 (arm64)
2 parents fb8ee82 + d27c156 commit 8af84e7

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
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.

test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
<ProjectReference Include="..\PowerShellEditorServices.Test.Shared\PowerShellEditorServices.Test.Shared.csproj" />
1818
</ItemGroup>
1919

20+
<!-- This is for testing PowerShell 7.2 LTS -->
2021
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0' ">
21-
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.2.0-preview.3" />
22+
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.2.0" />
2223
</ItemGroup>
2324

25+
<!-- This is for testing PowerShell 7.0 LTS -->
2426
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
25-
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.6" />
27+
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.8" />
2628
</ItemGroup>
2729

2830
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">

0 commit comments

Comments
 (0)