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

[browser] Fix webcil lazy loading and satellite assemblies in Wasm SDK #85335

Merged
merged 11 commits into from
Apr 26, 2023
7 changes: 5 additions & 2 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ public void BugRegression_60479_WithRazorClassLib()
.ExecuteWithCapturedOutput("new razorclasslib")
.EnsureSuccessful();

AddItemsPropertiesToProject(wasmProjectFile, extraItems:@"
AddItemsPropertiesToProject(wasmProjectFile, extraItems: UseWebcil ? @"
<ProjectReference Include=""..\RazorClassLibrary\RazorClassLibrary.csproj"" />
<BlazorWebAssemblyLazyLoad Include=""RazorClassLibrary.webcil"" />
" : @"
<ProjectReference Include=""..\RazorClassLibrary\RazorClassLibrary.csproj"" />
<BlazorWebAssemblyLazyLoad Include=""RazorClassLibrary.dll"" />
");
Expand All @@ -223,7 +226,7 @@ public void BugRegression_60479_WithRazorClassLib()
throw new XunitException($"Could not find resources.lazyAssembly object in {bootJson}");
}

Assert.Contains("RazorClassLibrary.dll", lazyVal.EnumerateObject().Select(jp => jp.Name));
Assert.Contains("RazorClassLibrary.webcil", lazyVal.EnumerateObject().Select(jp => jp.Name));
}

[ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,9 @@ private List<ITaskItem> ComputeUpdatedAssemblies(
assetsToUpdate.Add(satelliteAssembly.ItemSpec, satelliteAssembly);
var culture = satelliteAssembly.GetMetadata("AssetTraitValue");
var fileName = Path.GetFileName(satelliteAssembly.GetMetadata("RelativePath"));
if (IsWebCilEnabled)
fileName = Path.ChangeExtension(fileName, ".dll");

if (satelliteAssemblies.TryGetValue((culture, fileName), out var existing))
{
filesToRemove.Add(existing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ public override bool Execute()
var webcilWriter = Microsoft.WebAssembly.Build.Tasks.WebcilConverter.FromPortableExecutable(inputPath: filePath, outputPath: tmpWebcil, logger: Log);
webcilWriter.ConvertToWebcil();

var finalWebcil = Path.Combine(OutputPath, Path.GetFileNameWithoutExtension(filePath) + ".webcil");
string candicatePath = Path.Combine(OutputPath, candidate.GetMetadata("Culture"));
if (!Directory.Exists(candicatePath))
Directory.CreateDirectory(candicatePath);

var finalWebcil = Path.Combine(candicatePath, Path.GetFileNameWithoutExtension(filePath) + ".webcil");
if (Utils.CopyIfDifferent(tmpWebcil, finalWebcil, useHash: true))
Log.LogMessage(MessageImportance.Low, $"Generated {finalWebcil} .");
else
Expand All @@ -72,10 +76,16 @@ public override bool Execute()

var webcilItem = new TaskItem(finalWebcil, candidate.CloneCustomMetadata());
webcilItem.SetMetadata("RelativePath", Path.ChangeExtension(candidate.GetMetadata("RelativePath"), ".webcil"));
webcilItem.SetMetadata("AssetTraitName", "WasmResource");
webcilItem.SetMetadata("AssetTraitValue", "runtime");
webcilItem.SetMetadata("OriginalItemSpec", finalWebcil);

if (webcilItem.GetMetadata("AssetTraitName") == "Culture")
{
string relatedAsset = webcilItem.GetMetadata("RelatedAsset");
relatedAsset = Path.ChangeExtension(relatedAsset, ".webcil");
webcilItem.SetMetadata("RelatedAsset", relatedAsset);
Log.LogMessage(MessageImportance.Low, $"Changing related asset of {webcilItem} to {relatedAsset}.");
}

webCilCandidates.Add(webcilItem);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void WriteBootJson(Stream output, string entryAssemblyName)
}
else if (string.Equals("symbol", assetTraitValue, StringComparison.OrdinalIgnoreCase))
{
if (TryGetLazyLoadedAssembly($"{fileName}.dll", out _))
if (TryGetLazyLoadedAssembly($"{fileName}.dll", out _) || TryGetLazyLoadedAssembly($"{fileName}.webcil", out _))
{
Log.LogMessage(MessageImportance.Low, "Candidate '{0}' is defined as a lazy loaded symbols file.", resource.ItemSpec);
resourceData.lazyAssembly ??= new ResourceHashesByNameDictionary();
Expand Down