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

[Mobile] Maui with ONNX Runtime does not compile for IOS #22661

Open
Assassyn opened this issue Oct 30, 2024 · 9 comments
Open

[Mobile] Maui with ONNX Runtime does not compile for IOS #22661

Assassyn opened this issue Oct 30, 2024 · 9 comments
Labels
api:CSharp issues related to the C# API .NET Pull requests that update .net code platform:mobile issues related to ONNX Runtime mobile; typically submitted using template stale issues that have not been addressed in a while; categorized by a bot

Comments

@Assassyn
Copy link

Describe the issue

I have a mobile application that uses OnnxRuntime to try to generate a new image. The application works on Android and Windows, but I cannot compile it for and on IOS/macOS.

I am using the Vs2022 with remote build on Mac ( INterl based but running Sequoia)

I am getting the error :
Severity Code Description Project File Line Suppression State Error (active) clang++ exited with code 1: ld: library 'C:/Users/<user>/.nuget/packages/microsoft.ml.onnxruntime/1.19.2/buildTransitive/net8.0-ios15.4/../../runtimes/ios/native/onnxruntime.xcframework.zip' not found clang++: error: linker command failed with exit code 1 (use -v to see invocation) Functional.Silhouettist.Mobile (net8.0-ios) C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk.net8.0_18.0\18.0.8303\targets\Xamarin.Shared.Sdk.targets 1643

I have tried to add a native library, but it makes no difference.

<NativeReference Include="dep\onnxruntime.xcframework.zip" Kind="Framework" />
`

To reproduce

  1. Create new MAUI app
  2. Add OnnxRuntime
  3. Try to deploy to Simulator.

or use the repo: https://github.com/Assassyn/maui_onnx_ios_fail

Urgency

I need it to release the application

Platform

iOS

OS Version

17.5 and 18

ONNX Runtime Installation

Released Package

Compiler Version (if 'Built from Source')

No response

Package Name (if 'Released Package')

None

ONNX Runtime Version or Commit ID

1.19.2 but 1.18 was not working as well

ONNX Runtime API

C#

Architecture

X64

Execution Provider

Other / Unknown

Execution Provider Library Version

No response

@Assassyn Assassyn added the platform:mobile issues related to ONNX Runtime mobile; typically submitted using template label Oct 30, 2024
@github-actions github-actions bot added .NET Pull requests that update .net code api:CSharp issues related to the C# API labels Oct 30, 2024
@ben-dean
Copy link

ben-dean commented Nov 5, 2024

I'm getting the same errors in my app having updated to MacOS 15.1, Xcode 16 and dotnet 8.0.403.

The app is not using maui but a native net8.0-ios app.

@Assassyn
Copy link
Author

Assassyn commented Nov 5, 2024

@ben-dean have you updated the onnx runtime after the Mac update?

@ben-dean
Copy link

ben-dean commented Nov 5, 2024

Yes, I have updated to the latest versions.

 <PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.20.0" />
 <PackageReference Include="Microsoft.ML.OnnxRuntime.Extensions" Version="0.13.0" />
 <PackageReference Include="Microsoft.ML.OnnxRuntime.Managed" Version="1.20.0" /> 

I have also tried rolling back to 1.19.2 which was previously working fine for me with no luck.

@skottmckay
Copy link
Contributor

onnxruntime.xcframework.zip has an xcframework for multiple different platforms (iOS arm64, iOS simulator x64/arm64, mac-catalyst x64/arm64) and the mac-catalyst ones require the use of symlinks. As symlinks aren't supported by nuget on Windows we have to create a zip.

I would have expected the MAUI build infrastructure to expand the zip and use the xcframework within it. if that happened clang++ should be linking against the onnxruntime library found at onnxruntime.xcframework.zip/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/onnxruntime for an iOS build

Short term while we look into it you could try extracting the onnxruntime.xcframework from the zip and adding a NativeReference to that. I'd suggest copying the settings from the nuget package targets file

  <ItemGroup Condition="('$(OutputType)'!='Library' OR '$(IsAppExtension)'=='True')">
    <NativeReference Include="<extracted>\onnxruntime.xcframework">
      <Kind>Static</Kind>
      <IsCxx>True</IsCxx>
      <SmartLink>True</SmartLink>
      <ForceLoad>True</ForceLoad>
      <LinkerFlags>-lc++</LinkerFlags>
      <WeakFrameworks>CoreML</WeakFrameworks>
    </NativeReference>
  </ItemGroup>

Copy link
Contributor

github-actions bot commented Dec 6, 2024

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

@github-actions github-actions bot added the stale issues that have not been addressed in a while; categorized by a bot label Dec 6, 2024
@nickrandolph
Copy link

@skottmckay any updates on this issue?

@skottmckay
Copy link
Contributor

This should fix the issue: dotnet/macios#21492

But it's unclear how it was working originally. I still have the test setup from when I added usage of the zipped xcframework and that builds happily.

@enusbaum
Copy link

enusbaum commented Jan 9, 2025

This should fix the issue: xamarin/xamarin-macios#21492

But it's unclear how it was working originally. I still have the test setup from when I added usage of the zipped xcframework and that builds happily.

Do you happen to know the appropriate path to get the new NativeReference working for Microsoft.ML.OnnxRuntime?

@syedbilalali
Copy link

This should fix the issue: dotnet/macios#21492

But it's unclear how it was working originally. I still have the test setup from when I added usage of the zipped xcframework and that builds happily.

How you did you resolve it, Can you please explain it here or you can also provide some links for guidance to resolve it. I appreciate your prompt response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api:CSharp issues related to the C# API .NET Pull requests that update .net code platform:mobile issues related to ONNX Runtime mobile; typically submitted using template stale issues that have not been addressed in a while; categorized by a bot
Projects
None yet
Development

No branches or pull requests

6 participants