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

[mono] Add support for library mode in the aot compiler #79377

Closed
9 tasks done
steveisok opened this issue Dec 8, 2022 · 8 comments
Closed
9 tasks done

[mono] Add support for library mode in the aot compiler #79377

steveisok opened this issue Dec 8, 2022 · 8 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-Codegen-AOT-mono os-android os-ios Apple iOS User Story A single user-facing feature. Can be grouped under an epic.
Milestone

Comments

@steveisok
Copy link
Member

steveisok commented Dec 8, 2022

As a native developer targeting Android, iOS, or wasm, I would like to use a shared library containing custom managed code plus the mono runtime so that I can call into managed functions from my native application. The library should take the same approach as NativeAOT, only exporting the symbols from managed functions decorated with [UnmanagedCallersOnly(EntryPoint = "")].

@steveisok steveisok added the User Story A single user-facing feature. Can be grouped under an epic. label Dec 8, 2022
@steveisok steveisok added this to the 8.0.0 milestone Dec 8, 2022
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost
Copy link

ghost commented Dec 8, 2022

Tagging subscribers to 'arch-android': @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

Issue Details

As a native developer targeting Android, iOS, or wasm, I would like to use a shared library containing custom managed code plus the mono runtime so that I can call into managed functions from my native application. The library should take the same approach as NativeAOT, only exporting the symbols from managed functions decorated with [UnmanagedCallersOnly(EntryPoint = "")].

  • Run basic functional test loading two libraries in the same app (iOS & Android)
  • Modify aot compiler to generate exports file with symbols for all [UnmanagedCallersOnly(EntryPoint = "")]
  • Create a library builder msbuild task that produces a cmake file to build / link the library
  • Auto initialize and start the runtime when function is called from native code
  • Extend direct-pinvoke support by accepting an list of functions & what static libraries to link
  • Add workload to make it easier to install the mobile runtime packs + tooling
  • Add functional test for library mode
Author: steveisok
Assignees: -
Labels:

os-android, User Story

Milestone: 8.0.0

@steveisok steveisok added os-ios Apple iOS arch-wasm WebAssembly architecture labels Dec 8, 2022
@ghost
Copy link

ghost commented Dec 8, 2022

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

As a native developer targeting Android, iOS, or wasm, I would like to use a shared library containing custom managed code plus the mono runtime so that I can call into managed functions from my native application. The library should take the same approach as NativeAOT, only exporting the symbols from managed functions decorated with [UnmanagedCallersOnly(EntryPoint = "")].

  • Run basic functional test loading two libraries in the same app (iOS & Android)
  • Modify aot compiler to generate exports file with symbols for all [UnmanagedCallersOnly(EntryPoint = "")]
  • Create a library builder msbuild task that produces a cmake file to build / link the library
  • Auto initialize and start the runtime when function is called from native code
  • Extend direct-pinvoke support by accepting an list of functions & what static libraries to link
  • Add workload to make it easier to install the mobile runtime packs + tooling
  • Add functional test for library mode
Author: steveisok
Assignees: -
Labels:

arch-wasm, os-android, os-ios, User Story

Milestone: 8.0.0

@DeafMan1983
Copy link

Please do not forget to add includes and libraries if you use custom directories with includes and libraries for all platforms
Example:
ProjectRoot means your created class library's project

<IncludePath directory="{ProjectRoot}/include" />
<LibraryPath directory="{ProjectRoot}/libs" />

Like for custom object c / headers for adapters like USB Device supports or any device supporting.... or plugins with platform-engine desktop/shell managements or for WebAssembly with functions for current browser's runtime like Electron or Chromium etc...

PS: Please put support with AppImage for Linux if you don't worry to get warning like not found library for custom shared libraries.

<IsLinux>
 <SingleAppImage>true</SingleAppImage>
</IsLinux>

I hope you have to add more features in Net 8.0

steveisok added a commit that referenced this issue Mar 6, 2023
…81919)

This change adds a build task to generate a self-contained shared or static library when using the aot compiler and will only export symbols for methods decorated with UnmanagedCallersOnly attributes (similar to NativeAOT).

Contributes to #79377
@davetao
Copy link

davetao commented Apr 26, 2023

Hello @steveisok

We are currently using the Embeddinator 4000 toolkit to make a shared library written in c# available as a native mobile SDK. Seeing the similarities in the use case, we were wondering if this was a suitable replacement seeing the E4K tool has been EOL for some time now.

@steveisok
Copy link
Member Author

Hello @steveisok

We are currently using the Embeddinator 4000 toolkit to make a shared library written in c# available as a native mobile SDK. Seeing the similarities in the use case, we were wondering if this was a suitable replacement seeing the E4K tool has been EOL for some time now.

It's a suitable replacement if all you want is a native shared library you can call into that doesn't rely on any android or ios bindings. That's at least where we are starting from right now.

@curia-damiano
Copy link

Hi @steveisok , thank you for your answer and work on this issue.
I would have just a couple of questions:

  • this would allow, for example, the porting of the .NET Azure SDK (previous creation of public methods) as the existing Azure SDK for Swift has been deprecated. As the .NET SDK is pure .NET, it doesn't contain any bindings, so it should work. Do you confirm?
  • is it possible to test now the export to native libraries?
  • do you plan to complete this work with the release of .NET 8?
  • final question: what is the issue in case there are iOS or Android bindings?

@steveisok
Copy link
Member Author

  • this would allow, for example, the porting of the .NET Azure SDK (previous creation of public methods) as the existing Azure SDK for Swift has been deprecated. As the .NET SDK is pure .NET, it doesn't contain any bindings, so it should work. Do you confirm?

Yes, as long as it doesn't contain bindings, then you should be able to expose entry points that in this case wrap the SDK.

  • is it possible to test now the export to native libraries?

Yes, we have an experimental workload you can use. There is a sample repo to help you get started https://github.com/steveisok/library-mode-sample

  • do you plan to complete this work with the release of .NET 8?

Yes, we are planning on having this feature for .NET 8. As of right now we are targeting iOS/MacCatalyst, Android, and Wasm.

  • final question: what is the issue in case there are iOS or Android bindings?

Try not to use them :-). I'm not sure what the behavior will be.

@ghost ghost locked as resolved and limited conversation to collaborators Sep 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-Codegen-AOT-mono os-android os-ios Apple iOS User Story A single user-facing feature. Can be grouped under an epic.
Projects
None yet
Development

No branches or pull requests

7 participants