Skip to content

Commit

Permalink
Grab shared library directory
Browse files Browse the repository at this point in the history
  • Loading branch information
mdh1418 committed Mar 8, 2023
1 parent 97b2c35 commit bc86f2b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/tasks/LibraryBuilder/Templates/autoinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ static char *bundle_path = "/data/user/0/net.dot.Android.Device_Emulator.Aot_Llv
#define RUNTIMECONFIG_BIN_FILE "runtimeconfig.bin"

void register_aot_modules (void);
bool monoeg_g_module_address (void *addr, char *file_name, size_t file_name_len,
void **file_base, char *sym_name,
size_t sym_name_len, void **sym_addr);
char *mono_path_resolve_symlinks(const char *path);
char *monoeg_g_path_get_dirname (const char *filename);

void
cleanup_runtime_config (MonovmRuntimeConfigArguments *args, void *user_data)
Expand Down Expand Up @@ -78,6 +83,22 @@ mono_droid_load_assembly (const char *name, const char *culture)
return NULL;
}

// Assumes that the dl containing this function is in the same directory as the assemblies to load.
static char *
assemblies_dir (void)
{
static char *dl_dir_name = NULL;
char dl_filename[4096];

if (monoeg_g_module_address ((void *)assemblies_dir, dl_filename, sizeof (dl_filename), NULL, NULL, 0, NULL)) {
char *resolved_dl_filename = mono_path_resolve_symlinks (dl_filename);
dl_dir_name = monoeg_g_path_get_dirname (resolved_dl_filename);
free (resolved_dl_filename);
}

return dl_dir_name;
}

static MonoAssembly*
mono_droid_assembly_preload_hook (MonoAssemblyName *aname, char **assemblies_path, void* user_data)
{
Expand Down Expand Up @@ -128,7 +149,7 @@ void runtime_init_callback ()

register_bundled_modules ();

char *assemblyPath = bundle_path;
char *assemblyPath = assemblies_dir ();
mono_set_assemblies_path ((assemblyPath && assemblyPath[0] != '\0') ? assemblyPath : "./");

mono_jit_set_aot_only (true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<OutputType>Exe</OutputType>
<MonoForceInterpreter>false</MonoForceInterpreter>
<RunAOTCompilation>true</RunAOTCompilation>
<ForceFullAOT>true</ForceFullAOT>
<TestRuntime>true</TestRuntime>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<MainLibraryFileName>Android.Device_Emulator.Aot_Llvm.Test.dll</MainLibraryFileName>
Expand Down

0 comments on commit bc86f2b

Please sign in to comment.