lulu2203
lulu2203

Reputation: 25

gRPC support for Windows on ARM for HoloLens 2

I want to build my Unity-AR Apps to run on HoloLens 2. We use gRPC for interprocess communication of the HoloLens device and a desktop PC to pass information. HoloLens 2 has an ARM processor architecture, for which gRPC does not provide a grpc_csharp_ext.dll.

Does anyone already had the same problem and how did you solve it?

*Edit: I use Unity for app development, so I'm limited to .NET Framework & .NET Standard solutions

Upvotes: 2

Views: 1403

Answers (1)

aleneum
aleneum

Reputation: 2273

This is a merged copy/paste from my comments in the grpc issue tracker here and here

Edit: I published a Unity project with precompiled libraries for x86, x64 and arm64 on Github.

My workaround for this problem involves compiling a Grpc.Core.dll without the Mono and DllImportsFromStaticLib which is used for WSA builds AND an ARM64 version of the grpc_charp_ext.dll which isn't part of the official Unity package but necessary for HoloLens 2.

  • Download a daily build unity package (e.g. this one) and unzip it. This is version 1.25-dev. I have tried more recent 1.26-dev daily builds but unfortunately grpc_charp_ext.dll is not correctly loaded in the HoloLens emulator for these builds. I also tried the most recent version (1.29.1) vcpkg has to offer but unfortunately there is a Protobuf/System.Memory version conflict (#22251) which hasnt been resolved yet, afaik.
  • clone grpc and checkout the daily build commit:
    • git checkout 8853754e8caa0b2ffb3ab0e25514f3f7612ebf7a if you use the build above
  • init submodules: git submodule update --init
  • If you are like me and don't want to install outdated build tools you can change the used Visual Studio version in tools\run_tests\helper_scripts\pre_build_csharp.bat. I used "Visual Studio 15 2017" instead of "Visual Studio 14 2015".
  • build grpc_charp_ext:
    • python tools/run_tests/run_tests.py -l csharp -c opt --build_only
  • If everything works well, you will end up with some Microsoft.Build.Tasks.Git.targets exceptions when the Python script attempts to build the C# project. It's probably related to some outdated SourceLink dependency or something. Nevertheless, the project will build just fine with Visual Studio 2019.
  • Apply grpc-no-static.patch.txt
  • Open Grpc.sln and compile a Release build
  • Copy the resulting Grpc.Core.dll into Plugins/Grcp.Core/lib/net45_wsa of the downloaded package

  • If you followed these steps, you should have something that works with Unity and HoloLens 1, now the part that makes it work with HoloLens2.
  • Clone vcpkg and checkout the tag 2020.01. I don't know whether checking out 2020.01 is actually necessary but it contains the grpc version closest to 1.25
    • git clone https://github.com/microsoft/vcpkg.git
    • git checkout 2020.01
  • You have to edit the grpc port to build the correct version. Download 00001-fix-uwp.patch.txt, 00002-static-linking-in-linux.patch.txt and portfile.cmake.txt, remove the .txt ending and override the files located at ports\grpc.
  • Copy the Plugins folder into your Unity project
  • Make sure that Grpc.Core.dll in the folder net45_wsa is only used for WSA builds and the original build EXCLUDES Grpc.Core.dll in net45_wsa:

Grpc Core_wsa

  • Make sure that grpc_charp_ext in Grpc.Core/runtimes/win/x86 and x64 is exported correctly (correct arch) for WSA:

grpc_cscharp_ext

  • Next you have to backport a triplet configuration: Download arm64-windows-static.cmake.txt, rename it and put it into triplets\community
  • Now bootstrap vcpkg and build protobuf:x86-windows and grpc with the arm64-windows-static triplet
    • .\vcpkg.exe install protobuf:x86-windows
    • .\vcpkg.exe install grpc --triplet arm64-windows-static
  • Copy the generated file buildtrees\grpc\arm64-windows-static-rel\grpc_csharp_ext.dll into your Plugin folder (Grpc.Core\runtimes\win\arm64) and set the target for this DLL: arm64_ext
  • Export and build your project

Upvotes: 3

Related Questions