asus4 / onnxruntime-unity

ONNX Runtime Plugin for Unity
54 stars 2 forks source link

Framework not found when building for iOS #4

Closed spebern closed 9 months ago

spebern commented 9 months ago

Environment (please complete the following information):

Describe the bug Building on iOS fails with the following error:

AssertionException: Framework not found at /Users/rakhi/workspace/myelinhub_unity/Library/PackageCache/com.github.asus4.onnxruntime@0.1.5/Plugins/iOS~/onnxruntime.xcframework
Assertion failure. Value was False
Expected: True
UnityEngine.Assertions.Assert.Fail (System.String message, System.String userMessage) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Assertions/Assert/AssertBase.cs:29)
UnityEngine.Assertions.Assert.IsTrue (System.Boolean condition, System.String message) (at /Users/bokken/build/output/unity/unity/Runtime/Export/Assertions/Assert/AssertBool.cs:20)
Microsoft.ML.OnnxRuntime.Editor.OrtPostProcessBuild.CopyDir (System.String srcPath, System.String dstPath) (at ./Library/PackageCache/com.github.asus4.onnxruntime@0.1.5/Editor/OrtPostProcessBuild.cs:66)
Microsoft.ML.OnnxRuntime.Editor.OrtPostProcessBuild.PostprocessBuildIOS (UnityEditor.Build.Reporting.BuildReport report) (at ./Library/PackageCache/com.github.asus4.onnxruntime@0.1.5/Editor/OrtPostProcessBuild.cs:49)
Microsoft.ML.OnnxRuntime.Editor.OrtPostProcessBuild.OnPostprocessBuild (UnityEditor.Build.Reporting.BuildReport report) (at ./Library/PackageCache/com.github.asus4.onnxruntime@0.1.5/Editor/OrtPostProcessBuild.cs:26)
UnityEditor.Build.BuildPipelineInterfaces+<>c__DisplayClass18_0.<OnBuildPostProcess>b__1 (UnityEditor.Build.IPostprocessBuildWithReport bpp) (at /Users/bokken/build/output/unity/unity/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:529)
UnityEditor.Build.BuildPipelineInterfaces.InvokeCallbackInterfacesPair[T1,T2] (System.Collections.Generic.List`1[T] oneInterfaces, System.Action`1[T] invocationOne, System.Collections.Generic.List`1[T] twoInterfaces, System.Action`1[T] invocationTwo, System.Boolean exitOnFailure) (at /Users/bokken/build/output/unity/unity/Editor/Mono/BuildPipeline/BuildPipelineInterfaces.cs:465)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:190)

When building the exported project in xcode I get:

ld: Undefined symbols:
  _OrtGetApiBase, referenced from:
      _NativeMethods__cctor_m70DFE7B38AF14E758E523324EB7CE6A1022320F7 in libGameAssembly.a[9](ugr6217q41w7.o)
      _NativeMethods__cctor_m70DFE7B38AF14E758E523324EB7CE6A1022320F7 in libGameAssembly.a[9](ugr6217q41w7.o)
      _NativeMethods_OrtGetApiBase_m0AF88351AE71A7A90D03CF0422C07571A94AA346 in libGameAssembly.a[9](ugr6217q41w7.o)
  _OrtSessionOptionsAppendExecutionProvider_CPU, referenced from:
      _NativeMethods_OrtSessionOptionsAppendExecutionProvider_CPU_m92C3DE9194BD14C40ABAFA5BF9C002CB6671B660 in libGameAssembly.a[9](ugr6217q41w7.o)
  _OrtSessionOptionsAppendExecutionProvider_CoreML, referenced from:
      _NativeMethods_OrtSessionOptionsAppendExecutionProvider_CoreML_mC758C3EFBCF9D84767AB2C1881102CFFD49DE49F in libGameAssembly.a[9](ugr6217q41w7.o)
  _RegisterCustomOps, referenced from:
      _OrtExtensionsNativeMethods_RegisterCustomOps_mA5440E531969CCF75F399CA6B6F0BDCC49422CEA in libGameAssembly.a[10](5234ulbl7y03.o)
      _SessionOptions_RegisterOrtExtensions_mF1C70C8FE4A4F7D388D19EF96D1D332817298FAD in libGameAssembly.a[10](5234ulbl7y03.o)
clang: error: linker command failed with exit code 1 (use -v to see invocation)

To Reproduce

I included the package like explained in the readme:

    "scopedRegistries": [
        {
            "name": "NPM",
            "url": "https://registry.npmjs.com",
            "scopes": [
                "com.github.asus4"
            ]
        }
    ],
  "dependencies": {
        "com.github.asus4.onnxruntime": "0.1.5",
        "com.github.asus4.onnxruntime.linux-x64-gpu": "0.1.5",
        "com.github.asus4.onnxruntime.unity": "0.1.5",
        "com.github.asus4.onnxruntime.win-x64-gpu": "0.1.5",

Expected behavior Builds on iOS.

Additional context The build works for all other platforms (Android, macOS, Windows).

The required folder does not seem to exist instead I get two subfolders:

Sharmins-MBP:build rakhi$ ls ../Library/PackageCache/com.github.asus4.onnxruntime\@0.1.5/Plugins/iOS~/
Info.plist          ios-arm64           ios-arm64_x86_64-simulator
asus4 commented 9 months ago

@spebern Thank you for testing it. I think it's fixed in the latest main branch. Would you mind testing it again with the version 0.1.8?

    "com.github.asus4.onnxruntime": "0.1.8",
    "com.github.asus4.onnxruntime.unity": "0.1.8",
    "com.github.asus4.onnxruntime.win-x64-gpu": "0.1.8",
    "com.github.asus4.onnxruntime.linux-x64-gpu": "0.1.8",
spebern commented 9 months ago

Yes I will test it later today and get back to you.

Thanks a lot for this package by the way. It saved us a lot of time, especially since you made it work with so many platforms!

spebern commented 9 months ago

The errors from before are gone, there is just one more undefined symbol:

ld: Undefined symbols:
  _RegisterCustomOps, referenced from:
      _OrtExtensionsNativeMethods_RegisterCustomOps_mA5440E531969CCF75F399CA6B6F0BDCC49422CEA in libGameAssembly.a[10](5234ulbl7y03.o)
      _SessionOptions_RegisterOrtExtensions_mF1C70C8FE4A4F7D388D19EF96D1D332817298FAD in libGameAssembly.a[10](5234ulbl7y03.o)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
asus4 commented 9 months ago

@spebern hmm, that error didn't reproduce on my end. Are you testing with the onnxruntime-unity-examples project or your own project? If it's your own, can you send it over to me?

Presumably, the error means the onnxruntime.xcframework needs to be linked to the GameAssembly target. But Linking with UnityFramework was enough on my end.

Screenshot 2024-01-17 at 13 13 01

The linking is done automatically in the post-process build.

https://github.com/asus4/onnxruntime-unity/blob/96e8e52eaa0cc9b53181744109317e5012570093/com.github.asus4.onnxruntime/Editor/OrtPostProcessBuild.cs#L51-L57

spebern commented 9 months ago

I tried again with the most recent version and a completely clean build and it worked.

Many thanks for your ongoing support!