yotiky Tech Blog

とあるエンジニアの備忘録

HoloLens2 で MagicOnion v3 を動かす

目次

構築環境

補足

NGは動作させることができなかったバージョン。

Unity のベース構築

  1. MagicOnion.Client.Unity.unitypackage をインポートする
  2. MessagePack をインポートする

    • CodeGenerator は Window > MessagePack > CodeGenerator にある

      f:id:yotiky:20201028142315p:plain

  3. grpc-unity-package.x.xx.x-dev.zip を解凍して Assets\Plugins フォルダへインポートする

    1. System.BuffersSystem.MemorySystem.Runtime.CompilerServices.Unsafe は除く

gRPC のコード修正・ビルド

Grpc.Core.dll

  1. gRPC のソースコードを取得する
  2. タグ [v1.26.0] をチェックアウトする
  3. Unity の Asset\Plugins\Grpc.Core\runtimes\win\x64\grpc_csharp_ext.dll を gRPC プロジェクトの grpc\cmake\build\x64\Release フォルダにコピーする

    1. 次のフォルダは除く
      1. System.Buffers
      2. System.Memory
      3. System.Runtime.CompilerServices.Unsafe
  4. ソースコードを修正する

  5. ReleaseAny CPU で、Grpc.Core をビルドする
  6. 生成された Grpc.Core\bin\Release\net45\Grpc.Core.dll をUnityのAsset\Plugins\Grpc.Core\lib\net45\Grpc.Core.dll に上書きする

grpc_csharp_ext.dll

  1. vcpkg をインストールする

    1. vcpkg のソースコード取得
      1. https://github.com/microsoft/vcpkg
    2. タグ [2020.01] をチェックアウトする
    3. bootstrap-vcpkg.bat を実行する
    4. 以下のファイルを vcpkg\ports\grpc フォルダに上書きする
      1. 00001-fix-uwp.patch (3.5 kB)
      2. 00002-static-linking-in-linux.patch (533 B)
      3. portfile.cmake (2.9 kB)
    5. 以下のファイルを vcpkg\triplets\community にコピーする
      1. arm64-windows-static.cmake (106 B)
  2. vcpkg install protobuf:x86-windows

  3. vcpkg install grpc:arm64-windows-static

    1. なにか言われたら随時対処して再実行する

      • Warning: The following VS instances are excluded because the English language pack is unavailable. C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional Please install the English language pack. Could not locate a complete toolset.

        • Visual Studio Installer から英語の言語パックをインストール f:id:yotiky:20201028142423p:plain
      • -- Using source at C:/git/Microsoft/vcpkg/buildtrees/protobuf/src/a5c431386a-c9deea9e31.clean CMake Error at ports/protobuf/portfile.cmake:22 (message): Cross-targetting protobuf requires the x86-windows protoc to be available. Please install protobuf:x86-windows first. Call Stack (most recent call first): scripts/ports.cmake:79 (include)

        Error: Building package protobuf:arm64-windows-static failed with: BUILD_FAILED

        • install protobuf:x86-windows
    2. やり直したい場合は、vcpkg remove grpc:arm64-windows-static して buildtrees\grpc フォルダを削除する

      1. キャッシュ使って buildtrees が吐き出されない場合は下記フォルダを削除する
        1. C:\Users\[username]\AppData\Local\vcpkg\archives
  4. buildtrees\grpc\arm64-windows-static-relgrpc_csharp_ext.dll が生成されるので、Unityの Asset\Plugins\Grpc.Core\runtimes\win\arm64 フォルダを作成してインポート

    1. PlatformでWSAPlayer を選択、CPU を ARM64 に f:id:yotiky:20201028142717p:plain

grpc_csharp_ext_dummy_stubs.c

  1. Asset\Plugins\Grpc.Core\runtimes\grpc_csharp_ext_dummy_stubs の WSAPlayer にチェックを付ける f:id:yotiky:20201028142732p:plain

動作確認

以下のサイトに習い一部読み替えながら実施する。

qiita.com