-
Notifications
You must be signed in to change notification settings - Fork 10.6k
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
gRPC support for HoloLens2 with Unity #23488
Comments
I have the same goal: to run grpc on HoloLens 2. I have compiled grpc for ARM64 with vcpkg as you said. In my Unity project (Unity 2019.3.15f1) I use the package MSBuildForUnity to install the packages Google.Protobuf and Grpc.Core. I have created a Plugins folder in Assets where I copy the grpc_csharp_ext.dll for x64 and ARM64. I set up for each dll (Inspector) its corresponding platform. The dll for x64 is from UnityApp\Assets\Dependencies\net46\grpc_csharp_ext.x64.dll (I renamed the file as grpc_csharp_ext.dll, not sure yet why Unity does not find this dll automatically when you press Play button) and the dll for ARM64 is from \vcpkg\buildtrees\grpc\arm64-windows-dbg\grpc_csharp_ext.dll. After I checked that everything works in Unity editor, I built the Visual Studio project in Unity. In Visual Studio 2019, when I build the project for ARM64 I have a lot of linking errors like: Severity Code Description Project File Line Suppression State Could the errors come from having different grpc versions? The version of grpc in cvpkg is 1.29.1 while the version downloaded by MSBuildForUnity is 2.30.0. I have tried to download the version 1.29.1 but there isn´t this version of the NuGet package. The closest version of grpc that I can get is 2.23 (not 1.29.1). I have also tried with this version but the same errors in Visual Studio. Any idea of how to solve these linking errors? Thanks! |
To get the project to compile I've followed the steps here: #20344 (comment) I used the exact same version as in the post, which is 1.25. To isolate the problem I manually created a C++ dll and a C# project that invokes a simple function from that dll. This also yields a "dll not found" exception on the HoloLens2 (while it works fine in the Unity IDE). So at the moment I'm looking into how to get DllImport to work on HoloLens2. If you follow these steps please let me know if and how you've managed to get this working on the HoloLens2, and if so - how. Note:
Not sure which one should suite, but getting the same DllNotFound exception with both. |
Thanks! I will try it. Please see my comment on, I think, your other thread: https://forum.unity.com/threads/hololens2-with-grpc-on-unity.932688/ I hope that your error is solved with /MT |
Yes, that was another thread I opened :) Please let me know if you manage to get it working. |
Trying #20344 (comment) but I got stuck in python tools/run_tests/run_tests.py -l csharp -c opt --build_only Did you have the following error when doing tools\run_tests\helper_scripts\build_csharp.bat (I am using Visual Studio 16 2019)? C:\Users\XX\.nuget\packages\microsoft.build.tasks.git\1.0.0-beta2-18618-05\build\Microsoft.Build.Tasks.Git.targets(20,5): error MSB4018: task failed unexpectedly "Microsoft.Build.Tasks.Git.LocateRepository". [C:\HoloLens2_projects\grpc_buildCommit\grpc\src\csharp\Grpc.Core.Api\Grpc.Core.Api.csproj] \r\nC:\Users\XX\.nuget\packages\microsoft.build.tasks.git\1.0.0-beta2-18618-05\build\Microsoft.Build.Tasks.Git.targets(20,5): error MSB4018: System.TypeInitializationException: The type initializer for 'Microsoft.Build.Tasks.Git.TaskImplementation' threw an exception. [C:\HoloLens2_projects\grpc_buildCommit\grpc\src\csharp\Grpc.Core.Api\Grpc.Core.Api.csproj] \r\nC:\Users\XX\.nuget\packages\microsoft.build.tasks.git\1.0.0-beta2-18618-05\build\Microsoft.Build.Tasks.Git.targets(20,5): error MSB4018: ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Build.Tasks.Git, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. System cannot find the specific file .... |
Not sure if it'll solve your issue, but in one of the builds based on #20344 (comment) I noticed an error that was related to an older VS version, so I installed VS2015 and used its "developer command prompt" to run the build (which worked). The side effect was that it had mixed up global VS variables, and I had to re-install windows to get vcpkg working again. |
By the way, I attended the gRPC Conf 2020. I asked the following question in the session "Ask Us Anything: gRPC Maintainers": Trying to use gRPC on HoloLens 2 (ARM64). I use Unity 2019.3 to build the Visual studio project. Unity uses .NET 4.x or .NET standard 2.0, with IL2CPP backend. Do you think that grpc-dotnet will work on HoloLens 2? If not, do you have any suggestion with grpc.core? With grpc.core I could built grpc_csharp_ext.dll for ARM64 using vcpkg but it does not work because I need to build it with the option /MT. Their answer: Grpc.Core might also not work unfortunately, because we only support Unity as "experimental" and there is way too many targeted platforms for us to test. I don't think there's anything preventing your from using Grpc.Core (C#) with HoloLens in principle, but you might need to tweak the source code a bit to make that work. - Jan Tattermusch grpc-dotnet will very likely not work with Unity because unity doesn't support recent .NET core versions. (you'd need netstandard2.1/netcoreapp3.0 to use grpc-dotnet) - Jan Tattermusch |
You could try using a custom triplet[1] to build with /MT set(VCPKG_CRT_LINKAGE static) [1] https://github.com/microsoft/vcpkg/tree/master/docs/users/triplets.md |
I cloned vcpkg repository on 15.07.2020. With that version, I can generate grpc_csharp_ext.dll with the triplet arm64-windows as tom-r-o suggested. After creating a custom triplet for arm64-windows with the setting that ras0219 suggested for building with /MT (thanks!), I can also generate grpc_csharp_ext.dll. In that case, the gRPC version is 1.29.1. However, if I try to generate grpc_csharp_ext.dll with the triplet arm64-windows (without /MT) after cloning the vcpkg repository today (version of gRPC 1.31.1), I have grpc_csharp_ext.lib but not grpc_csharp_ext.dll, no error shown. I do not know why because the triplet of the new version of vcpkg matches that of the old version. The reason for updating vcpkg (and thus grpc) is because I think I also have a problem with the grpc versions. I implemented a grpc server with the NuGet packages Google.Protobuf (version 3.13.0) and Grpc.Core (version 2.30.0) with Visual Studio 2019. Same NuGet packages for the Unity project using MSBuild for Unity (package manager). I can receive the data in Unity from the gRPC server using these settings but if I just replace grpc_csharp_ext.dll that comes with MSBuild with a new grpc_csharp_ext.dll generated with vcpkg (grpc version 1.29.1) and the triplet x64-windows, Unity says that "DllNotFoundException: grpc_csharp_ext". Do you know which version of the NuGet packages Google.Protobuf and Grpc.Core will work with which version of grpc to generate grpc_csharp_ext.dll with vcpkg? tom-r-o , in your Unity project have you tried to replace grpc_csharp_ext.dll with a dll generated with vcpkg (x64) to check if you do not have any problem with the versions, at least for x64? |
Regarding the versions problem, I could generate a grpc_csharp_ext.dll for x64 that works with the NuGet packages Google.Protobuf (version 3.13.0) and Grpc.Core (version 2.30.0) (using MSBuild for Unity (package manager)) in Unity. What I did was to clone the version of gprc 1.31.1 and follow the steps in https://github.com/grpc/grpc/blob/v1.31.1/BUILDING.md (Windows, CMake) except for using cmake .. -G "Visual Studio 15 2017" -A x64 Now the next steps would be to generate grpc_csharp_ext.dll for ARM64 using the same way as before and try to do the same as #20344 (comment) (tom-r-o suggestion) but with the version of grpc corresponding to the NuGet packages. I have started with the first step (generate the ARM64 file for grpc_csharp_ext.dll) cmake .. -G "Visual Studio 15 2017" -A ARM64 and I have the following errors: crypto.dir\Release\chacha-x86_64.obj : fatal error LNK1112: module machine type 'x64' conflicts with target machine typ No idea yet how to create chacha.obj for ARM64 and C:\grpc\src\core\lib\transport\transport.cc(100): warning C4003: not enough arguments for function-like macro invocatio Any suggestion? |
Regarding chacha.obj for ARM64, I have had a look at cMakeLists.txt in cypto project. There are ASM files for win-x86 and win-86-64 in grpc\third-party\boringssl-withbazel. For ARM64 there are files for Linux and iOS (see below) but not for windows... grpc\third_party\boringssl-with-bazel\ios-aarch64\crypto\chacha\chacha-armv8.S Any suggestion to get through this problem? I think I will have the same problem for the other ASM files: win-x86_64/crypto/chacha/chacha-x86_64.asm |
I managed to get grpc 1.25 working on HoloLens 2. 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. The referenced issues claims that the last version without that conflict has been 1.26 which -- as I mentioned in my previous comment -- contains a So what needs to be done:
|
@aleneum, Great that gRPC 1.25 is working on HoloLens 2 with the vcpkg and the unity package!!!! Congratulations and also thanks for your ideas of last year!! In my case I couldn't make it run using vcpkg. Thanks! I found that idea about the dll here. I would like also to thank @tom-r-o. I have been able to make gRPC (version 1.31.1) run on HoloLens 2 this week directly with gRPC github repository as follows:
With OPENSSL_NO_ASM=1 the build does not use ASM files (contain lines of code in assembly language). I did that because there are not ASM files for ARM64 in gRPC repository, specifically in c:\grpc\third_party\boringssl-with-bazel (there are ASM files for Windows x86 and x86_64). I have no idea yet how to generate those ASM files for ARM64.
with
Change the following cs files (you can see why I have done that change in the comments):
To load this Unity package to another Unity project, Assets -- Import package -- Custom package -- Select GRPC_version_1_31_1_csharpNuGet_2_31_0_HoloLens2.unitypackage -- Import
After the application works on Unity editor, in Unity generate Visual Studio solution, open it with Visual Studio 2019, change to ARM64 and Deploy Solution to HoloLens 2. IMPORTANT NOTES:
|
This issue/PR has been automatically marked as stale because it has not had any update (including commits, comments, labels, milestones, etc) for 30 days. It will be closed automatically if no further update occurs in 7 day. Thank you for your contributions! |
Is there a more streamlined way than what @veronicagarciavazquez outlines? It's great that it actually works but it could be easier imho. I still think this is has not been solved so far. |
@veronicagarciavazquez, thank you very much for your indepth tutorial of deploying gRPC on the HL2! |
I found the location of the problem! I created the solution always for ARM64 in the build settings in unity. I hope everybody manage to run gRPC on Hololens 2 and don't have annoying blockers. Thank you very much! |
Thank you @veronicagarciavazquez for the amazing explanation! I have now also managed to build it, but I am having similar problems as @Birkenpapier . I am getting an error saying that the server cannot be found and failed to pick subchannel. @Birkenpapier I tried to do what you did but without success. Would you mind giving a litte bit deeper explanation? It is working in unity, android, other computer etc. so I have ruled out error on the server side. |
Just in case, my settings in Unity were as follows: Unity (version Unity 2019.3.15f1 (64-bit))
|
Of course. I will try to explain it deeper: The server and one client are written in Python 3.8.5. The server is receiving messages from the Python client and then wating for a message from the HoloLens client to send the message. This are my deploying options in Unity 2019.4.17f1 I hope that something helped in this explanation. Edit: |
Thank you both for spending time to help! As you both pointed out I had made the mistake of forgetting to add the correct capabilities... But now it's working so thanks once again since I probably would have spent another couple of days fault tracing before I would have remembered to look at the capabilities :) |
Since Grpc.Core is now in maintenance mode (see https://grpc.io/blog/grpc-csharp-future/), we don't plan to add any new features (or add support for more platforms). |
Seems like I actually got the files compiled myself now thanks to your explanation (had 2 problems which are my fault tho, did not rename the .dll's properly and had a .asmdef file in my script folder which made it that my code could not find the Grpc namespace). At least an empty project with just these files works just fine to build and deploy.
EDIT:
EDIT2: Using Unity 2020 or 2019 removed the error for me so it's a Unity 2021 (maybe 2022 as well?) bug. Now I can deploy the app but still get the Error that it can't reach the adresses. Not sure if that's a firewall problem of my working laptop or not. Dependencies are all active. Will update this post once I know more. |
Great the error was removed with Unity 2020/2019. Sorry, I do not know why it cannot reach your address and I cannot test it with a HoloLens right now... :-( Maybe one option is to try to create a x64 application with Unity to test if you can receive the data on another computer (not on Hololens) sent by your laptop. |
follow the step but not found such a dll |
Thanks for the tip! I moved the server to a different PC and it worked! Seems like the Company Firewall does not allow any device outside the company internet to connect to the PC so that is probably the problem. Unity Support also said that my code works for them on Unity 2021 with the newest version but does not work for me. Maybe this Info helps someone as they are at least working on it? @SnowWindSaveYou Here is my grpc stuff as a Unity Package. Best way to try it is to download this repo and if this does not work change the grpc stuff with my stuff. |
Is your feature request related to a problem? Please describe.
I'd like to use gRPC in Unity in HoloLens2. HoloLens2 runs windows on an ARM64 CPU, and requires a dedicated grpc_csharp_ext.dll.
Describe the solution you'd like
I'd like:
grpc_csharp_ext.dll for windows ARM64 to be delivered as part of the gRPC package.
A working build for Unity and HoloLens2 (as part of Official gRPC Releases).
Describe alternatives you've considered
I've managed to get grpc_csharp_ext.dll for windows arm64 with vcpkg by running:
Following these steps helps compile the Unity application, but for some reason I'm getting this error message:
Additional context
Unity uses C#, but for uwp windows they use an IL2CPP compiler. I.e. the C# code is converted to C++ (IIUC).
I've seen some related threads, but not one that discusses HoloLens2+Unity specifically, so I hope this isn't redundant with other threads.
The text was updated successfully, but these errors were encountered: