Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to test .NET on macOS Arm64 #21404

Closed
richlander opened this issue Sep 25, 2021 · 1 comment
Closed

How to test .NET on macOS Arm64 #21404

richlander opened this issue Sep 25, 2021 · 1 comment

Comments

@richlander
Copy link
Member

richlander commented Sep 25, 2021

Arm64 + x64 emulation test plan

This is a good take on testing this new environment.

Can be straightforwardly adapted to Windows. That's what I'll be doing.

There are a few places where you'll likely run into troubles. These instructions likely won't work well for the general public until RC2 is released. The nightly builds are currently broken. I ran through all of this with internal builds.

Start with Arm64

First, install an Arm64 build.

Note: The instructions for each scenario assume you got back somewhere rational, like cd ~.

Run an app.

  • dotnet new console -o app
  • cd app
  • dotnet run
  • Update the app to report the processor architecture, with the following change to Program.cs
  • dotnet run
  • You should see "Arm64".

Update to Program.cs

using System.Runtime.InteropServices;

Console.WriteLine($"Hello, {RuntimeInformation.OSArchitecture}!");

Install a tool (best to use a random name due to name squatting).

  • dotnet new console -o app4321
  • cd app4321
  • Apply the same Program.cs change as above.
  • dotnet pack -p:PackAsTool=true
  • dotnet tool install -g app4321 --add-source bin/Debug
  • app4321

Note: Use codesign -s - ~/.dotnet/tools/app4321 if the tool is killed by the macOS notary.

Use dotnet-watch with an ASP.NET app.

  • dotnet new webapp -o webapp
  • cd webapp
  • code .
  • dotnet watch run
  • open web app in browser
  • Make the home page say "Welcome Arm64", with two changes to Index.cshtml:
    • Line 2: `@using System.Runtime.InteropServices
    • Line 9: <h1 class="display-4">Welcome @RuntimeInformation.OSArchitecture</h1>
  • Save
  • App should refresh and you will see the expected text.
  • CTRL-C

Run tests.

  • dotnet new xunit -o tests
  • cd tests
  • dotnet test

Test x64 emulation

Install the .NET 6 x64 SDK. We're primarily installing the SDK to get the runtimes, as opposed to using the SDK itself.

Repeat the tasks but with arch-specific flags that coerce the us of the x64 runtime.

Note: It is assumed all the same apps exist as directed above. Commands are not provided to re-create them.

Run app with x64 runtime.

  • cd app
  • dotnet run -a x64
  • You should see "x64".
  • dotnet run
  • You should see "Arm64"

Run the tool.

  • cd app4321
  • dotnet tool uninstall -g app4321
  • dotnet tool install -g app4321 --add-source bin/Debug -a x64
  • app4321
  • You should see x64
  • dotnet tool uninstall -g app4321
  • dotnet tool install -g app4321 --add-source bin/Debug
  • You should see Arm64
  • dotnet tool uninstall -g app4321

Note: Use codesign -s - ~/.dotnet/tools/app4321 if the tool is killed by the macOS notary.

Use dotnet-watch with an ASP.NET app.

  • cd webapp
  • dotnet watch run -a x64
  • You should see "x64"
  • CTRL-C
  • dotnet watch run
  • You should see "Arm64"
  • CTRL-C

Run tests.

Validate the x64 test

We should also ensure the x64 SDK works. Here's one trick for easily using the x64 SDK.

  • export OLDPATH=$PATH

  • export PATH=/usr/local/share/dotnet/x64:$PATH

  • dotnet --info | grep RID

  • You should see x64.

  • cd app

  • dotnet run

  • You should see x64.

  • dotnet run -a arm64

  • This currently fails.

Let's try the tool.

  • dotnet tool uninstall -g app4321
  • dotnet tool install -g app4321 --add-source bin/Debug
  • app4321
  • You should see "X64"
  • dotnet tool uninstall -g app4321
  • dotnet tool install -g app4321 --add-source bin/Debug -a arm64
  • app4321
  • You should see "arm64"
  • This currently fails.

Note: Use codesign -s - ~/.dotnet/tools/app4321 if the tool is killed by the macOS notary.

Let's try dotnet watch.

  • cd webapp
  • dotnet watch run
  • You should see "x64"
  • CTRL-C
  • dotnet watch run -a arm64
  • You should see "Arm64"
  • CTRL-C
  • This currently fails.

Let's finish up with testing.

  • cd tests
  • dotnet test
  • Should pass
  • dotnet test --arch arm64
  • This currently fails

Let's fixup the path back.

  • export PATH=$OLDPATH

Test .NET Core 3.1 (x64 only)

Download the latest .NET Core 3.1 ASP.NET Core binaries package and unpack to the x64 hive.

  • sudo tar -xf Downloads/aspnetcore-runtime-3.1.19-osx-x64.tar.gz -C /usr/local/share/dotnet/x64

Let's validate we are using the Arm64 SDK.

  • dotnet --info | grep RID
  • Should see "arm64"

We now need a .NET Core 3.1 app. We can use the .NET Core repo for that.

  • git clone https://github.com/dotnet/core
  • cd core/samples/dotnet-runtimeinfo
  • dotnet run
  • Should see "x64"

We can try an official tool now.

  • dotnet tool install -g dotnet-runtimeinfo
  • dotnet-runtimeinfo
  • Should install as x64, but [currently installs as Arm64(https://github.com/dotnet install does not create signed apphost on macOS Arm64 #21349) as will run that way.
  • dotnet tool uninstall -g dotnet-runtimeinfo
  • dotnet tool install -g dotnet-runtimeinfo -a x64
  • dotnet-runtimeinfo
  • Should show "x64"

Note: Use codesign -s - ~/.dotnet/tools/dotnet-runtimeinfo if the tool is killed by the macOS notary.

We can use dotnet-watch on the dotnet-runtimeinfo source.

  • dotnet watch run
  • Should run as x64.
  • CTRL-C

Let's try same with the x64 SDK.

  • /usr/local/share/dotnet/x64/dotnet watch run
  • Should run as x64.
  • CTRL-C

Let's try testing, but using the test sample from above.

  • cd tests
  • Change TargetFramework to netcoreapp3.1 in the project file.
  • Remove the Nullable line from the project file.
  • Remove the @namespace line in Program.cs
  • dotnet test
  • This currently fails.
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-dotnet test untriaged Request triage from a team member labels Sep 25, 2021
@MarcoRossignoli
Copy link
Member

MarcoRossignoli commented Nov 18, 2021

dotnet test fixed in 6.0.200/7.0.100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants