commit
3c280ba80b
|
@ -30,17 +30,20 @@ namespace HybridCLR.Editor.Commands
|
||||||
|
|
||||||
var gs = SettingsUtil.GlobalSettings;
|
var gs = SettingsUtil.GlobalSettings;
|
||||||
|
|
||||||
var analyzer = new Analyzer(new Analyzer.Options
|
using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget), SettingsUtil.HotUpdateAssemblyNames))
|
||||||
{
|
{
|
||||||
MaxIterationCount = Math.Min(20, gs.maxGenericReferenceIteration),
|
var analyzer = new Analyzer(new Analyzer.Options
|
||||||
Collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget), SettingsUtil.HotUpdateAssemblyNames),
|
{
|
||||||
});
|
MaxIterationCount = Math.Min(20, gs.maxGenericReferenceIteration),
|
||||||
|
Collector = collector,
|
||||||
|
});
|
||||||
|
|
||||||
analyzer.Run();
|
analyzer.Run();
|
||||||
|
|
||||||
var writer = new GenericReferenceWriter();
|
var writer = new GenericReferenceWriter();
|
||||||
writer.Write(analyzer.AotGenericTypes.ToList(), analyzer.AotGenericMethods.ToList(), $"{Application.dataPath}/{gs.outputAOTGenericReferenceFile}");
|
writer.Write(analyzer.AotGenericTypes.ToList(), analyzer.AotGenericMethods.ToList(), $"{Application.dataPath}/{gs.outputAOTGenericReferenceFile}");
|
||||||
AssetDatabase.Refresh();
|
AssetDatabase.Refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,32 +72,37 @@ namespace HybridCLR.Editor.Commands
|
||||||
{
|
{
|
||||||
CompileDllCommand.CompileDllActiveBuildTarget();
|
CompileDllCommand.CompileDllActiveBuildTarget();
|
||||||
}
|
}
|
||||||
var analyzer = new Analyzer(new Analyzer.Options
|
|
||||||
{
|
|
||||||
MaxIterationCount = Math.Min(20, SettingsUtil.GlobalSettings.maxMethodBridgeGenericIteration),
|
|
||||||
Collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget), SettingsUtil.HotUpdateAssemblyNames),
|
|
||||||
});
|
|
||||||
|
|
||||||
analyzer.Run();
|
using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateBuildTargetAssemblyResolver(EditorUserBuildSettings.activeBuildTarget), SettingsUtil.HotUpdateAssemblyNames))
|
||||||
|
|
||||||
var generateJobs = new List<(PlatformABI, string)>()
|
|
||||||
{
|
{
|
||||||
(PlatformABI.Arm64, "MethodBridge_Arm64"),
|
var analyzer = new Analyzer(new Analyzer.Options
|
||||||
(PlatformABI.Universal64, "MethodBridge_Universal64"),
|
|
||||||
(PlatformABI.Universal32, "MethodBridge_Universal32"),
|
|
||||||
};
|
|
||||||
|
|
||||||
var tasks = new List<Task>();
|
|
||||||
foreach (var (platform, stubFile) in generateJobs)
|
|
||||||
{
|
|
||||||
string templateCode = GetTemplateCode(platform);
|
|
||||||
string outputFile = $"{SettingsUtil.MethodBridgeCppDir}/{stubFile}.cpp";
|
|
||||||
tasks.Add(Task.Run(() =>
|
|
||||||
{
|
{
|
||||||
GenerateMethodBridgeCppFile(analyzer, platform, templateCode, outputFile);
|
MaxIterationCount = Math.Min(20, SettingsUtil.GlobalSettings.maxMethodBridgeGenericIteration),
|
||||||
}));
|
Collector = collector,
|
||||||
|
});
|
||||||
|
|
||||||
|
analyzer.Run();
|
||||||
|
|
||||||
|
var generateJobs = new List<(PlatformABI, string)>()
|
||||||
|
{
|
||||||
|
(PlatformABI.Arm64, "MethodBridge_Arm64"),
|
||||||
|
(PlatformABI.Universal64, "MethodBridge_Universal64"),
|
||||||
|
(PlatformABI.Universal32, "MethodBridge_Universal32"),
|
||||||
|
};
|
||||||
|
|
||||||
|
var tasks = new List<Task>();
|
||||||
|
foreach (var (platform, stubFile) in generateJobs)
|
||||||
|
{
|
||||||
|
string templateCode = GetTemplateCode(platform);
|
||||||
|
string outputFile = $"{SettingsUtil.MethodBridgeCppDir}/{stubFile}.cpp";
|
||||||
|
tasks.Add(Task.Run(() =>
|
||||||
|
{
|
||||||
|
GenerateMethodBridgeCppFile(analyzer, platform, templateCode, outputFile);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
Task.WaitAll(tasks.ToArray());
|
||||||
}
|
}
|
||||||
Task.WaitAll(tasks.ToArray());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,29 +21,32 @@ namespace HybridCLR.Editor.Link
|
||||||
|
|
||||||
public HashSet<TypeRef> CollectRefs(List<Assembly> rootAssemblies)
|
public HashSet<TypeRef> CollectRefs(List<Assembly> rootAssemblies)
|
||||||
{
|
{
|
||||||
var assCollector = new AssemblyCache(_resolver);
|
using (var assCollector = new AssemblyCache(_resolver))
|
||||||
var rootAssemblyName = new HashSet<string>();
|
|
||||||
foreach(var ass in rootAssemblies)
|
|
||||||
{
|
{
|
||||||
if (!rootAssemblyName.Add(ass.GetName().Name))
|
var rootAssemblyName = new HashSet<string>();
|
||||||
|
foreach (var ass in rootAssemblies)
|
||||||
{
|
{
|
||||||
throw new Exception($"assembly:{ass.GetName().Name} 重复");
|
if (!rootAssemblyName.Add(ass.GetName().Name))
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var typeRefs = new HashSet<TypeRef>(TypeEqualityComparer.Instance);
|
|
||||||
foreach (var rootAss in rootAssemblies)
|
|
||||||
{
|
|
||||||
var dnAss = assCollector.LoadModule(rootAss.GetName().Name);
|
|
||||||
foreach(var type in dnAss.GetTypeRefs())
|
|
||||||
{
|
|
||||||
if (!rootAssemblyName.Contains(type.DefinitionAssembly.Name))
|
|
||||||
{
|
{
|
||||||
typeRefs.Add(type);
|
throw new Exception($"assembly:{ass.GetName().Name} 重复");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var typeRefs = new HashSet<TypeRef>(TypeEqualityComparer.Instance);
|
||||||
|
foreach (var rootAss in rootAssemblies)
|
||||||
|
{
|
||||||
|
var dnAss = assCollector.LoadModule(rootAss.GetName().Name);
|
||||||
|
foreach (var type in dnAss.GetTypeRefs())
|
||||||
|
{
|
||||||
|
if (!rootAssemblyName.Contains(type.DefinitionAssembly.Name))
|
||||||
|
{
|
||||||
|
typeRefs.Add(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assCollector.Dispose();
|
||||||
|
return typeRefs;
|
||||||
}
|
}
|
||||||
return typeRefs;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,11 +9,12 @@ using UnityEngine;
|
||||||
|
|
||||||
namespace HybridCLR.Editor.Meta
|
namespace HybridCLR.Editor.Meta
|
||||||
{
|
{
|
||||||
public class AssemblyCache
|
public class AssemblyCache : IDisposable
|
||||||
{
|
{
|
||||||
private readonly IAssemblyResolver _assemblyPathResolver;
|
private readonly IAssemblyResolver _assemblyPathResolver;
|
||||||
private readonly ModuleContext _modCtx;
|
private readonly ModuleContext _modCtx;
|
||||||
private readonly AssemblyResolver _asmResolver;
|
private readonly AssemblyResolver _asmResolver;
|
||||||
|
private bool disposedValue;
|
||||||
|
|
||||||
public Dictionary<string, ModuleDefMD> LoadedModules { get; } = new Dictionary<string, ModuleDefMD>();
|
public Dictionary<string, ModuleDefMD> LoadedModules { get; } = new Dictionary<string, ModuleDefMD>();
|
||||||
|
|
||||||
|
@ -51,5 +52,26 @@ namespace HybridCLR.Editor.Meta
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (!disposedValue)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
foreach(var mod in LoadedModules.Values)
|
||||||
|
{
|
||||||
|
mod.Dispose();
|
||||||
|
}
|
||||||
|
LoadedModules.Clear();
|
||||||
|
}
|
||||||
|
disposedValue = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(disposing: true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,14 @@ using UnityEngine;
|
||||||
|
|
||||||
namespace HybridCLR.Editor.Meta
|
namespace HybridCLR.Editor.Meta
|
||||||
{
|
{
|
||||||
public class AssemblyReferenceDeepCollector
|
public class AssemblyReferenceDeepCollector : IDisposable
|
||||||
{
|
{
|
||||||
private readonly IAssemblyResolver _assemblyPathResolver;
|
private readonly IAssemblyResolver _assemblyPathResolver;
|
||||||
private readonly List<string> _rootAssemblies;
|
private readonly List<string> _rootAssemblies;
|
||||||
|
|
||||||
private readonly ModuleContext _modCtx;
|
private readonly ModuleContext _modCtx;
|
||||||
private readonly AssemblyResolver _asmResolver;
|
private readonly AssemblyResolver _asmResolver;
|
||||||
|
private bool disposedValue;
|
||||||
|
|
||||||
public Dictionary<string, ModuleDefMD> LoadedModules { get; } = new Dictionary<string, ModuleDefMD>();
|
public Dictionary<string, ModuleDefMD> LoadedModules { get; } = new Dictionary<string, ModuleDefMD>();
|
||||||
|
|
||||||
|
@ -78,5 +79,26 @@ namespace HybridCLR.Editor.Meta
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (!disposedValue)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
foreach(var mod in LoadedModules.Values)
|
||||||
|
{
|
||||||
|
mod.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LoadedModules.Clear();
|
||||||
|
disposedValue = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(disposing: true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "com.focus-creative-games.hybridclr_unity",
|
"name": "com.focus-creative-games.hybridclr_unity",
|
||||||
"version": "0.2.1",
|
"version": "0.3.0",
|
||||||
"displayName": "HybridCLR",
|
"displayName": "HybridCLR",
|
||||||
"description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR",
|
"description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR",
|
||||||
"category": "Runtime",
|
"category": "Runtime",
|
||||||
|
|
Loading…
Reference in New Issue