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

[tasks] Add auto runtime initialization template to LibraryBuilder #83050

Merged
merged 30 commits into from
Mar 17, 2023

Conversation

mdh1418
Copy link
Member

@mdh1418 mdh1418 commented Mar 6, 2023

Contributes to #79377

Incorporates mono's lazy runtime init capability #82253 into the library builder task #81919.

In the target use case of having a self-contained library containing the mono runtime with custom managed code, the mono runtime needs to be initialized when the library is loaded into the native application. In order to do so, one can either

A. leverage the default runtime-init-callback and upon loading the shared library, rely on the auto initialization logic in autoinit.c (Introduced by this PR) to setup the callback via mono_set_runtime_init_callback. The callback is set when first loading the shared library due to the constructor.

or

B. pass in a custom runtime-init-callback= introduced in #82253 and have one's own runtime initialization startup logic instead of autoinit.c.


The runtime initialization logic looked at https://github.com/dotnet/runtime/blob/main/src/tasks/AndroidAppBuilder/Templates/monodroid.c for inspiration.
In attempt to have a barebones version, the following is done:

  • Set the path to assemblies, expected in environment variable DOTNET_ASSETS_PATH
  • Initialize possible runtime config file
  • Initialize app context environment variables
  • register all aot modules
  • register bundled modules // TODO when bundling is implemented
  • set the path to search for assemblies based on environment variable DOTNET_ASSETS_PATH or custom defined variable
  • set to aot only // For now until Mixed mode is worked out
  • add a custom assembly preload hook // No longer needed as assembly paths are set
  • allow for debugging //TODO in followup
  • add install hook for aot data // Not default scenario
  • add signal chaining
  • initialize the mono runtime
  • load all assemblies that contain exported symbols

Example generated files
CMakeLists
shared_library_log.h
autoinit.c
load_assemblies.c

@mdh1418 mdh1418 force-pushed the library_builder_runtime_initialization branch from fd14133 to bef3de9 Compare March 8, 2023 22:45
@mdh1418 mdh1418 marked this pull request as ready for review March 8, 2023 22:49
@mdh1418 mdh1418 force-pushed the library_builder_runtime_initialization branch from 39b9c7a to b46fdb3 Compare March 15, 2023 17:11
@mdh1418 mdh1418 force-pushed the library_builder_runtime_initialization branch from 0944eeb to 5761f4c Compare March 16, 2023 15:39
@mdh1418
Copy link
Member Author

mdh1418 commented Mar 16, 2023

From the Build Analysis, looks like everything is a known test error.
Unfortunately I made a slight typo and I need to update the CMake, but that shouldn't affect any of our tests.

Copy link
Member

@lateralusX lateralusX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@mdh1418
Copy link
Member Author

mdh1418 commented Mar 17, 2023

All failures are known issues.

@mdh1418 mdh1418 merged commit ea57982 into dotnet:main Mar 17, 2023
@mdh1418 mdh1418 deleted the library_builder_runtime_initialization branch March 17, 2023 13:27
@ghost ghost locked as resolved and limited conversation to collaborators Apr 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants