2022-10-17 12:16:18 +08:00
|
|
|
|
using HybridCLR.Editor.ABI;
|
|
|
|
|
using HybridCLR.Editor.Link;
|
|
|
|
|
using HybridCLR.Editor.Meta;
|
2022-10-17 21:38:39 +08:00
|
|
|
|
using HybridCLR.Editor.ReversePInvokeWrap;
|
2022-09-22 08:56:07 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace HybridCLR.Editor.Commands
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public static class ReversePInvokeWrapperGeneratorCommand
|
|
|
|
|
{
|
|
|
|
|
|
2022-09-23 14:26:28 +08:00
|
|
|
|
[MenuItem("HybridCLR/Generate/ReversePInvokeWrapper", priority = 103)]
|
2022-12-14 14:11:32 +08:00
|
|
|
|
|
|
|
|
|
public static void CompileAndGenerateReversePInvokeWrapper()
|
|
|
|
|
{
|
|
|
|
|
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
|
|
|
|
|
CompileDllCommand.CompileDll(target);
|
|
|
|
|
GenerateReversePInvokeWrapper(target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void GenerateReversePInvokeWrapper(BuildTarget target)
|
2022-09-22 08:56:07 +08:00
|
|
|
|
{
|
2023-01-11 17:41:44 +08:00
|
|
|
|
List<string> hotUpdateDlls = SettingsUtil.HotUpdateAssemblyNamesExcludePreserved;
|
2022-12-14 14:11:32 +08:00
|
|
|
|
using (var cache = new AssemblyCache(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotUpdateDlls)))
|
2022-10-17 12:16:18 +08:00
|
|
|
|
{
|
2022-12-14 14:11:32 +08:00
|
|
|
|
var analyzer = new ReversePInvokeWrap.Analyzer(cache, hotUpdateDlls);
|
2022-10-17 21:38:39 +08:00
|
|
|
|
analyzer.Run();
|
|
|
|
|
|
2023-08-22 11:16:31 +08:00
|
|
|
|
string outputFile = $"{SettingsUtil.GeneratedCppDir}/ReversePInvokeMethodStub.cpp";
|
2022-10-17 12:16:18 +08:00
|
|
|
|
|
2023-08-22 11:16:31 +08:00
|
|
|
|
List<ABIReversePInvokeMethodInfo> methods = analyzer.BuildABIMethods();
|
|
|
|
|
Debug.Log($"GenerateReversePInvokeWrapper. wraperCount:{methods.Sum(m => m.Count)} output:{outputFile}");
|
|
|
|
|
var generator = new Generator();
|
2023-11-10 13:35:53 +08:00
|
|
|
|
generator.Generate(methods, outputFile);
|
|
|
|
|
Debug.LogFormat("[ReversePInvokeWrapperGeneratorCommand] output:{0}", outputFile);
|
2022-10-17 21:38:39 +08:00
|
|
|
|
}
|
|
|
|
|
MethodBridgeGeneratorCommand.CleanIl2CppBuildCache();
|
2022-09-22 08:56:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|