Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.6k
[mono][tasks] Extract EmitWasmBundle into generic EmitBundle task and enable bundling in mono self-contained library#84191
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
1d4e2462955cdb2d25efcd8d97e8eb5e396a34c284c1924b29084234382a93dd4d4193e70e61aecf5ffcfda389a791c743d98c0a56fc54b1d7c09d0d1b5f02c0c443c7683ed1b1f3240ddf6691130aff3b8177d060aa110ba241b5cfa60e56fe9912077c0201e7ad1cc5eb985d28ee4ba796bfb364a1197e48dc646bd211ddade817c0081f39b510769af44cc3401df239c649ae088f2233025a7f4258aa632a73429fe755aeaef4ccd783b3cf95fc5d265db3206aaba8c5d88fbe022e3390e90e16e467684b66750fd4ba236539adf96a6dbefa5d6c3bb50aa060748aff9c60c1e9ec1aeaf879a6b92456c7d33ddfba3f4e8aa970d191d59afaf91a3eff6b97d3bebd187855f7cf6edd8a78222f5ec428f30956950016220b3b30d1803ede2af674d4541530204cae7a77c39cec2570d4ba29ad9e5e42fd0fafb65dad71151637a30e3344237b1c8288f90d4e4c6ef6dbe7c218705c974071c10a5735837d1a6bd58eeb954e568b1b755fc7e34aff7854c5ec4379c3759ba150102c47d560491a5e41b8118afedac2c69ab45d2f8bb377ff4File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -18,6 +18,7 @@ | ||
| #include <stdlib.h> | ||
| #include <mono/metadata/assembly.h> | ||
| #include "assembly-internals.h" | ||
| #include <mono/metadata/bundled-resources-internals.h> | ||
| #include <mono/metadata/image.h> | ||
| #include "image-internals.h" | ||
| #include "object-internals.h" | ||
| @@ -81,11 +82,6 @@ mono_assemblies_unlock (void) | ||
| mono_os_mutex_unlock (&assemblies_mutex); | ||
| } | ||
| /* If defined, points to the bundled assembly information */ | ||
| static const MonoBundledAssembly **bundles; | ||
| static const MonoBundledSatelliteAssembly **satellite_bundles; | ||
| /* Class lazy loading functions */ | ||
| static GENERATE_TRY_GET_CLASS_WITH_CACHE (debuggable_attribute, "System.Diagnostics", "DebuggableAttribute") | ||
| @@ -711,7 +707,8 @@ mono_assembly_get_assemblyref (MonoImage *image, int index, MonoAssemblyName *an | ||
| static MonoAssembly * | ||
| search_bundle_for_assembly (MonoAssemblyLoadContext *alc, MonoAssemblyName *aname) | ||
| { | ||
| if (bundles == NULL && satellite_bundles == NULL) | ||
| if (!mono_bundled_resources_contains_assemblies () && | ||
| !mono_bundled_resources_contains_satellite_assemblies ()) | ||
| return NULL; | ||
| MonoImageOpenStatus status; | ||
| @@ -794,15 +791,15 @@ netcore_load_reference (MonoAssemblyName *aname, MonoAssemblyLoadContext *alc, M | ||
| } | ||
| } | ||
| if (bundles != NULL && !is_satellite) { | ||
| if (mono_bundled_resources_contains_assemblies () && !is_satellite) { | ||
| reference = search_bundle_for_assembly (mono_alc_get_default (), aname); | ||
| if (reference) { | ||
| mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_ASSEMBLY, "Assembly found in the bundle: '%s'.", aname->name); | ||
| goto leave; | ||
| } | ||
| } | ||
| if (satellite_bundles != NULL && is_satellite) { | ||
| if (mono_bundled_resources_contains_satellite_assemblies () && is_satellite) { | ||
| // Satellite assembly byname requests should be loaded in the same ALC as their parent assembly | ||
| size_t name_len = strlen (aname->name); | ||
| char *parent_name = NULL; | ||
| @@ -1451,47 +1448,19 @@ absolute_dir (const gchar *filename) | ||
| return res; | ||
| } | ||
| static gboolean | ||
| bundled_assembly_match (const char *bundled_name, const char *name) | ||
| { | ||
| #ifndef ENABLE_WEBCIL | ||
| return strcmp (bundled_name, name) == 0; | ||
| #else | ||
| if (strcmp (bundled_name, name) == 0) | ||
| return TRUE; | ||
| /* if they want a .dll and we have the matching .webcil, return it */ | ||
| if (g_str_has_suffix (bundled_name, ".webcil") && g_str_has_suffix (name, ".dll")) { | ||
| size_t bprefix = strlen (bundled_name) - strlen (".webcil"); | ||
| size_t nprefix = strlen (name) - strlen (".dll"); | ||
| if (bprefix == nprefix && strncmp (bundled_name, name, bprefix) == 0) | ||
| return TRUE; | ||
| } | ||
| /* if they want a .dll and we have the matching .wasm webcil-in-wasm, return it */ | ||
| if (g_str_has_suffix (bundled_name, MONO_WEBCIL_IN_WASM_EXTENSION) && g_str_has_suffix (name, ".dll")) { | ||
| size_t bprefix = strlen (bundled_name) - strlen (MONO_WEBCIL_IN_WASM_EXTENSION); | ||
| size_t nprefix = strlen (name) - strlen (".dll"); | ||
| if (bprefix == nprefix && strncmp (bundled_name, name, bprefix) == 0) | ||
| return TRUE; | ||
| } | ||
| return FALSE; | ||
| #endif | ||
| } | ||
| static MonoImage * | ||
| open_from_bundle_internal (MonoAssemblyLoadContext *alc, const char *filename, MonoImageOpenStatus *status, gboolean is_satellite) | ||
| open_from_bundle_internal (MonoAssemblyLoadContext *alc, const char *filename, MonoImageOpenStatus *status) | ||
| { | ||
| if (!bundles) | ||
lateralusX marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (!mono_bundled_resources_contains_assemblies ()) | ||
| return NULL; | ||
| MonoImage *image = NULL; | ||
| char *name = is_satellite ? g_strdup (filename) : g_path_get_basename (filename); | ||
| for (int i = 0; !image && bundles [i]; ++i) { | ||
| if (bundled_assembly_match (bundles[i]->name, name)) { | ||
| // Since bundled images don't exist on disk, don't give them a legit filename | ||
| image = mono_image_open_from_data_internal (alc, (char*)bundles [i]->data, bundles [i]->size, FALSE, status, FALSE, name, NULL); | ||
| break; | ||
| } | ||
| } | ||
| char *name = g_path_get_basename (filename); | ||
| const uint8_t *data = NULL; | ||
| uint32_t size = 0; | ||
| if (mono_bundled_resources_get_assembly_resource_values (name, &data, &size)) | ||
| image = mono_image_open_from_data_internal (alc, (char *)data, size, FALSE, status, FALSE, name, NULL); | ||
| g_free (name); | ||
| return image; | ||
| @@ -1500,22 +1469,18 @@ open_from_bundle_internal (MonoAssemblyLoadContext *alc, const char *filename, M | ||
| static MonoImage * | ||
| open_from_satellite_bundle (MonoAssemblyLoadContext *alc, const char *filename, MonoImageOpenStatus *status, const char *culture) | ||
| { | ||
| if (!satellite_bundles) | ||
lateralusX marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (!mono_bundled_resources_contains_satellite_assemblies ()) | ||
| return NULL; | ||
| MonoImage *image = NULL; | ||
| char *name = g_strdup (filename); | ||
| char *bundle_name = g_strconcat (culture, "/", filename, (const char *)NULL); | ||
| for (int i = 0; !image && satellite_bundles [i]; ++i) { | ||
| if (bundled_assembly_match (satellite_bundles[i]->name, name) && strcmp (satellite_bundles [i]->culture, culture) == 0) { | ||
| char *bundle_name = g_strconcat (culture, "/", name, (const char *)NULL); | ||
| image = mono_image_open_from_data_internal (alc, (char *)satellite_bundles [i]->data, satellite_bundles [i]->size, FALSE, status, FALSE, bundle_name, NULL); | ||
| g_free (bundle_name); | ||
| break; | ||
| } | ||
| } | ||
| const uint8_t *data = NULL; | ||
| uint32_t size = 0; | ||
| if (mono_bundled_resources_get_satellite_assembly_resource_values (bundle_name, &data, &size)) | ||
| image = mono_image_open_from_data_internal (alc, (char *)data, size, FALSE, status, FALSE, bundle_name, NULL); | ||
| g_free (name); | ||
| g_free (bundle_name); | ||
| return image; | ||
| } | ||
| @@ -1525,7 +1490,7 @@ open_from_satellite_bundle (MonoAssemblyLoadContext *alc, const char *filename, | ||
| * \param status return status code | ||
| * | ||
| * This routine tries to open the assembly specified by \p filename from the | ||
| * defined bundles, if found, returns the MonoImage for it, if not found | ||
| * bundles hashtable in bundled-resources.c, if found, returns the MonoImage for it, if not found | ||
| * returns NULL | ||
| */ | ||
| MonoImage * | ||
| @@ -1537,12 +1502,10 @@ mono_assembly_open_from_bundle (MonoAssemblyLoadContext *alc, const char *filena | ||
| */ | ||
| MonoImage *image = NULL; | ||
| MONO_ENTER_GC_UNSAFE; | ||
| gboolean is_satellite = culture && culture [0] != 0; | ||
| if (is_satellite) | ||
| if (culture && culture [0] != 0) | ||
| image = open_from_satellite_bundle (alc, filename, status, culture); | ||
| else | ||
| image = open_from_bundle_internal (alc, filename, status, FALSE); | ||
| image = open_from_bundle_internal (alc, filename, status); | ||
| if (image) { | ||
| mono_image_addref (image); | ||
| @@ -1620,7 +1583,7 @@ mono_assembly_request_open (const char *filename, const MonoAssemblyOpenRequest | ||
| // If VM built with mkbundle | ||
| loaded_from_bundle = FALSE; | ||
| if (bundles != NULL || satellite_bundles != NULL) { | ||
| if (mono_bundled_resources_contains_assemblies ()) { | ||
| /* We don't know the culture of the filename we're loading here, so this call is not culture aware. */ | ||
| image = mono_assembly_open_from_bundle (load_req.alc, fname, status, NULL); | ||
| loaded_from_bundle = image != NULL; | ||
| @@ -3172,11 +3135,16 @@ mono_assembly_get_name_internal (MonoAssembly *assembly) | ||
| /** | ||
| * mono_register_bundled_assemblies: | ||
| * Dynamically allocates MonoBundledAssemblyResources to leverage | ||
| * preferred bundling api mono_bundled_resources_add. | ||
| */ | ||
| void | ||
| mono_register_bundled_assemblies (const MonoBundledAssembly **assemblies) | ||
| { | ||
| bundles = assemblies; | ||
| for (int i = 0; assemblies [i]; ++i) { | ||
| const MonoBundledAssembly *assembly = assemblies [i]; | ||
| mono_bundled_resources_add_assembly_resource (assembly->name, assembly->name, (const uint8_t *)assembly->data, (uint32_t)assembly->size, NULL, NULL); | ||
| } | ||
| } | ||
| /** | ||
| @@ -3187,19 +3155,34 @@ mono_create_new_bundled_satellite_assembly (const char *name, const char *cultur | ||
| { | ||
| MonoBundledSatelliteAssembly *satellite_assembly = g_new0 (MonoBundledSatelliteAssembly, 1); | ||
| satellite_assembly->name = strdup (name); | ||
| g_assert (satellite_assembly->name); | ||
| satellite_assembly->culture = strdup (culture); | ||
| g_assert (satellite_assembly->culture); | ||
| satellite_assembly->data = data; | ||
| satellite_assembly->size = size; | ||
| return satellite_assembly; | ||
| } | ||
| static void | ||
| mono_free_bundled_satellite_assembly_func (void *resource, void *free_data) | ||
| { | ||
| g_free (free_data); | ||
| } | ||
| /** | ||
| * mono_register_bundled_satellite_assemblies: | ||
| * Dynamically allocates MonoBundledSatelliteAssemblyResources to leverage | ||
| * preferred bundling api mono_bundled_resources_add. | ||
| */ | ||
| void | ||
| mono_register_bundled_satellite_assemblies (const MonoBundledSatelliteAssembly **assemblies) | ||
| mono_register_bundled_satellite_assemblies (const MonoBundledSatelliteAssembly **satellite_assemblies) | ||
| { | ||
| satellite_bundles = assemblies; | ||
| for (int i = 0; satellite_assemblies [i]; ++i) { | ||
| const MonoBundledSatelliteAssembly *satellite_assembly = satellite_assemblies [i]; | ||
| char *id = g_strconcat (satellite_assembly->culture, "/", satellite_assembly->name, (const char*)NULL); | ||
| g_assert (id); | ||
| mono_bundled_resources_add_satellite_assembly_resource (id, satellite_assembly->name, satellite_assembly->culture, (const uint8_t *)satellite_assembly->data, (uint32_t)satellite_assembly->size, mono_free_bundled_satellite_assembly_func, id); | ||
| } | ||
| } | ||
| /** | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
mdh1418 marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // | ||
| #ifndef __MONO_METADATA_BUNDLED_RESOURCES_INTERNALS_H__ | ||
| #define __MONO_METADATA_BUNDLED_RESOURCES_INTERNALS_H__ | ||
| #include <stdbool.h> | ||
| #include <stdint.h> | ||
| typedef enum { | ||
| MONO_BUNDLED_DATA, | ||
| MONO_BUNDLED_ASSEMBLY, | ||
| MONO_BUNDLED_SATELLITE_ASSEMBLY, | ||
| MONO_BUNDLED_RESOURCE_COUNT | ||
| } MonoBundledResourceType; | ||
| typedef void (*free_bundled_resource_func)(void *, void*); | ||
| typedef struct _MonoBundledResource { | ||
| MonoBundledResourceType type; | ||
| const char *id; | ||
| free_bundled_resource_func free_func; | ||
| void *free_data; | ||
| } MonoBundledResource; | ||
| typedef struct _MonoBundledData { | ||
| const char *name; | ||
| const uint8_t *data; | ||
| uint32_t size; | ||
| } MonoBundledData; | ||
| typedef struct _MonoBundledDataResource { | ||
| MonoBundledResource resource; | ||
| MonoBundledData data; | ||
| } MonoBundledDataResource; | ||
| typedef struct _MonoBundledSymbolData { | ||
| const uint8_t *data; | ||
| uint32_t size; | ||
| } MonoBundledSymbolData; | ||
| typedef struct _MonoBundledAssemblyData { | ||
| const char *name; | ||
| const uint8_t *data; | ||
| uint32_t size; | ||
| } MonoBundledAssemblyData; | ||
| typedef struct _MonoBundledAssemblyResource { | ||
| MonoBundledResource resource; | ||
| MonoBundledAssemblyData assembly; | ||
| MonoBundledSymbolData symbol_data; | ||
| } MonoBundledAssemblyResource; | ||
| typedef struct _MonoBundledSatelliteAssemblyData { | ||
| const char *name; | ||
| const char *culture; | ||
| const uint8_t *data; | ||
| uint32_t size; | ||
| } MonoBundledSatelliteAssemblyData; | ||
| typedef struct _MonoBundledSatelliteAssemblyResource { | ||
| MonoBundledResource resource; | ||
| MonoBundledSatelliteAssemblyData satellite_assembly; | ||
| } MonoBundledSatelliteAssemblyResource; | ||
| void | ||
| mono_bundled_resources_free (void); | ||
mdh1418 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| void | ||
| mono_bundled_resources_add (MonoBundledResource **resources_to_bundle, uint32_t len); | ||
| bool | ||
| mono_bundled_resources_get_assembly_resource_values (const char *id, const uint8_t **data_out, uint32_t *size_out); | ||
| bool | ||
| mono_bundled_resources_get_assembly_resource_symbol_values (const char *id, const uint8_t **symbol_data_out, uint32_t *symbol_size_out); | ||
| bool | ||
| mono_bundled_resources_get_satellite_assembly_resource_values (const char *id, const uint8_t **data_out, uint32_t *size_out); | ||
| bool | ||
| mono_bundled_resources_get_data_resource_values (const char *id, const uint8_t **data_out, uint32_t *size_out); | ||
| void | ||
| mono_bundled_resources_add_assembly_resource (const char *id, const char *name, const uint8_t *data, uint32_t size, free_bundled_resource_func free_func, void *free_data); | ||
| void | ||
| mono_bundled_resources_add_assembly_symbol_resource (const char *id, const uint8_t *data, uint32_t size, free_bundled_resource_func free_func, void *free_data); | ||
| void | ||
| mono_bundled_resources_add_satellite_assembly_resource (const char *id, const char *name, const char *culture, const uint8_t *data, uint32_t size, free_bundled_resource_func free_func, void *free_data); | ||
| void | ||
| mono_bundled_resources_add_data_resource (const char *id, const char *name, const uint8_t *data, uint32_t size, free_bundled_resource_func free_func, void *free_data); | ||
| bool | ||
| mono_bundled_resources_contains_assemblies (void); | ||
| bool | ||
| mono_bundled_resources_contains_satellite_assemblies (void); | ||
| #endif /* __MONO_METADATA_BUNDLED_RESOURCES_INTERNALS_H__ */ | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.