Skip to content

Commit

Permalink
[mono][librarymode] Bundle runtimeconfig.bin
Browse files Browse the repository at this point in the history
  • Loading branch information
mdh1418 committed Apr 3, 2023
1 parent c1924b2 commit 9084234
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/mono/msbuild/android/build/AndroidBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@
<Target Name="_AndroidGenerateRuntimeConfig"
Inputs="$(_AndroidRuntimeConfigFilePath)"
Outputs="$(_ParsedRuntimeConfigFilePath)"
Condition="Exists('$(_AndroidRuntimeConfigFilePath)')">
Condition="Exists('$(_AndroidRuntimeConfigFilePath)')"
BeforeTargets="_GenerateBundle">
<ItemGroup>
<_RuntimeConfigReservedProperties Include="RUNTIME_IDENTIFIER"/>
<_RuntimeConfigReservedProperties Include="APP_CONTEXT_BASE_DIRECTORY"/>
Expand Down
3 changes: 2 additions & 1 deletion src/mono/msbuild/apple/build/AppleBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@
<Target Name="_AppleGenerateRuntimeConfig"
Inputs="$(_AppleRuntimeConfigFilePath)"
Outputs="$(_ParsedRuntimeConfigFilePath)"
Condition="Exists('$(_AppleRuntimeConfigFilePath)')">
Condition="Exists('$(_AppleRuntimeConfigFilePath)')"
BeforeTargets="_GenerateBundle">
<ItemGroup>
<_RuntimeConfigReservedProperties Include="RUNTIME_IDENTIFIER"/>
<_RuntimeConfigReservedProperties Include="APP_CONTEXT_BASE_DIRECTORY"/>
Expand Down
1 change: 1 addition & 0 deletions src/mono/msbuild/common/LibraryBuilder.targets
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<ItemGroup>
<_AssembliesToBundle Remove="@(_AssembliesToBundle)" />
<_AssembliesToBundle Include="@(_AssembliesToBundleInternal)" />
<_AssembliesToBundle Include="$(_ParsedRuntimeConfigFilePath)" />
</ItemGroup>

<GetFileHash Files="@(_AssembliesToBundle)">
Expand Down
43 changes: 36 additions & 7 deletions src/tasks/LibraryBuilder/Templates/autoinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@

#include "library-builder.h"

#if defined(BUNDLED_ASSEMBLIES)

static void
cleanup_runtime_config (MonovmRuntimeConfigArguments *args, void *user_data)
{
free (args);
free (user_data);
}

static void
initialize_runtimeconfig ()
{
MonovmRuntimeConfigArguments *arg = (MonovmRuntimeConfigArguments *)malloc (sizeof (MonovmRuntimeConfigArguments));
if (!arg)
LOG_ERROR ("Out of memory.\n");

arg->kind = 1;
const char *data;
int data_len;
mono_get_bundled_assembly ("runtimeconfig.bin", &data, &data_len);
arg->runtimeconfig.data.data = data;
arg->runtimeconfig.data.data_len = data_len;
monovm_runtimeconfig_initialize (arg, cleanup_runtime_config, NULL);
}

#else

static void
cleanup_runtime_config (MonovmRuntimeConfigArguments *args, void *user_data)
{
Expand Down Expand Up @@ -54,6 +81,8 @@ initialize_runtimeconfig (const char *bundle_path)
}
}

#endif // BUNDLED_ASSEMBLIES

static void
initialize_appctx_env_variables (const char *bundle_path)
{
Expand Down Expand Up @@ -110,6 +139,13 @@ free_aot_data (MonoAssembly *assembly, int size, void *user_data, void *handle)
static void
runtime_init_callback ()
{
register_aot_modules ();

#if defined(BUNDLED_ASSEMBLIES)
mono_register_assemblies_bundle ();
mono_register_bundle ();
#endif

const char *assemblies_location = getenv ("%ASSEMBLIES_LOCATION%");
if (!assemblies_location || assemblies_location[0] == '\0')
assemblies_location = "./";
Expand All @@ -123,13 +159,6 @@ runtime_init_callback ()

initialize_appctx_env_variables (bundle_path);

register_aot_modules ();

#if defined(BUNDLED_ASSEMBLIES)
mono_register_assemblies_bundle ();
mono_register_bundle ();
#endif

mono_set_assemblies_path (bundle_path);

mono_jit_set_aot_only (true);
Expand Down
1 change: 1 addition & 0 deletions src/tasks/LibraryBuilder/Templates/library-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

void register_aot_modules (void);
#if defined(BUNDLED_ASSEMBLIES)
void mono_get_bundled_assembly (const char *name, const unsigned char **out_data, unsigned int *out_size);
void mono_register_assemblies_bundle (void);
void mono_register_bundle (void);
#endif // BUNDLED_ASSEMBLIES
Expand Down

0 comments on commit 9084234

Please sign in to comment.