8.2版本上传
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using dnlib.DotNet;
|
||||
using dnlib.DotNet.Writer;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HybridCLR.Editor.AOT
|
||||
{
|
||||
public class AOTAssemblyMetadataStripper
|
||||
{
|
||||
public static byte[] Strip(byte[] assemblyBytes)
|
||||
{
|
||||
var context = ModuleDef.CreateModuleContext();
|
||||
var readerOption = new ModuleCreationOptions(context)
|
||||
{
|
||||
Runtime = CLRRuntimeReaderKind.Mono
|
||||
};
|
||||
var mod = ModuleDefMD.Load(assemblyBytes, readerOption);
|
||||
// remove all resources
|
||||
mod.Resources.Clear();
|
||||
foreach (var type in mod.GetTypes())
|
||||
{
|
||||
if (type.HasGenericParameters)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
foreach (var method in type.Methods)
|
||||
{
|
||||
if (!method.HasBody || method.HasGenericParameters)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
method.Body = null;
|
||||
}
|
||||
}
|
||||
var writer = new System.IO.MemoryStream();
|
||||
var options = new ModuleWriterOptions(mod);
|
||||
options.MetadataOptions.Flags |= MetadataFlags.PreserveRids;
|
||||
mod.Write(writer, options);
|
||||
writer.Flush();
|
||||
return writer.ToArray();
|
||||
}
|
||||
|
||||
public static void Strip(string originalAssemblyPath, string strippedAssemblyPath)
|
||||
{
|
||||
byte[] originDllBytes = System.IO.File.ReadAllBytes(originalAssemblyPath);
|
||||
byte[] strippedDllBytes = Strip(originDllBytes);
|
||||
UnityEngine.Debug.Log($"aot dll:{originalAssemblyPath}, length: {originDllBytes.Length} -> {strippedDllBytes.Length}, stripping rate:{(originDllBytes.Length - strippedDllBytes.Length)/(double)originDllBytes.Length} ");
|
||||
Directory.CreateDirectory(System.IO.Path.GetDirectoryName(strippedAssemblyPath));
|
||||
System.IO.File.WriteAllBytes(strippedAssemblyPath, strippedDllBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e9e6a048682dcb4fab806251411f29f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -17,12 +17,16 @@ namespace HybridCLR.Editor.AOT
|
||||
public AssemblyReferenceDeepCollector Collector { get; set; }
|
||||
|
||||
public int MaxIterationCount { get; set; }
|
||||
|
||||
public bool ComputeAotAssembly { get; set; }
|
||||
}
|
||||
|
||||
private readonly int _maxInterationCount;
|
||||
|
||||
private readonly AssemblyReferenceDeepCollector _assemblyCollector;
|
||||
|
||||
private readonly bool _computeAotAssembly;
|
||||
|
||||
private readonly HashSet<GenericClass> _genericTypes = new HashSet<GenericClass>();
|
||||
private readonly HashSet<GenericMethod> _genericMethods = new HashSet<GenericMethod>();
|
||||
|
||||
@@ -47,6 +51,7 @@ namespace HybridCLR.Editor.AOT
|
||||
{
|
||||
_assemblyCollector = options.Collector;
|
||||
_maxInterationCount = options.MaxIterationCount;
|
||||
_computeAotAssembly = options.ComputeAotAssembly;
|
||||
_methodReferenceAnalyzer = new MethodReferenceAnalyzer(this.OnNewMethod);
|
||||
_hotUpdateAssemblyFiles = new HashSet<string>(options.Collector.GetRootAssemblyNames().Select(assName => assName + ".dll"));
|
||||
}
|
||||
@@ -71,7 +76,7 @@ namespace HybridCLR.Editor.AOT
|
||||
|
||||
private bool IsAotType(TypeDef type)
|
||||
{
|
||||
return !_hotUpdateAssemblyFiles.Contains(type.Module.Name);
|
||||
return _computeAotAssembly || !_hotUpdateAssemblyFiles.Contains(type.Module.Name);
|
||||
}
|
||||
|
||||
private bool IsAotGenericMethod(MethodDef method)
|
||||
@@ -191,11 +196,29 @@ namespace HybridCLR.Editor.AOT
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsNotShareableAOTGenericType(TypeDef typeDef)
|
||||
{
|
||||
if (!IsAotType(typeDef))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return typeDef.GenericParameters.Any(c => !c.HasReferenceTypeConstraint);
|
||||
}
|
||||
|
||||
private bool IsNotShareableAOTGenericMethod(MethodDef method)
|
||||
{
|
||||
if (!IsAotGenericMethod(method))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return method.GenericParameters.Concat(method.DeclaringType.GenericParameters).Any(c => !c.HasReferenceTypeConstraint);
|
||||
}
|
||||
|
||||
private void FilterAOTGenericTypeAndMethods()
|
||||
{
|
||||
ConstraintContext cc = this.ConstraintContext;
|
||||
AotGenericTypes.AddRange(_genericTypes.Where(type => IsAotType(type.Type)).Select(gc => cc.ApplyConstraints(gc)));
|
||||
AotGenericMethods.AddRange(_genericMethods.Where(method => IsAotGenericMethod(method.Method)).Select(gm => cc.ApplyConstraints(gm)));
|
||||
AotGenericTypes.AddRange(_genericTypes.Where(type => IsNotShareableAOTGenericType(type.Type)).Select(gc => cc.ApplyConstraints(gc)));
|
||||
AotGenericMethods.AddRange(_genericMethods.Where(method => IsNotShareableAOTGenericMethod(method.Method)).Select(gm => cc.ApplyConstraints(gm)));
|
||||
}
|
||||
|
||||
public void Run()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5eb77177ef7793a44af2666b647e9605
|
||||
guid: 30bbf4a80a6cf3a43b3f489747d9dd6a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6b6f4ac6086fbc46b43cb1610dba4fb
|
||||
guid: 812d81a75b690394bbe16ef5f0bcbc46
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace HybridCLR.Editor.AOT
|
||||
{
|
||||
_typeSimpleNameMapping.Add(e.Key.FullName, e.Value);
|
||||
}
|
||||
_systemTypePattern = new Regex(string.Join("|", _typeSimpleNameMapping.Keys.Select (k => $@"\b{k}\b")));
|
||||
_systemTypePattern = new Regex(string.Join("|", _typeSimpleNameMapping.Keys.Select (k => $@"\b{Regex.Escape(k)}\b")));
|
||||
}
|
||||
|
||||
public string PrettifyTypeSig(string typeSig)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc730a906269a78429589f950b5a92f3
|
||||
guid: d1243cf04685361478972f93b5ca868a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
||||
Reference in New Issue
Block a user