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

[webcil] Minor cleanups #81009

Merged
merged 8 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/mono/mono/metadata/assembly.c
Original file line number Diff line number Diff line change
Expand Up @@ -1460,8 +1460,8 @@ bundled_assembly_match (const char *bundled_name, const char *name)
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) - 7;
size_t nprefix = strlen (name) - 4;
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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/mono-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ bsymfile_match (BundledSymfile *bsymfile, const char *assembly_name)
#ifdef ENABLE_WEBCIL
const char *p = strstr (assembly_name, ".webcil");
/* if assembly_name ends with .webcil, check if aname matches, with a .dll extension instead */
if (p && *(p + 7) == 0) {
if (p && *(p + strlen(".webcil")) == 0) {
size_t n = p - assembly_name;
if (!strncmp (bsymfile->aname, assembly_name, n)
&& !strcmp (bsymfile->aname + n, ".dll"))
Expand Down
7 changes: 5 additions & 2 deletions src/mono/mono/mini/monovm.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,11 @@ mono_core_preload_hook (MonoAssemblyLoadContext *alc, MonoAssemblyName *aname, c
#ifdef ENABLE_WEBCIL
else {
/* /path/foo.dll -> /path/foo.webcil */
size_t n = strlen (fullpath) - 4;
char *fullpath2 = g_malloc (n + 8);
size_t n = strlen (fullpath);
if (n < strlen(".dll"))
continue;
n -= strlen(".dll");
char *fullpath2 = g_malloc (n + strlen(".webcil") + 1);
g_strlcpy (fullpath2, fullpath, n + 1);
g_strlcpy (fullpath2 + n, ".webcil", 8);
if (g_file_test (fullpath2, G_FILE_TEST_IS_REGULAR)) {
Expand Down
1 change: 1 addition & 0 deletions src/mono/sample/wasm/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<_ServeMimeTypes>$(_ServeMimeTypes) --mime .mjs=text/javascript</_ServeMimeTypes>
<_ServeMimeTypes>$(_ServeMimeTypes) --mime .cjs=text/javascript</_ServeMimeTypes>
<_ServeMimeTypes>$(_ServeMimeTypes) --mime .js=text/javascript</_ServeMimeTypes>
<_ServeMimeTypes>$(_ServeMimeTypes) --mime .webcil=application/octet-stream</_ServeMimeTypes>
</PropertyGroup>

<Target Name="BuildSampleInTree"
Expand Down
2 changes: 2 additions & 0 deletions src/mono/sample/wasm/simple-server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ private async void ServeAsync(HttpListenerContext context)
string? contentType = null;
if (path.EndsWith(".wasm"))
contentType = "application/wasm";
if (path.EndsWith(".webcil"))
contentType = "application/octet-stream";
if (path.EndsWith(".json"))
contentType = "application/json";
if (path.EndsWith(".js") || path.EndsWith(".mjs") || path.EndsWith(".cjs"))
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/host/WebServerStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void Configure(IApplicationBuilder app,
provider.Mappings[".cjs"] = "text/javascript";
provider.Mappings[".mjs"] = "text/javascript";

foreach (string extn in new string[] { ".dll", ".pdb", ".dat", ".blat" })
foreach (string extn in new string[] { ".dll", ".pdb", ".dat", ".blat", ".webcil" })
lambdageek marked this conversation as resolved.
Show resolved Hide resolved
{
provider.Mappings[extn] = "application/octet-stream";
}
Expand Down
18 changes: 13 additions & 5 deletions src/tasks/WasmAppBuilder/WasmAppBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,12 @@ private bool ExecuteInternal ()
var tmpWebcil = Path.GetTempFileName();
var webcilWriter = Microsoft.WebAssembly.Build.Tasks.WebcilConverter.FromPortableExecutable(inputPath: assembly, outputPath: tmpWebcil, logger: Log);
webcilWriter.ConvertToWebcil();
var finalWebcil = Path.ChangeExtension(assembly, ".webcil");
FileCopyChecked(tmpWebcil, Path.Combine(asmRootPath, Path.GetFileName(finalWebcil)), "Assemblies");
var finalWebcil = Path.Combine(asmRootPath, Path.ChangeExtension(Path.GetFileName(assembly), ".webcil"));
if (Utils.CopyIfDifferent(tmpWebcil, finalWebcil, useHash: true))
Log.LogMessage(MessageImportance.Low, $"Generated {finalWebcil} .");
else
Log.LogMessage(MessageImportance.Low, $"Skipped generating {finalWebcil} as the contents are unchanged.");
_fileWrites.Add(finalWebcil);
}
else
{
Expand Down Expand Up @@ -283,9 +287,13 @@ private bool ExecuteInternal ()
var tmpWebcil = Path.GetTempFileName();
var webcilWriter = Microsoft.WebAssembly.Build.Tasks.WebcilConverter.FromPortableExecutable(inputPath: fullPath, outputPath: tmpWebcil, logger: Log);
webcilWriter.ConvertToWebcil();
var finalWebcil = Path.ChangeExtension(name, ".webcil");
FileCopyChecked(tmpWebcil, Path.Combine(directory, finalWebcil), "SatelliteAssemblies");
config.Assets.Add(new SatelliteAssemblyEntry(finalWebcil, culture));
var finalWebcil = Path.Combine(directory, Path.ChangeExtension(name, ".webcil"));
if (Utils.CopyIfDifferent(tmpWebcil, finalWebcil, useHash: true))
Log.LogMessage(MessageImportance.Low, $"Generated {finalWebcil} .");
else
Log.LogMessage(MessageImportance.Low, $"Skipped generating {finalWebcil} as the contents are unchanged.");
_fileWrites.Add(finalWebcil);
config.Assets.Add(new SatelliteAssemblyEntry(Path.GetFileName(finalWebcil), culture));
}
else
{
Expand Down