-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #903 from unoplatform/dev/jela/cache-break
fix: Restore cache breaking
- Loading branch information
Showing
13 changed files
with
453 additions
and
362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...m.Bootstrap/WasmScripts/service-worker.js → ...Wasm.Bootstrap/Embedded/service-worker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using Microsoft.Build.Framework; | ||
|
||
namespace Uno.Wasm.Bootstrap.Extensions; | ||
|
||
internal static class TaskItemExtensions | ||
{ | ||
public static (string fullPath, string relativePath) GetFilePaths(this ITaskItem item, Microsoft.Build.Utilities.TaskLoggingHelper log, string currentProjectPath) | ||
{ | ||
if (item.GetMetadata("RelativePath") is { } relativePath && !string.IsNullOrEmpty(relativePath)) | ||
{ | ||
log.LogMessage(MessageImportance.Low, $"RelativePath '{relativePath}' for full path '{item.GetMetadata("FullPath")}' (ItemSpec: {item.ItemSpec})"); | ||
|
||
// This case is mainly for shared projects and files out of the baseSourceFile path | ||
return (item.GetMetadata("FullPath"), relativePath); | ||
} | ||
else if (item.GetMetadata("TargetPath") is { } targetPath && !string.IsNullOrEmpty(targetPath)) | ||
{ | ||
log.LogMessage(MessageImportance.Low, $"TargetPath '{targetPath}' for full path '{item.GetMetadata("FullPath")}' (ItemSpec: {item.ItemSpec})"); | ||
|
||
// This is used for item remapping | ||
return (item.GetMetadata("FullPath"), targetPath); | ||
} | ||
else if (item.GetMetadata("Link") is { } link && !string.IsNullOrEmpty(link)) | ||
{ | ||
log.LogMessage(MessageImportance.Low, $"Link '{link}' for full path '{item.GetMetadata("FullPath")}' (ItemSpec: {item.ItemSpec})"); | ||
|
||
// This case is mainly for shared projects and files out of the baseSourceFile path | ||
return (item.GetMetadata("FullPath"), link); | ||
} | ||
else if (item.GetMetadata("FullPath") is { } fullPath && File.Exists(fullPath)) | ||
{ | ||
log.LogMessage(MessageImportance.Low, $"FullPath '{fullPath}' (ItemSpec: {item.ItemSpec})"); | ||
|
||
var sourceFilePath = item.ItemSpec; | ||
|
||
if (sourceFilePath.StartsWith(currentProjectPath)) | ||
{ | ||
// This is for files added explicitly through other targets (e.g. Microsoft.TypeScript.MSBuild) | ||
return (fullPath: fullPath, sourceFilePath.Replace(currentProjectPath + Path.DirectorySeparatorChar, "")); | ||
} | ||
else | ||
{ | ||
return (fullPath, sourceFilePath); | ||
} | ||
} | ||
else | ||
{ | ||
log.LogMessage(MessageImportance.Low, $"Without metadata '{item.GetMetadata("FullPath")}' (ItemSpec: {item.ItemSpec})"); | ||
|
||
return (item.GetMetadata("FullPath"), item.ItemSpec); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
src/Uno.Wasm.Bootstrap/GenerateUnoNativeAssetsTask.AOTProfile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
// ****************************************************************** | ||
// Copyright � 2015-2022 Uno Platform inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// ****************************************************************** | ||
// | ||
// This file is based on the work from https://github.com/praeclarum/Ooui | ||
// | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.IO.Compression; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Runtime.InteropServices; | ||
using System.Security; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Transactions; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Win32.SafeHandles; | ||
using Mono.Cecil; | ||
using Mono.CompilerServices.SymbolWriter; | ||
using Newtonsoft.Json.Linq; | ||
using Uno.Wasm.Bootstrap.Extensions; | ||
|
||
namespace Uno.Wasm.Bootstrap; | ||
|
||
public partial class GenerateUnoNativeAssetsTask_v0 | ||
{ | ||
/// <summary> | ||
/// Applies a temporary workaround for https://github.com/mono/mono/issues/19824 | ||
/// </summary> | ||
private string? TransformAOTProfile() | ||
{ | ||
var profilePath = AotProfile; | ||
|
||
if (profilePath != null) | ||
{ | ||
var reader = new Mono.Profiler.Aot.ProfileReader(); | ||
Mono.Profiler.Aot.ProfileData profile; | ||
using (FileStream stream = File.OpenRead(profilePath)) | ||
{ | ||
profile = reader.ReadAllData(stream); | ||
} | ||
|
||
var excludedMethodsList = AOTProfileExcludedMethods | ||
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) | ||
.ToList(); | ||
|
||
var excludedAssemblies = MixedModeExcludedAssembly?.ToDictionary(i => i.ItemSpec, i => i.ItemSpec) | ||
?? new Dictionary<string, string>(); | ||
|
||
if (excludedMethodsList.Any() || excludedAssemblies.Any()) | ||
{ | ||
// LoadIntoBufferAsync uses exception filtering | ||
excludedMethodsList.AddRange(DefaultAOTProfileExcludedMethods); | ||
|
||
TryDumpProfileMethods(profile, "AOTProfileDump.Original.txt"); | ||
|
||
var excludedMethods = excludedMethodsList.Select(e => new Regex(e)).ToList(); | ||
|
||
var q = from m in profile.Methods | ||
where !excludedMethods.Any(e => e.Match(m.Type.FullName + '.' + m.Name).Success) | ||
&& !excludedAssemblies.ContainsKey(m.Type.Module.Name) | ||
select m; | ||
|
||
profile.Methods = q.ToArray(); | ||
|
||
TryDumpProfileMethods(profile, "AOTProfileDump.Filtered.txt"); | ||
|
||
var writer = new Mono.Profiler.Aot.ProfileWriter(); | ||
|
||
var outputFile = Path.Combine(IntermediateOutputPath, "aot-filtered.profile"); | ||
using (var outStream = File.Create(outputFile)) | ||
{ | ||
writer.WriteAllData(outStream, profile); | ||
} | ||
|
||
return outputFile; | ||
} | ||
} | ||
|
||
return profilePath; | ||
} | ||
|
||
private IEnumerable<string> DefaultAOTProfileExcludedMethods => | ||
new[] | ||
{ | ||
@"ManifestBasedResourceGroveler\.InternalGetSatelliteAssembly", // https://github.com/dotnet/runtime/issues/45698 | ||
|
||
@"System\.Reflection\.Assembly\.GetExecutingAssembly", // https://github.com/dotnet/runtime/issues/47996 | ||
@"System\.RuntimeType\.GetType", | ||
@"System\.RuntimeTypeHandle\.internal_from_name", | ||
@"System\.RuntimeTypeHandle\.GetTypeByName", | ||
@"System\.Type\.GetType", | ||
@"System\.Runtime\.Loader\.AssemblyLoadContext\.InternalLoadFromPath", | ||
@"System\.Runtime\.Loader\.AssemblyLoadContext\.InternalLoadFile", | ||
@"System\.Runtime\.Loader\.AssemblyLoadContext\.LoadFromAssemblyName", | ||
@"System\.Reflection\.Assembly\.Load", | ||
@"System\.Reflection\.Assembly\.InternalLoad", | ||
@"System\.Reflection\.RuntimeAssembly\.InternalGetSatelliteAssembly", | ||
@"System\.Reflection\.RuntimeAssembly\.InternalLoad", | ||
}; | ||
|
||
private void TryDumpProfileMethods(Mono.Profiler.Aot.ProfileData profile, string filePath) | ||
{ | ||
if (GenerateAOTProfileDebugList) | ||
{ | ||
var sb = new StringBuilder(); | ||
|
||
foreach (var method in profile.Methods) | ||
{ | ||
var genericParameters = string.Join("|", method.GenericInst?.Types.Select(t => t.ToString()) ?? []); | ||
|
||
sb.AppendLine($"{method.Type.Module.Name};{method.Type.FullName}.{method.Name};{method.GenericInst?.Id};{genericParameters}"); | ||
} | ||
|
||
File.WriteAllText(Path.Combine(IntermediateOutputPath, filePath), sb.ToString()); | ||
} | ||
} | ||
|
||
private bool UseAotProfile | ||
=> !string.IsNullOrEmpty(AotProfile) && _runtimeExecutionMode == RuntimeExecutionMode.InterpreterAndAOT; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
| ||
// ****************************************************************** | ||
// Copyright � 2015-2022 Uno Platform inc. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// ****************************************************************** | ||
// | ||
// This file is based on the work from https://github.com/praeclarum/Ooui | ||
// | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Numerics; | ||
using System.Runtime.InteropServices; | ||
using System.Security.Cryptography; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
using Uno.Wasm.Bootstrap.Extensions; | ||
|
||
namespace Uno.Wasm.Bootstrap; | ||
|
||
public partial class GenerateUnoNativeAssetsTask_v0 : Microsoft.Build.Utilities.Task | ||
{ | ||
private RuntimeExecutionMode _runtimeExecutionMode; | ||
|
||
public string AotProfile { get; set; } = ""; | ||
|
||
public bool GenerateAOTProfile { get; set; } | ||
|
||
public string AOTProfileExcludedMethods { get; set; } = ""; | ||
|
||
public bool GenerateAOTProfileDebugList { get; set; } = false; | ||
|
||
public bool WasmBuildNative { get; set; } | ||
|
||
public bool RunAOTCompilation { get; set; } | ||
|
||
public Microsoft.Build.Framework.ITaskItem[]? MixedModeExcludedAssembly { get; set; } | ||
|
||
public bool EnableThreads { get; set; } | ||
|
||
public ITaskItem[]? Assets { get; set; } | ||
|
||
public string EmscriptenVersion { get; set; } = ""; | ||
|
||
[Required] | ||
public string IntermediateOutputPath { get; set; } = ""; | ||
|
||
[Required] | ||
public string CurrentProjectPath { get; set; } = ""; | ||
|
||
[Output] | ||
public ITaskItem[] NativeFileReference { get; set; } = []; | ||
|
||
[Output] | ||
public string? FilteredAotProfile { get; set; } = ""; | ||
|
||
public override bool Execute() | ||
{ | ||
ParseProperties(); | ||
GenerateBitcodeFiles(); | ||
BuildAOTProfile(); | ||
|
||
return true; | ||
} | ||
|
||
private void ParseProperties() | ||
=> _runtimeExecutionMode | ||
= WasmBuildNative && RunAOTCompilation ? RuntimeExecutionMode.InterpreterAndAOT : RuntimeExecutionMode.Interpreter; | ||
|
||
private void BuildAOTProfile() | ||
{ | ||
var useAotProfile = !GenerateAOTProfile && UseAotProfile; | ||
|
||
if (useAotProfile) | ||
{ | ||
// If the profile was transformed, we need to use the transformed profile | ||
FilteredAotProfile = TransformAOTProfile(); | ||
} | ||
} | ||
private void GenerateBitcodeFiles() | ||
{ | ||
var bitcodeFiles = Assets | ||
?.Where(a => a.ItemSpec.EndsWith(".o") || a.ItemSpec.EndsWith(".a")) | ||
.Where(a => !bool.TryParse(a.GetMetadata("UnoAotCompile"), out var compile) || compile) | ||
.Select(a => a.GetFilePaths(Log, CurrentProjectPath).fullPath) | ||
.ToArray() | ||
?? []; | ||
|
||
List<string> features = new() | ||
{ | ||
EnableThreads ? "mt" : "st", | ||
"simd" | ||
}; | ||
|
||
Log.LogMessage(MessageImportance.Low, $"Bitcode files features lookup filter: {string.Join(",", features)}"); | ||
|
||
if (Version.TryParse(EmscriptenVersion, out var emsdkVersion)) | ||
{ | ||
var list = BitcodeFilesSelector.Filter(emsdkVersion, features.ToArray(), bitcodeFiles); | ||
|
||
NativeFileReference = list.Select(i => new TaskItem(i)).ToArray(); | ||
} | ||
else | ||
{ | ||
Log.LogMessage(MessageImportance.Low, $"EmscriptenVersion is not set, skipping native assets"); | ||
} | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.