mirror of
https://github.com/focus-creative-games/hybridclr_unity.git
synced 2026-11-20 07:22:39 +08:00
Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 909e96ca7c | |||
| 75b24345f6 | |||
| 88e20505f8 | |||
| b4b486944c | |||
| 360ba38805 | |||
| e5a6952777 | |||
| 9330cf682c | |||
| 16a7d5d529 | |||
| 303c6c7b35 | |||
| e4cf9e9086 | |||
| b977a85b23 | |||
| 0fcb51a369 | |||
| d61511924d | |||
| aca7dd0a67 | |||
| fc685a99ca | |||
| d431aeb019 | |||
| 63d0aaa6e6 | |||
| d45974c6b4 | |||
| 3de931a3af | |||
| b96d6fc10d | |||
| ef1b78caae | |||
| 47622bf49c | |||
| 846d7103a3 | |||
| 170f13082e | |||
| 60016d7481 | |||
| 97dae7fed2 | |||
| f935127cd3 | |||
| ec5f2ef05e | |||
| 6d0ceaa4f5 |
@@ -2,28 +2,38 @@
|
||||
"versions": [
|
||||
{
|
||||
"unity_version":"2019",
|
||||
"hybridclr" : { "branch":"v5.3.0"},
|
||||
"il2cpp_plus": { "branch":"v2019-5.3.0"}
|
||||
"hybridclr" : { "branch":"v6.2.0"},
|
||||
"il2cpp_plus": { "branch":"v2019-6.1.0"}
|
||||
},
|
||||
{
|
||||
"unity_version":"2020",
|
||||
"hybridclr" : { "branch":"v5.3.0"},
|
||||
"il2cpp_plus": { "branch":"v2020-5.3.0"}
|
||||
"hybridclr" : { "branch":"v6.2.0"},
|
||||
"il2cpp_plus": { "branch":"v2020-6.1.0"}
|
||||
},
|
||||
{
|
||||
"unity_version":"2021",
|
||||
"hybridclr" : { "branch":"v5.3.0"},
|
||||
"il2cpp_plus": { "branch":"v2021-5.3.0"}
|
||||
"hybridclr" : { "branch":"v6.2.0"},
|
||||
"il2cpp_plus": { "branch":"v2021-6.2.0"}
|
||||
},
|
||||
{
|
||||
"unity_version":"2022",
|
||||
"hybridclr" : { "branch":"v5.3.0"},
|
||||
"il2cpp_plus": { "branch":"v2022-5.3.0"}
|
||||
"hybridclr" : { "branch":"v6.2.0"},
|
||||
"il2cpp_plus": { "branch":"v2022-6.1.0"}
|
||||
},
|
||||
{
|
||||
"unity_version":"2022-tuanjie",
|
||||
"hybridclr" : { "branch":"v5.3.0"},
|
||||
"il2cpp_plus": { "branch":"v2022-tuanjie-5.3.0"}
|
||||
"hybridclr" : { "branch":"v6.2.0"},
|
||||
"il2cpp_plus": { "branch":"v2022-tuanjie-6.1.0"}
|
||||
},
|
||||
{
|
||||
"unity_version":"2023",
|
||||
"hybridclr" : { "branch":"v6.2.0"},
|
||||
"il2cpp_plus": { "branch":"v2023-6.0.0"}
|
||||
},
|
||||
{
|
||||
"unity_version":"6000",
|
||||
"hybridclr" : { "branch":"v6.2.0"},
|
||||
"il2cpp_plus": { "branch":"v6000-6.1.0"}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -12,7 +12,7 @@ using System.IO;
|
||||
|
||||
namespace HybridCLR.MonoHook
|
||||
{
|
||||
#if UNITY_2021_1_OR_NEWER
|
||||
#if UNITY_2021_1_OR_NEWER && !UNITY_2023_1_OR_NEWER
|
||||
[InitializeOnLoad]
|
||||
public class CopyStrippedAOTAssembliesHook
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ using System.IO;
|
||||
|
||||
namespace HybridCLR.MonoHook
|
||||
{
|
||||
#if UNITY_2022
|
||||
#if UNITY_2022 || UNITY_2023_1_OR_NEWER
|
||||
[InitializeOnLoad]
|
||||
public class GetIl2CppFolderHook
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ using System.IO;
|
||||
|
||||
namespace HybridCLR.MonoHook
|
||||
{
|
||||
#if (UNITY_2021_1_OR_NEWER && UNITY_WEBGL) || TUANJIE_2022_3_OR_NEWER
|
||||
#if UNITY_2021_1_OR_NEWER && (UNITY_WEBGL || UNITY_WEIXINMINIGAME)
|
||||
[InitializeOnLoad]
|
||||
public class PatchScriptingAssembliesJsonHook
|
||||
{
|
||||
@@ -35,12 +35,10 @@ namespace HybridCLR.MonoHook
|
||||
|
||||
private static string BuildMainWindowTitle()
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
string tempJsonPath = $"{Application.dataPath}/../Library/PlayerDataCache/WebGL/Data/ScriptingAssemblies.json";
|
||||
#if TUANJIE_2022_3_OR_NEWER
|
||||
if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.WeixinMiniGame)
|
||||
{
|
||||
tempJsonPath = $"{Application.dataPath}/../Library/PlayerDataCache/WeixinMiniGame/Data/ScriptingAssemblies.json";
|
||||
}
|
||||
#elif UNITY_WEIXINMINIGAME
|
||||
string tempJsonPath = $"{Application.dataPath}/../Library/PlayerDataCache/WeixinMiniGame/Data/ScriptingAssemblies.json";
|
||||
#endif
|
||||
if (File.Exists(tempJsonPath))
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -17,18 +17,6 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||
{
|
||||
public static class AddLil2cppSourceCodeToXcodeproj2019
|
||||
{
|
||||
//[MenuItem("Test/GenProj")]
|
||||
//public static void Modify()
|
||||
//{
|
||||
// OnPostProcessBuild(BuildTarget.iOS, $"{SettingsUtil.ProjectDir}/Build-iOS");
|
||||
//}
|
||||
|
||||
//[MenuItem("Test/CreateLumps")]
|
||||
//public static void CreateLumpsCmd()
|
||||
//{
|
||||
// CreateLumps($"{SettingsUtil.LocalIl2CppDir}/libil2cpp", $"{SettingsUtil.HybridCLRDataDir}/lumps");
|
||||
//}
|
||||
|
||||
[PostProcessBuild]
|
||||
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
|
||||
{
|
||||
@@ -46,8 +34,8 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||
9. add external/xxHash
|
||||
10. add "#include <stdio.h>" to Classes/Prefix.pch
|
||||
*/
|
||||
|
||||
string pbxprojFile = $"{pathToBuiltProject}/Unity-iPhone.xcodeproj/project.pbxproj";
|
||||
|
||||
string pbxprojFile = BuildProcessorUtil.GetXcodeProjectFile(pathToBuiltProject);
|
||||
string srcLibil2cppDir = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp";
|
||||
string dstLibil2cppDir = $"{pathToBuiltProject}/Libraries/libil2cpp";
|
||||
string lumpDir = $"{pathToBuiltProject}/Libraries/lumps";
|
||||
|
||||
@@ -17,17 +17,6 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||
{
|
||||
public static class AddLil2cppSourceCodeToXcodeproj2020Or2021
|
||||
{
|
||||
//[MenuItem("Test/GenProj")]
|
||||
//public static void Modify()
|
||||
//{
|
||||
// OnPostProcessBuild(BuildTarget.iOS, $"{SettingsUtil.ProjectDir}/Build-iOS");
|
||||
//}
|
||||
|
||||
//[MenuItem("Test/CreateLumps")]
|
||||
//public static void CreateLumpsCmd()
|
||||
//{
|
||||
// CreateLumps($"{SettingsUtil.LocalIl2CppDir}/libil2cpp", $"{SettingsUtil.HybridCLRDataDir}/lumps");
|
||||
//}
|
||||
|
||||
[PostProcessBuild]
|
||||
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
|
||||
@@ -46,7 +35,7 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||
9. add external/xxHash
|
||||
*/
|
||||
|
||||
string pbxprojFile = $"{pathToBuiltProject}/Unity-iPhone.xcodeproj/project.pbxproj";
|
||||
string pbxprojFile = BuildProcessorUtil.GetXcodeProjectFile(pathToBuiltProject);
|
||||
string srcLibil2cppDir = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp";
|
||||
string dstLibil2cppDir = $"{pathToBuiltProject}/Libraries/libil2cpp";
|
||||
string lumpDir = $"{pathToBuiltProject}/Libraries/lumps";
|
||||
|
||||
@@ -7,28 +7,19 @@ using UnityEditor.Build;
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_2022_2_OR_NEWER && (UNITY_IOS || UNITY_TVOS)
|
||||
#if UNITY_2022 && (UNITY_IOS || UNITY_TVOS || UNITY_VISIONOS)
|
||||
|
||||
namespace HybridCLR.Editor.BuildProcessors
|
||||
{
|
||||
public static class AddLil2cppSourceCodeToXcodeproj2022OrNewer
|
||||
{
|
||||
//[MenuItem("HybridCLR/Modfiyxcode")]
|
||||
//public static void Modify()
|
||||
//{
|
||||
// OnPostProcessBuild(BuildTarget.iOS, $"{SettingsUtil.ProjectDir}/Build-iOS");
|
||||
//}
|
||||
|
||||
[PostProcessBuild]
|
||||
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
|
||||
{
|
||||
if (!HybridCLRSettings.Instance.enable)
|
||||
return;
|
||||
#if TUANJIE_2022_3_OR_NEWER
|
||||
string pbxprojFile = $"{pathToBuiltProject}/Tuanjie-iPhone.xcodeproj/project.pbxproj";
|
||||
#else
|
||||
string pbxprojFile = $"{pathToBuiltProject}/Unity-iPhone.xcodeproj/project.pbxproj";
|
||||
#endif
|
||||
string pbxprojFile = BuildProcessorUtil.GetXcodeProjectFile(pathToBuiltProject);
|
||||
RemoveExternalLibil2cppOption(pbxprojFile);
|
||||
CopyLibil2cppToXcodeProj(pathToBuiltProject);
|
||||
}
|
||||
@@ -37,15 +28,25 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||
{
|
||||
string pbxprojContent = File.ReadAllText(pbxprojFile, Encoding.UTF8);
|
||||
string removeBuildOption = @"--external-lib-il2-cpp=\""$PROJECT_DIR/Libraries/libil2cpp.a\""";
|
||||
if (!pbxprojContent.Contains(removeBuildOption))
|
||||
if (pbxprojContent.Contains(removeBuildOption))
|
||||
{
|
||||
//throw new BuildFailedException("modified project.pbxproj fail");
|
||||
Debug.LogError("[AddLil2cppSourceCodeToXcodeproj] modified project.pbxproj fail");
|
||||
return;
|
||||
pbxprojContent = pbxprojContent.Replace(removeBuildOption, "");
|
||||
Debug.Log($"[AddLil2cppSourceCodeToXcodeproj] remove il2cpp build option '{removeBuildOption}' from file '{pbxprojFile}'");
|
||||
}
|
||||
pbxprojContent = pbxprojContent.Replace(removeBuildOption, "");
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"[AddLil2cppSourceCodeToXcodeproj] project.pbxproj remove building option:'{removeBuildOption}' fail. This may occur when 'Append' to existing xcode project in building");
|
||||
}
|
||||
|
||||
int strShellScriptIndex1 = pbxprojContent.IndexOf("/* ShellScript */,");
|
||||
int strShellScriptIndex2 = pbxprojContent.IndexOf("/* ShellScript */,", strShellScriptIndex1 + 10);
|
||||
if (strShellScriptIndex2 >= 0)
|
||||
{
|
||||
pbxprojContent = pbxprojContent.Remove(strShellScriptIndex1, strShellScriptIndex2 - strShellScriptIndex1);
|
||||
Debug.LogWarning($"[AddLil2cppSourceCodeToXcodeproj] remove duplicated '/* ShellScript */' from file '{pbxprojFile}'");
|
||||
}
|
||||
|
||||
File.WriteAllText(pbxprojFile, pbxprojContent, Encoding.UTF8);
|
||||
Debug.Log($"[AddLil2cppSourceCodeToXcodeproj] remove il2cpp build option '{removeBuildOption}' from file '{pbxprojFile}'");
|
||||
}
|
||||
|
||||
private static void CopyLibil2cppToXcodeProj(string pathToBuiltProject)
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using HybridCLR.Editor.Installer;
|
||||
using HybridCLR.Editor.Settings;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_2023_1_OR_NEWER && (UNITY_IOS || UNITY_TVOS || UNITY_VISIONOS)
|
||||
|
||||
namespace HybridCLR.Editor.BuildProcessors
|
||||
{
|
||||
public static class AddLil2cppSourceCodeToXcodeproj2022OrNewer
|
||||
{
|
||||
|
||||
[PostProcessBuild]
|
||||
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
|
||||
{
|
||||
if (!HybridCLRSettings.Instance.enable)
|
||||
return;
|
||||
CopyLibil2cppToXcodeProj(pathToBuiltProject);
|
||||
}
|
||||
|
||||
private static void CopyLibil2cppToXcodeProj(string pathToBuiltProject)
|
||||
{
|
||||
string srcLibil2cppDir = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp";
|
||||
string destLibil2cppDir = $"{pathToBuiltProject}/Il2CppOutputProject/IL2CPP/libil2cpp";
|
||||
BashUtil.RemoveDir(destLibil2cppDir);
|
||||
BashUtil.CopyDir(srcLibil2cppDir, destLibil2cppDir, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2fa46135129b046a28014d58fdfd18ca
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEditor.Build;
|
||||
|
||||
namespace HybridCLR.Editor.BuildProcessors
|
||||
{
|
||||
|
||||
public static class BuildProcessorUtil
|
||||
{
|
||||
|
||||
public static string GetXcodeProjectFile(string pathToBuiltProject)
|
||||
{
|
||||
foreach (string dir in Directory.GetDirectories(pathToBuiltProject, "*.xcodeproj", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
string pbxprojFile = $"{dir}/project.pbxproj";
|
||||
if (File.Exists(pbxprojFile))
|
||||
{
|
||||
return pbxprojFile;
|
||||
}
|
||||
}
|
||||
throw new BuildFailedException($"can't find xxxx.xcodeproj/project.pbxproj in {pathToBuiltProject}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7db18e1736f593c4089c85d764cf8620
|
||||
guid: c680e56f90f2745298a90803c04f6efc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,8 +1,10 @@
|
||||
using HybridCLR.Editor.Settings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
@@ -16,6 +18,8 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||
{
|
||||
public int callbackOrder => 0;
|
||||
|
||||
public static bool DisableMethodBridgeDevelopmentFlagChecking { get; set; }
|
||||
|
||||
public void OnPreprocessBuild(BuildReport report)
|
||||
{
|
||||
HybridCLRSettings globalSettings = SettingsUtil.HybridCLRSettings;
|
||||
@@ -67,6 +71,24 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||
Debug.LogWarning("[CheckSettings] No hot update modules configured in HybridCLRSettings");
|
||||
}
|
||||
|
||||
if (!DisableMethodBridgeDevelopmentFlagChecking)
|
||||
{
|
||||
string methodBridgeFile = $"{SettingsUtil.GeneratedCppDir}/MethodBridge.cpp";
|
||||
var match = Regex.Match(File.ReadAllText(methodBridgeFile), @"// DEVELOPMENT=(\d)");
|
||||
if (match.Success)
|
||||
{
|
||||
int developmentFlagInMethodBridge = int.Parse(match.Groups[1].Value);
|
||||
int developmentFlagInEditorSettings = EditorUserBuildSettings.development ? 1 : 0;
|
||||
if (developmentFlagInMethodBridge != developmentFlagInEditorSettings)
|
||||
{
|
||||
Debug.LogError($"[CheckSettings] MethodBridge.cpp DEVELOPMENT flag:{developmentFlagInMethodBridge} is inconsistent with EditorUserBuildSettings.development:{developmentFlagInEditorSettings}. Please run 'HybridCLR/Generate/All' before building.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("[CheckSettings] MethodBridge.cpp DEVELOPMENT flag not found. Please run 'HybridCLR/Generate/All' before building.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,11 @@ using System.Threading.Tasks;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEditor.Il2Cpp;
|
||||
using UnityEditor.UnityLinker;
|
||||
using UnityEngine;
|
||||
#if !UNITY_2021_1_OR_NEWER
|
||||
using UnityEditor.Il2Cpp;
|
||||
#endif
|
||||
|
||||
namespace HybridCLR.Editor.BuildProcessors
|
||||
{
|
||||
@@ -36,8 +38,14 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||
case BuildTarget.Android:
|
||||
return $"{projectDir}/Library/Bee/artifacts/Android/ManagedStripped";
|
||||
case BuildTarget.iOS:
|
||||
return $"{projectDir}/Library/Bee/artifacts/iOS/ManagedStripped";
|
||||
case BuildTarget.WebGL:
|
||||
#if UNITY_TVOS
|
||||
case BuildTarget.tvOS:
|
||||
#endif
|
||||
#if UNITY_VISIONOS
|
||||
case BuildTarget.VisionOS:
|
||||
#endif
|
||||
return $"{projectDir}/Library/Bee/artifacts/iOS/ManagedStripped";
|
||||
case BuildTarget.WebGL:
|
||||
return $"{projectDir}/Library/Bee/artifacts/WebGL/ManagedStripped";
|
||||
case BuildTarget.StandaloneOSX:
|
||||
return $"{projectDir}/Library/Bee/artifacts/MacStandalonePlayerBuildProgram/ManagedStripped";
|
||||
@@ -45,11 +53,11 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||
return $"{projectDir}/Library/Bee/artifacts/PS4PlayerBuildProgram/ManagedStripped";
|
||||
case BuildTarget.PS5:
|
||||
return $"{projectDir}/Library/Bee/artifacts/PS5PlayerBuildProgram/ManagedStripped";
|
||||
case BuildTarget.tvOS:
|
||||
return $"{projectDir}/Library/Bee/artifacts/iOS/ManagedStripped";
|
||||
#if TUANJIE_2022_3_OR_NEWER
|
||||
#if UNITY_WEIXINMINIGAME
|
||||
case BuildTarget.WeixinMiniGame:
|
||||
return $"{projectDir}/Library/Bee/artifacts/WeixinMiniGame/ManagedStripped";
|
||||
#endif
|
||||
#if UNITY_OPENHARMONY
|
||||
case BuildTarget.OpenHarmony:
|
||||
return $"{projectDir}/Library/Bee/artifacts/OpenHarmonyPlayerBuildProgram/ManagedStripped";
|
||||
#endif
|
||||
|
||||
@@ -9,10 +9,12 @@ using UnityEditor;
|
||||
using UnityEditor.Android;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEditor.Il2Cpp;
|
||||
using UnityEditor.UnityLinker;
|
||||
using UnityEngine;
|
||||
using UnityFS;
|
||||
#if !UNITY_2023_1_OR_NEWER
|
||||
using UnityEditor.Il2Cpp;
|
||||
#endif
|
||||
|
||||
namespace HybridCLR.Editor.BuildProcessors
|
||||
{
|
||||
@@ -177,7 +179,7 @@ namespace HybridCLR.Editor.BuildProcessors
|
||||
return true;
|
||||
}
|
||||
|
||||
#if UNITY_WEBGL
|
||||
#if UNITY_WEBGL && !UNITY_2022_3_OR_NEWER
|
||||
public void OnBeforeConvertRun(BuildReport report, Il2CppBuildPipelineData data)
|
||||
{
|
||||
PathScriptingAssembilesFile($"{SettingsUtil.ProjectDir}/Temp/StagingArea/Data");
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using HybridCLR.Editor.Meta;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -22,25 +23,110 @@ namespace HybridCLR.Editor.Commands
|
||||
GenerateAOTGenericReference(target);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算热更代码中的泛型引用
|
||||
/// </summary>
|
||||
/// <param name="target"></param>
|
||||
public static void GenerateAOTGenericReference(BuildTarget target)
|
||||
{
|
||||
var gs = SettingsUtil.HybridCLRSettings;
|
||||
List<string> hotUpdateDllNames = SettingsUtil.HotUpdateAssemblyNamesExcludePreserved;
|
||||
|
||||
using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotUpdateDllNames), hotUpdateDllNames))
|
||||
AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotUpdateDllNames), hotUpdateDllNames);
|
||||
var analyzer = new Analyzer(new Analyzer.Options
|
||||
{
|
||||
var analyzer = new Analyzer(new Analyzer.Options
|
||||
{
|
||||
MaxIterationCount = Math.Min(20, gs.maxGenericReferenceIteration),
|
||||
Collector = collector,
|
||||
});
|
||||
MaxIterationCount = Math.Min(20, gs.maxGenericReferenceIteration),
|
||||
Collector = collector,
|
||||
});
|
||||
|
||||
analyzer.Run();
|
||||
analyzer.Run();
|
||||
|
||||
var writer = new GenericReferenceWriter();
|
||||
writer.Write(analyzer.AotGenericTypes.ToList(), analyzer.AotGenericMethods.ToList(), $"{Application.dataPath}/{gs.outputAOTGenericReferenceFile}");
|
||||
AssetDatabase.Refresh();
|
||||
var writer = new GenericReferenceWriter();
|
||||
writer.Write(analyzer.AotGenericTypes.ToList(), analyzer.AotGenericMethods.ToList(), $"{Application.dataPath}/{gs.outputAOTGenericReferenceFile}");
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//[MenuItem("HybridCLR/Generate/AOTGenericReference2", priority = 103)]
|
||||
//public static void GeneratedAOTGenericReferenceExcludeExists()
|
||||
//{
|
||||
// GeneratedAOTGenericReferenceExcludeExists(EditorUserBuildSettings.activeBuildTarget);
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 计算热更新代码中的泛型引用,但排除AOT已经存在的泛型引用
|
||||
/// </summary>
|
||||
/// <param name="target"></param>
|
||||
///
|
||||
public static void GeneratedAOTGenericReferenceExcludeExistsAOTClassAndMethods(BuildTarget target)
|
||||
{
|
||||
|
||||
var gs = SettingsUtil.HybridCLRSettings;
|
||||
List<string> hotUpdateDllNames = SettingsUtil.HotUpdateAssemblyNamesExcludePreserved;
|
||||
|
||||
AssemblyReferenceDeepCollector hotUpdateCollector = new AssemblyReferenceDeepCollector(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotUpdateDllNames), hotUpdateDllNames);
|
||||
var hotUpdateAnalyzer = new Analyzer(new Analyzer.Options
|
||||
{
|
||||
MaxIterationCount = Math.Min(10, gs.maxGenericReferenceIteration),
|
||||
Collector = hotUpdateCollector,
|
||||
});
|
||||
|
||||
hotUpdateAnalyzer.Run();
|
||||
|
||||
|
||||
string aotDllDir = SettingsUtil.GetAssembliesPostIl2CppStripDir(target);
|
||||
List<string> aotAssemblyNames = Directory.Exists(aotDllDir) ?
|
||||
Directory.GetFiles(aotDllDir, "*.dll", SearchOption.TopDirectoryOnly).Select(Path.GetFileNameWithoutExtension).ToList()
|
||||
: new List<string>();
|
||||
if (aotAssemblyNames.Count == 0)
|
||||
{
|
||||
throw new Exception($"no aot assembly found. please run `HybridCLR/Generate/All` or `HybridCLR/Generate/AotDlls` to generate aot dlls before runing `HybridCLR/Generate/AOTGenericReference`");
|
||||
}
|
||||
AssemblyReferenceDeepCollector aotCollector = new AssemblyReferenceDeepCollector(MetaUtil.CreateAOTAssemblyResolver(target), aotAssemblyNames);
|
||||
var aotAnalyzer = new Analyzer(new Analyzer.Options
|
||||
{
|
||||
MaxIterationCount = Math.Min(10, gs.maxGenericReferenceIteration),
|
||||
Collector = aotCollector,
|
||||
ComputeAotAssembly = true,
|
||||
});
|
||||
|
||||
aotAnalyzer.Run();
|
||||
|
||||
var (resultTypes, resultMethods) = ExcludeExistAOTGenericTypeAndMethodss(hotUpdateAnalyzer.AotGenericTypes.ToList(), hotUpdateAnalyzer.AotGenericMethods.ToList(), aotAnalyzer.AotGenericTypes.ToList(), aotAnalyzer.AotGenericMethods.ToList());
|
||||
var writer = new GenericReferenceWriter();
|
||||
writer.Write(resultTypes, resultMethods, $"{Application.dataPath}/{gs.outputAOTGenericReferenceFile}");
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
|
||||
private static (List<GenericClass>, List<GenericMethod>) ExcludeExistAOTGenericTypeAndMethodss(List<GenericClass> hotUpdateTypes, List<GenericMethod> hotUpdateMethods, List<GenericClass> aotTypes, List<GenericMethod> aotMethods)
|
||||
{
|
||||
var types = new List<GenericClass>();
|
||||
|
||||
var typeSig2Type = hotUpdateTypes.ToDictionary(t => t.Type.DefinitionAssembly.Name + ":" + t.ToTypeSig(), t => t);
|
||||
foreach (var t in aotTypes)
|
||||
{
|
||||
string key = t.Type.DefinitionAssembly.Name + ":" + t.ToTypeSig();
|
||||
if (typeSig2Type.TryGetValue(key, out var removedType))
|
||||
{
|
||||
typeSig2Type.Remove(key);
|
||||
Debug.Log($"remove AOT type:{removedType.ToTypeSig()} ");
|
||||
}
|
||||
}
|
||||
|
||||
var methodSig2Method = hotUpdateMethods.ToDictionary(m => m.Method.DeclaringType.DefinitionAssembly.Name + ":" + m.ToMethodSpec().ToString(), m => m);
|
||||
foreach (var m in aotMethods)
|
||||
{
|
||||
string key = m.Method.DeclaringType.DefinitionAssembly.Name + ":" + m.ToMethodSpec().ToString();
|
||||
if (methodSig2Method.TryGetValue(key, out var removedMethod))
|
||||
{
|
||||
methodSig2Method.Remove(key);
|
||||
Debug.Log($"remove AOT method:{removedMethod.ToMethodSpec()} ");
|
||||
}
|
||||
}
|
||||
|
||||
return (typeSig2Type.Values.ToList(), methodSig2Method.Values.ToList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using HybridCLR.Editor.ABI;
|
||||
using HybridCLR.Editor.Meta;
|
||||
using HybridCLR.Editor.MethodBridge;
|
||||
using HybridCLR.Editor.ReversePInvokeWrap;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -30,29 +31,30 @@ namespace HybridCLR.Editor.Commands
|
||||
Directory.Delete(il2cppBuildCachePath, true);
|
||||
}
|
||||
|
||||
private static void GenerateMethodBridgeCppFile(Analyzer analyzer, string outputFile)
|
||||
private static void GenerateMethodBridgeCppFile(IReadOnlyCollection<GenericMethod> genericMethods, List<RawReversePInvokeMethodInfo> reversePInvokeMethods, string outputFile)
|
||||
{
|
||||
string templateCode = File.ReadAllText(outputFile, Encoding.UTF8);
|
||||
var g = new Generator(new Generator.Options()
|
||||
{
|
||||
TemplateCode = templateCode,
|
||||
OutputFile = outputFile,
|
||||
GenericMethods = analyzer.GenericMethods,
|
||||
GenericMethods = genericMethods,
|
||||
ReversePInvokeMethods = reversePInvokeMethods,
|
||||
Development = EditorUserBuildSettings.development,
|
||||
});
|
||||
|
||||
g.PrepareMethods();
|
||||
g.Generate();
|
||||
Debug.LogFormat("[MethodBridgeGeneratorCommand] output:{0}", outputFile);
|
||||
}
|
||||
|
||||
[MenuItem("HybridCLR/Generate/MethodBridge", priority = 101)]
|
||||
public static void CompileAndGenerateMethodBridge()
|
||||
[MenuItem("HybridCLR/Generate/MethodBridgeAndReversePInvokeWrapper", priority = 101)]
|
||||
public static void GenerateMethodBridgeAndReversePInvokeWrapper()
|
||||
{
|
||||
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
|
||||
GenerateMethodBridge(target);
|
||||
GenerateMethodBridgeAndReversePInvokeWrapper(target);
|
||||
}
|
||||
|
||||
public static void GenerateMethodBridge(BuildTarget target)
|
||||
public static void GenerateMethodBridgeAndReversePInvokeWrapper(BuildTarget target)
|
||||
{
|
||||
string aotDllDir = SettingsUtil.GetAssembliesPostIl2CppStripDir(target);
|
||||
List<string> aotAssemblyNames = Directory.Exists(aotDllDir) ?
|
||||
@@ -62,18 +64,25 @@ namespace HybridCLR.Editor.Commands
|
||||
{
|
||||
throw new Exception($"no aot assembly found. please run `HybridCLR/Generate/All` or `HybridCLR/Generate/AotDlls` to generate aot dlls before runing `HybridCLR/Generate/MethodBridge`");
|
||||
}
|
||||
using (AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateAOTAssemblyResolver(target), aotAssemblyNames))
|
||||
{
|
||||
var analyzer = new Analyzer(new Analyzer.Options
|
||||
{
|
||||
MaxIterationCount = Math.Min(20, SettingsUtil.HybridCLRSettings.maxMethodBridgeGenericIteration),
|
||||
Collector = collector,
|
||||
});
|
||||
AssemblyReferenceDeepCollector collector = new AssemblyReferenceDeepCollector(MetaUtil.CreateAOTAssemblyResolver(target), aotAssemblyNames);
|
||||
|
||||
analyzer.Run();
|
||||
string outputFile = $"{SettingsUtil.GeneratedCppDir}/MethodBridge.cpp";
|
||||
GenerateMethodBridgeCppFile(analyzer, outputFile);
|
||||
}
|
||||
var methodBridgeAnalyzer = new Analyzer(new Analyzer.Options
|
||||
{
|
||||
MaxIterationCount = Math.Min(20, SettingsUtil.HybridCLRSettings.maxMethodBridgeGenericIteration),
|
||||
Collector = collector,
|
||||
});
|
||||
|
||||
methodBridgeAnalyzer.Run();
|
||||
|
||||
List<string> hotUpdateDlls = SettingsUtil.HotUpdateAssemblyNamesExcludePreserved;
|
||||
var cache = new AssemblyCache(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotUpdateDlls));
|
||||
|
||||
var reversePInvokeAnalyzer = new ReversePInvokeWrap.Analyzer(cache, hotUpdateDlls);
|
||||
reversePInvokeAnalyzer.Run();
|
||||
|
||||
string outputFile = $"{SettingsUtil.GeneratedCppDir}/MethodBridge.cpp";
|
||||
|
||||
GenerateMethodBridgeCppFile(methodBridgeAnalyzer.GenericMethods, reversePInvokeAnalyzer.ReversePInvokeMethods, outputFile);
|
||||
|
||||
CleanIl2CppBuildCache();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
|
||||
namespace HybridCLR.Editor.Commands
|
||||
{
|
||||
@@ -15,6 +16,11 @@ namespace HybridCLR.Editor.Commands
|
||||
[MenuItem("HybridCLR/Generate/All", priority = 200)]
|
||||
public static void GenerateAll()
|
||||
{
|
||||
var installer = new Installer.InstallerController();
|
||||
if (!installer.HasInstalledHybridCLR())
|
||||
{
|
||||
throw new BuildFailedException($"You have not initialized HybridCLR, please install it via menu 'HybridCLR/Installer'");
|
||||
}
|
||||
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
|
||||
CompileDllCommand.CompileDll(target);
|
||||
Il2CppDefGeneratorCommand.GenerateIl2CppDef();
|
||||
@@ -26,8 +32,7 @@ namespace HybridCLR.Editor.Commands
|
||||
StripAOTDllCommand.GenerateStripedAOTDlls(target);
|
||||
|
||||
// 桥接函数生成依赖于AOT dll,必须保证已经build过,生成AOT dll
|
||||
MethodBridgeGeneratorCommand.GenerateMethodBridge(target);
|
||||
ReversePInvokeWrapperGeneratorCommand.GenerateReversePInvokeWrapper(target);
|
||||
MethodBridgeGeneratorCommand.GenerateMethodBridgeAndReversePInvokeWrapper(target);
|
||||
AOTReferenceGeneratorCommand.GenerateAOTGenericReference(target);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
using HybridCLR.Editor.ABI;
|
||||
using HybridCLR.Editor.Link;
|
||||
using HybridCLR.Editor.Meta;
|
||||
using HybridCLR.Editor.ReversePInvokeWrap;
|
||||
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
|
||||
{
|
||||
|
||||
[MenuItem("HybridCLR/Generate/ReversePInvokeWrapper", priority = 103)]
|
||||
|
||||
public static void CompileAndGenerateReversePInvokeWrapper()
|
||||
{
|
||||
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
|
||||
CompileDllCommand.CompileDll(target);
|
||||
GenerateReversePInvokeWrapper(target);
|
||||
}
|
||||
|
||||
public static void GenerateReversePInvokeWrapper(BuildTarget target)
|
||||
{
|
||||
List<string> hotUpdateDlls = SettingsUtil.HotUpdateAssemblyNamesExcludePreserved;
|
||||
using (var cache = new AssemblyCache(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotUpdateDlls)))
|
||||
{
|
||||
var analyzer = new ReversePInvokeWrap.Analyzer(cache, hotUpdateDlls);
|
||||
analyzer.Run();
|
||||
|
||||
string outputFile = $"{SettingsUtil.GeneratedCppDir}/ReversePInvokeMethodStub.cpp";
|
||||
|
||||
List<ABIReversePInvokeMethodInfo> methods = analyzer.BuildABIMethods();
|
||||
Debug.Log($"GenerateReversePInvokeWrapper. wraperCount:{methods.Sum(m => m.Count)} output:{outputFile}");
|
||||
var generator = new Generator();
|
||||
generator.Generate(methods, outputFile);
|
||||
Debug.LogFormat("[ReversePInvokeWrapperGeneratorCommand] output:{0}", outputFile);
|
||||
}
|
||||
MethodBridgeGeneratorCommand.CleanIl2CppBuildCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using HybridCLR.Editor.Installer;
|
||||
using HybridCLR.Editor.BuildProcessors;
|
||||
using HybridCLR.Editor.Installer;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -85,99 +86,109 @@ namespace HybridCLR.Editor.Commands
|
||||
bool oldOpenHarmonyProj = EditorUserBuildSettings.exportAsOpenHarmonyProject;
|
||||
#endif
|
||||
bool oldBuildScriptsOnly = EditorUserBuildSettings.buildScriptsOnly;
|
||||
EditorUserBuildSettings.buildScriptsOnly = true;
|
||||
|
||||
string location = GetLocationPathName(outputPath, target);
|
||||
string oldBuildLocation = EditorUserBuildSettings.GetBuildLocation(target);
|
||||
EditorUserBuildSettings.SetBuildLocation(target, location);
|
||||
|
||||
switch (target)
|
||||
try
|
||||
{
|
||||
case BuildTarget.StandaloneWindows:
|
||||
case BuildTarget.StandaloneWindows64:
|
||||
CheckSettings.DisableMethodBridgeDevelopmentFlagChecking = true;
|
||||
EditorUserBuildSettings.buildScriptsOnly = true;
|
||||
|
||||
string location = GetLocationPathName(outputPath, target);
|
||||
EditorUserBuildSettings.SetBuildLocation(target, location);
|
||||
|
||||
switch (target)
|
||||
{
|
||||
#if UNITY_EDITOR_WIN
|
||||
UnityEditor.WindowsStandalone.UserBuildSettings.createSolution = true;
|
||||
#endif
|
||||
case BuildTarget.StandaloneWindows:
|
||||
case BuildTarget.StandaloneWindows64:
|
||||
{
|
||||
#if UNITY_EDITOR_WIN
|
||||
UnityEditor.WindowsStandalone.UserBuildSettings.createSolution = true;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case BuildTarget.StandaloneOSX:
|
||||
{
|
||||
#if UNITY_EDITOR_OSX
|
||||
UnityEditor.OSXStandalone.UserBuildSettings.createXcodeProject = true;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#if TUANJIE_2022_3_OR_NEWER
|
||||
case BuildTarget.HMIAndroid:
|
||||
#endif
|
||||
case BuildTarget.Android:
|
||||
{
|
||||
EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
|
||||
break;
|
||||
}
|
||||
#if TUANJIE_2022_3_OR_NEWER
|
||||
case BuildTarget.OpenHarmony:
|
||||
{
|
||||
EditorUserBuildSettings.exportAsOpenHarmonyProject = true;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
case BuildTarget.StandaloneOSX:
|
||||
|
||||
Debug.Log($"GenerateStripedAOTDlls build option:{buildOptions}");
|
||||
|
||||
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions()
|
||||
{
|
||||
#if UNITY_EDITOR_OSX
|
||||
UnityEditor.OSXStandalone.UserBuildSettings.createXcodeProject = true;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#if TUANJIE_2022_3_OR_NEWER
|
||||
case BuildTarget.HMIAndroid:
|
||||
#endif
|
||||
case BuildTarget.Android:
|
||||
scenes = EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray(),
|
||||
locationPathName = location,
|
||||
options = buildOptions,
|
||||
target = target,
|
||||
targetGroup = BuildPipeline.GetBuildTargetGroup(target),
|
||||
};
|
||||
|
||||
var report = BuildPipeline.BuildPlayer(buildPlayerOptions);
|
||||
|
||||
|
||||
|
||||
if (report.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded)
|
||||
{
|
||||
EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
|
||||
break;
|
||||
throw new Exception("GenerateStripedAOTDlls failed");
|
||||
}
|
||||
#if TUANJIE_2022_3_OR_NEWER
|
||||
case BuildTarget.OpenHarmony:
|
||||
{
|
||||
EditorUserBuildSettings.exportAsOpenHarmonyProject = true;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Debug.Log($"GenerateStripedAOTDlls build option:{buildOptions}");
|
||||
|
||||
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions()
|
||||
finally
|
||||
{
|
||||
scenes = EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray(),
|
||||
locationPathName = location,
|
||||
options = buildOptions,
|
||||
target = target,
|
||||
targetGroup = BuildPipeline.GetBuildTargetGroup(target),
|
||||
};
|
||||
CheckSettings.DisableMethodBridgeDevelopmentFlagChecking = false;
|
||||
EditorUserBuildSettings.buildScriptsOnly = oldBuildScriptsOnly;
|
||||
EditorUserBuildSettings.SetBuildLocation(target, oldBuildLocation);
|
||||
|
||||
var report = BuildPipeline.BuildPlayer(buildPlayerOptions);
|
||||
|
||||
EditorUserBuildSettings.buildScriptsOnly = oldBuildScriptsOnly;
|
||||
EditorUserBuildSettings.SetBuildLocation(target, oldBuildLocation);
|
||||
|
||||
switch (target)
|
||||
{
|
||||
case BuildTarget.StandaloneWindows:
|
||||
case BuildTarget.StandaloneWindows64:
|
||||
switch (target)
|
||||
{
|
||||
case BuildTarget.StandaloneWindows:
|
||||
case BuildTarget.StandaloneWindows64:
|
||||
{
|
||||
#if UNITY_EDITOR_WIN
|
||||
UnityEditor.WindowsStandalone.UserBuildSettings.createSolution = oldCreateSolution;
|
||||
UnityEditor.WindowsStandalone.UserBuildSettings.createSolution = oldCreateSolution;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case BuildTarget.StandaloneOSX:
|
||||
case BuildTarget.StandaloneOSX:
|
||||
{
|
||||
#if UNITY_EDITOR_OSX
|
||||
UnityEditor.OSXStandalone.UserBuildSettings.createXcodeProject = oldCreateSolution;
|
||||
UnityEditor.OSXStandalone.UserBuildSettings.createXcodeProject = oldCreateSolution;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
#if TUANJIE_2022_3_OR_NEWER
|
||||
case BuildTarget.HMIAndroid:
|
||||
case BuildTarget.HMIAndroid:
|
||||
#endif
|
||||
case BuildTarget.Android:
|
||||
{
|
||||
EditorUserBuildSettings.exportAsGoogleAndroidProject = oldExportAndroidProj;
|
||||
break;
|
||||
}
|
||||
case BuildTarget.Android:
|
||||
{
|
||||
EditorUserBuildSettings.exportAsGoogleAndroidProject = oldExportAndroidProj;
|
||||
break;
|
||||
}
|
||||
#if TUANJIE_2022_3_OR_NEWER
|
||||
case BuildTarget.OpenHarmony:
|
||||
{
|
||||
EditorUserBuildSettings.exportAsOpenHarmonyProject = oldOpenHarmonyProj;
|
||||
break;
|
||||
}
|
||||
case BuildTarget.OpenHarmony:
|
||||
{
|
||||
EditorUserBuildSettings.exportAsOpenHarmonyProject = oldOpenHarmonyProj;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (report.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded)
|
||||
{
|
||||
throw new Exception("GenerateStripedAOTDlls failed");
|
||||
}
|
||||
}
|
||||
Debug.Log($"GenerateStripedAOTDlls target:{target} path:{outputPath}");
|
||||
}
|
||||
|
||||
@@ -52,7 +52,14 @@ namespace HybridCLR.Editor.Il2CppDef
|
||||
|
||||
lines.Add($"#define HYBRIDCLR_UNITY_VERSION {majorVer}{minorVer1.ToString("D2")}{minorVer2.ToString("D2")}");
|
||||
lines.Add($"#define HYBRIDCLR_UNITY_{majorVer} 1");
|
||||
for (int ver = 2019; ver <= 2024; ver++)
|
||||
for (int ver = 2019; ver <= 2023; ver++)
|
||||
{
|
||||
if (majorVer >= ver)
|
||||
{
|
||||
lines.Add($"#define HYBRIDCLR_UNITY_{ver}_OR_NEW 1");
|
||||
}
|
||||
}
|
||||
for (int ver = 6000; ver <= 6100; ver++)
|
||||
{
|
||||
if (majorVer >= ver)
|
||||
{
|
||||
|
||||
@@ -122,10 +122,12 @@ namespace HybridCLR.Editor.Installer
|
||||
{
|
||||
switch(majorVersion)
|
||||
{
|
||||
case 2019: return $"2019.4.0";
|
||||
case 2020: return $"2020.3.0";
|
||||
case 2021: return $"2021.3.0";
|
||||
case 2022: return $"2022.3.0";
|
||||
case 2019: return "2019.4.0";
|
||||
case 2020: return "2020.3.0";
|
||||
case 2021: return "2021.3.0";
|
||||
case 2022: return "2022.3.0";
|
||||
case 2023: return "2023.2.0";
|
||||
case 6000: return "6000.0.0";
|
||||
default: return $"2020.3.0";
|
||||
}
|
||||
}
|
||||
@@ -144,7 +146,8 @@ namespace HybridCLR.Editor.Installer
|
||||
{
|
||||
return CompatibleType.Incompatible;
|
||||
}
|
||||
if ((version.major == 2019 && version.minor1 < 4) || (version.major >= 2020 && version.minor1 < 3))
|
||||
if ((version.major == 2019 && version.minor1 < 4)
|
||||
|| (version.major >= 2020 && version.major <= 2022 && version.minor1 < 3))
|
||||
{
|
||||
return CompatibleType.MaybeIncompatible;
|
||||
}
|
||||
|
||||
+16
-14
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
||||
using dnlib.DotNet;
|
||||
using HybridCLR.Editor.Meta;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using IAssemblyResolver = HybridCLR.Editor.Meta.IAssemblyResolver;
|
||||
|
||||
namespace HybridCLR.Editor.Link
|
||||
@@ -22,26 +23,27 @@ namespace HybridCLR.Editor.Link
|
||||
|
||||
public HashSet<TypeRef> CollectRefs(List<string> rootAssemblies)
|
||||
{
|
||||
using (var assCollector = new AssemblyCache(_resolver))
|
||||
{
|
||||
var rootAssemblyNames = new HashSet<string>(rootAssemblies);
|
||||
var assCollector = new AssemblyCache(_resolver);
|
||||
var rootAssemblyNames = new HashSet<string>(rootAssemblies);
|
||||
|
||||
var typeRefs = new HashSet<TypeRef>(TypeEqualityComparer.Instance);
|
||||
foreach (var rootAss in rootAssemblies)
|
||||
var typeRefs = new HashSet<TypeRef>(TypeEqualityComparer.Instance);
|
||||
foreach (var rootAss in rootAssemblies)
|
||||
{
|
||||
var dnAss = assCollector.LoadModule(rootAss, false);
|
||||
foreach (var type in dnAss.GetTypeRefs())
|
||||
{
|
||||
var dnAss = assCollector.LoadModule(rootAss, false);
|
||||
foreach (var type in dnAss.GetTypeRefs())
|
||||
if (type.DefinitionAssembly == null)
|
||||
{
|
||||
if (!rootAssemblyNames.Contains(type.DefinitionAssembly.Name.ToString()))
|
||||
{
|
||||
typeRefs.Add(type);
|
||||
}
|
||||
Debug.LogWarning($"assembly:{dnAss.Name} TypeRef {type.FullName} has no DefinitionAssembly");
|
||||
continue;
|
||||
}
|
||||
if (!rootAssemblyNames.Contains(type.DefinitionAssembly.Name.ToString()))
|
||||
{
|
||||
typeRefs.Add(type);
|
||||
}
|
||||
}
|
||||
|
||||
assCollector.Dispose();
|
||||
return typeRefs;
|
||||
}
|
||||
return typeRefs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,12 @@ namespace HybridCLR.Editor.Link
|
||||
assTypeNames.Sort(string.CompareOrdinal);
|
||||
foreach(var typeName in assTypeNames)
|
||||
{
|
||||
#if UNITY_2023_1_OR_NEWER
|
||||
if (typeName == "UnityEngine.Debug")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
writer.WriteStartElement("type");
|
||||
writer.WriteAttributeString("fullname", typeName);
|
||||
writer.WriteAttributeString("preserve", "all");
|
||||
|
||||
@@ -8,12 +8,11 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace HybridCLR.Editor.Meta
|
||||
{
|
||||
public abstract class AssemblyCacheBase : IDisposable
|
||||
public abstract class AssemblyCacheBase
|
||||
{
|
||||
private readonly IAssemblyResolver _assemblyPathResolver;
|
||||
private readonly ModuleContext _modCtx;
|
||||
private readonly AssemblyResolver _asmResolver;
|
||||
private bool disposedValue;
|
||||
private bool _loadedNetstandard;
|
||||
|
||||
|
||||
@@ -96,28 +95,5 @@ namespace HybridCLR.Editor.Meta
|
||||
_loadedModulesIncludeNetstandard.Add(mod);
|
||||
return mod;
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
foreach (var mod in _loadedModulesIncludeNetstandard)
|
||||
{
|
||||
mod.Dispose();
|
||||
}
|
||||
_loadedModulesIncludeNetstandard.Clear();
|
||||
LoadedModules.Clear();
|
||||
}
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using dnlib.DotNet;
|
||||
using HybridCLR.Editor.ABI;
|
||||
using HybridCLR.Editor.Meta;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using dnlib.DotNet;
|
||||
using HybridCLR.Editor.ABI;
|
||||
using HybridCLR.Editor.Meta;
|
||||
using HybridCLR.Editor.ReversePInvokeWrap;
|
||||
using HybridCLR.Editor.Template;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -13,6 +14,8 @@ using System.Threading.Tasks;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using TypeInfo = HybridCLR.Editor.ABI.TypeInfo;
|
||||
using CallingConvention = System.Runtime.InteropServices.CallingConvention;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace HybridCLR.Editor.MethodBridge
|
||||
{
|
||||
@@ -25,14 +28,22 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
public string OutputFile { get; set; }
|
||||
|
||||
public IReadOnlyCollection<GenericMethod> GenericMethods { get; set; }
|
||||
|
||||
public List<RawReversePInvokeMethodInfo> ReversePInvokeMethods { get; set; }
|
||||
|
||||
public bool Development { get; set; }
|
||||
}
|
||||
|
||||
private readonly List<GenericMethod> _genericMethods;
|
||||
|
||||
private readonly List<RawReversePInvokeMethodInfo> _originalReversePInvokeMethods;
|
||||
|
||||
private readonly string _templateCode;
|
||||
|
||||
private readonly string _outputFile;
|
||||
|
||||
private readonly bool _development;
|
||||
|
||||
private readonly TypeCreator _typeCreator;
|
||||
|
||||
private readonly HashSet<MethodDesc> _managed2nativeMethodSet = new HashSet<MethodDesc>();
|
||||
@@ -41,15 +52,19 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
|
||||
private readonly HashSet<MethodDesc> _adjustThunkMethodSet = new HashSet<MethodDesc>();
|
||||
|
||||
private List<ABIReversePInvokeMethodInfo> _reversePInvokeMethods;
|
||||
|
||||
public Generator(Options options)
|
||||
{
|
||||
List<(GenericMethod, string)> genericMethodInfo = options.GenericMethods.Select(m => (m, m.ToString())).ToList();
|
||||
genericMethodInfo.Sort((a, b) => string.CompareOrdinal(a.Item2, b.Item2));
|
||||
_genericMethods = genericMethodInfo.Select(m => m.Item1).ToList();
|
||||
_originalReversePInvokeMethods = options.ReversePInvokeMethods;
|
||||
|
||||
_templateCode = options.TemplateCode;
|
||||
_outputFile = options.OutputFile;
|
||||
_typeCreator = new TypeCreator();
|
||||
_development = options.Development;
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, TypeInfo> _sig2Types = new Dictionary<string, TypeInfo>();
|
||||
@@ -167,12 +182,23 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
}
|
||||
}
|
||||
|
||||
public void PrepareMethods()
|
||||
private void PrepareMethodBridges()
|
||||
{
|
||||
foreach(var method in _genericMethods)
|
||||
foreach (var method in _genericMethods)
|
||||
{
|
||||
ProcessMethod(method.Method, method.KlassInst, method.MethodInst);
|
||||
}
|
||||
foreach (var reversePInvokeMethod in _originalReversePInvokeMethods)
|
||||
{
|
||||
MethodDef method = reversePInvokeMethod.Method;
|
||||
ICorLibTypes corLibTypes = method.Module.CorLibTypes;
|
||||
|
||||
var returnType = MetaUtil.ToShareTypeSig(corLibTypes, method.ReturnType);
|
||||
var parameters = method.Parameters.Select(p => MetaUtil.ToShareTypeSig(corLibTypes, p.Type)).ToList();
|
||||
var sharedMethod = CreateMethodDesc(method, true, returnType, parameters);
|
||||
sharedMethod.Init();
|
||||
AddNative2ManagedMethod(sharedMethod);
|
||||
}
|
||||
}
|
||||
|
||||
static void CheckUnique(IEnumerable<string> names)
|
||||
@@ -288,7 +314,7 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
var sigBuf = new StringBuilder();
|
||||
foreach (var field in ati.fields)
|
||||
{
|
||||
sigBuf.Append(GetOrCalculateTypeInfoSignature(ToIsomorphicType(field)));
|
||||
sigBuf.Append("{" + GetOrCalculateTypeInfoSignature(ToIsomorphicType(field)) + "}");
|
||||
}
|
||||
return ati.signature = sigBuf.ToString();
|
||||
}
|
||||
@@ -370,11 +396,92 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
return methodMap.Values.ToList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static string MakeSignature(MethodDesc desc, CallingConvention CallingConventionention)
|
||||
{
|
||||
string convStr = ((char)('A' + (int)CallingConventionention - 1)).ToString();
|
||||
return $"{convStr}{desc.Sig}";
|
||||
}
|
||||
|
||||
private static CallingConvention GetCallingConvention(MethodDef method)
|
||||
{
|
||||
var monoPInvokeCallbackAttr = method.CustomAttributes.FirstOrDefault(ca => ca.AttributeType.Name == "MonoPInvokeCallbackAttribute");
|
||||
if (monoPInvokeCallbackAttr == null)
|
||||
{
|
||||
return CallingConvention.Winapi;
|
||||
}
|
||||
object delegateTypeSig = monoPInvokeCallbackAttr.ConstructorArguments[0].Value;
|
||||
|
||||
TypeDef delegateTypeDef;
|
||||
if (delegateTypeSig is ClassSig classSig)
|
||||
{
|
||||
delegateTypeDef = classSig.TypeDefOrRef.ResolveTypeDefThrow();
|
||||
}
|
||||
else if (delegateTypeSig is GenericInstSig genericInstSig)
|
||||
{
|
||||
delegateTypeDef = genericInstSig.GenericType.TypeDefOrRef.ResolveTypeDefThrow();
|
||||
}
|
||||
else
|
||||
{
|
||||
delegateTypeDef = null;
|
||||
}
|
||||
|
||||
if (delegateTypeDef == null)
|
||||
{
|
||||
throw new NotSupportedException($"Unsupported delegate type: {delegateTypeSig}");
|
||||
}
|
||||
var attr = delegateTypeDef.CustomAttributes.FirstOrDefault(ca => ca.AttributeType.FullName == "System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute");
|
||||
if (attr == null)
|
||||
{
|
||||
return CallingConvention.Winapi;
|
||||
}
|
||||
var conv = attr.ConstructorArguments[0].Value;
|
||||
return (CallingConvention)conv;
|
||||
}
|
||||
|
||||
private List<ABIReversePInvokeMethodInfo> BuildABIMethods(List<RawReversePInvokeMethodInfo> rawMethods)
|
||||
{
|
||||
var methodsBySig = new Dictionary<string, ABIReversePInvokeMethodInfo>();
|
||||
foreach (var method in rawMethods)
|
||||
{
|
||||
var sharedMethod = new MethodDesc
|
||||
{
|
||||
MethodDef = method.Method,
|
||||
ReturnInfo = new ReturnInfo { Type = _typeCreator.CreateTypeInfo(method.Method.ReturnType) },
|
||||
ParamInfos = method.Method.Parameters.Select(p => new ParamInfo { Type = _typeCreator.CreateTypeInfo(p.Type) }).ToList(),
|
||||
};
|
||||
sharedMethod.Init();
|
||||
sharedMethod = ToIsomorphicMethod(sharedMethod);
|
||||
|
||||
CallingConvention callingConv = GetCallingConvention(method.Method);
|
||||
string signature = MakeSignature(sharedMethod, callingConv);
|
||||
|
||||
if (!methodsBySig.TryGetValue(signature, out var arm))
|
||||
{
|
||||
arm = new ABIReversePInvokeMethodInfo()
|
||||
{
|
||||
Method = sharedMethod,
|
||||
Signature = signature,
|
||||
Count = 0,
|
||||
Callvention = callingConv,
|
||||
};
|
||||
methodsBySig.Add(signature, arm);
|
||||
}
|
||||
int preserveCount = method.GenerationAttribute != null ? (int)method.GenerationAttribute.ConstructorArguments[0].Value : 1;
|
||||
arm.Count += preserveCount;
|
||||
}
|
||||
var newMethods = methodsBySig.Values.ToList();
|
||||
newMethods.Sort((a, b) => string.CompareOrdinal(a.Signature, b.Signature));
|
||||
return newMethods;
|
||||
}
|
||||
|
||||
private void BuildOptimizedMethods()
|
||||
{
|
||||
_managed2NativeMethodList = ToUniqueOrderedList(_managed2NativeMethodList0);
|
||||
_native2ManagedMethodList = ToUniqueOrderedList(_native2ManagedMethodList0);
|
||||
_adjustThunkMethodList = ToUniqueOrderedList(_adjustThunkMethodList0);
|
||||
_reversePInvokeMethods = BuildABIMethods(_originalReversePInvokeMethods);
|
||||
}
|
||||
|
||||
private void OptimizationTypesAndMethods()
|
||||
@@ -389,7 +496,12 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
{
|
||||
var frr = new FileRegionReplace(_templateCode);
|
||||
|
||||
List<string> lines = new List<string>(20_0000);
|
||||
List<string> lines = new List<string>(20_0000)
|
||||
{
|
||||
"\n",
|
||||
$"// DEVELOPMENT={(_development ? 1 : 0)}",
|
||||
"\n"
|
||||
};
|
||||
|
||||
var classInfos = new List<ClassInfo>();
|
||||
var classTypeSet = new HashSet<TypeInfo>();
|
||||
@@ -424,6 +536,8 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
|
||||
GenerateAdjustThunkStub(_adjustThunkMethodList, lines);
|
||||
|
||||
GenerateReversePInvokeWrappers(_reversePInvokeMethods, lines);
|
||||
|
||||
frr.Replace("CODE", string.Join("\n", lines));
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(_outputFile));
|
||||
@@ -431,8 +545,69 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
frr.Commit(_outputFile);
|
||||
}
|
||||
|
||||
private static string GetIl2cppCallConventionName(CallingConvention conv)
|
||||
{
|
||||
switch (conv)
|
||||
{
|
||||
case 0:
|
||||
case CallingConvention.Winapi:
|
||||
return "DEFAULT_CALL";
|
||||
case CallingConvention.Cdecl:
|
||||
return "CDECL";
|
||||
case CallingConvention.StdCall:
|
||||
return "STDCALL";
|
||||
case CallingConvention.ThisCall:
|
||||
return "THISCALL";
|
||||
case CallingConvention.FastCall:
|
||||
return "FASTCALL";
|
||||
default:
|
||||
throw new NotSupportedException($"Unsupported CallingConvention {conv}");
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateReversePInvokeWrappers(List<ABIReversePInvokeMethodInfo> methods, List<string> lines)
|
||||
{
|
||||
int methodIndex = 0;
|
||||
var stubCodes = new List<string>();
|
||||
foreach (var methodInfo in methods)
|
||||
{
|
||||
MethodDesc method = methodInfo.Method;
|
||||
string il2cppCallConventionName = GetIl2cppCallConventionName(methodInfo.Callvention);
|
||||
string paramDeclaringListWithoutMethodInfoStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()} __arg{p.Index}"));
|
||||
string paramNameListWithoutMethodInfoStr = string.Join(", ", method.ParamInfos.Select(p => $"__arg{p.Index}").Concat(new string[] { "method" }));
|
||||
string paramTypeListWithMethodInfoStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()}").Concat(new string[] { "const MethodInfo*" }));
|
||||
string methodTypeDef = $"typedef {method.ReturnInfo.Type.GetTypeName()} (*Callback)({paramTypeListWithMethodInfoStr})";
|
||||
for (int i = 0; i < methodInfo.Count; i++, methodIndex++)
|
||||
{
|
||||
lines.Add($@"
|
||||
{method.ReturnInfo.Type.GetTypeName()} {il2cppCallConventionName} __ReversePInvokeMethod_{methodIndex}({paramDeclaringListWithoutMethodInfoStr})
|
||||
{{
|
||||
il2cpp::vm::ScopedThreadAttacher _vmThreadHelper;
|
||||
const MethodInfo* method = InterpreterModule::GetMethodInfoByReversePInvokeWrapperIndex({methodIndex});
|
||||
{methodTypeDef};
|
||||
{(method.ReturnInfo.IsVoid ? "" : "return ")}((Callback)(method->methodPointerCallByInterp))({paramNameListWithoutMethodInfoStr});
|
||||
}}
|
||||
");
|
||||
stubCodes.Add($"\t{{\"{methodInfo.Signature}\", (Il2CppMethodPointer)__ReversePInvokeMethod_{methodIndex}}},");
|
||||
}
|
||||
Debug.Log($"[ReversePInvokeWrap.Generator] method:{method.MethodDef} wrapperCount:{methodInfo.Count}");
|
||||
}
|
||||
|
||||
lines.Add(@"
|
||||
const ReversePInvokeMethodData hybridclr::interpreter::g_reversePInvokeMethodStub[]
|
||||
{
|
||||
");
|
||||
lines.AddRange(stubCodes);
|
||||
|
||||
lines.Add(@"
|
||||
{nullptr, nullptr},
|
||||
};
|
||||
");
|
||||
}
|
||||
|
||||
public void Generate()
|
||||
{
|
||||
PrepareMethodBridges();
|
||||
CollectTypesAndMethods();
|
||||
OptimizationTypesAndMethods();
|
||||
GenerateCode();
|
||||
@@ -678,7 +853,7 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
|
||||
public void GenerateStructureSignatureStub(List<TypeInfo> types, List<string> lines)
|
||||
{
|
||||
lines.Add("FullName2Signature hybridclr::interpreter::g_fullName2SignatureStub[] = {");
|
||||
lines.Add("const FullName2Signature hybridclr::interpreter::g_fullName2SignatureStub[] = {");
|
||||
foreach (var type in types)
|
||||
{
|
||||
TypeInfo isoType = ToIsomorphicType(type);
|
||||
@@ -691,7 +866,7 @@ namespace HybridCLR.Editor.MethodBridge
|
||||
public void GenerateManaged2NativeStub(List<MethodDesc> methods, List<string> lines)
|
||||
{
|
||||
lines.Add($@"
|
||||
Managed2NativeMethodInfo hybridclr::interpreter::g_managed2nativeStub[] =
|
||||
const Managed2NativeMethodInfo hybridclr::interpreter::g_managed2nativeStub[] =
|
||||
{{
|
||||
");
|
||||
|
||||
@@ -707,7 +882,7 @@ Managed2NativeMethodInfo hybridclr::interpreter::g_managed2nativeStub[] =
|
||||
public void GenerateNative2ManagedStub(List<MethodDesc> methods, List<string> lines)
|
||||
{
|
||||
lines.Add($@"
|
||||
Native2ManagedMethodInfo hybridclr::interpreter::g_native2managedStub[] =
|
||||
const Native2ManagedMethodInfo hybridclr::interpreter::g_native2managedStub[] =
|
||||
{{
|
||||
");
|
||||
|
||||
@@ -723,7 +898,7 @@ Native2ManagedMethodInfo hybridclr::interpreter::g_native2managedStub[] =
|
||||
public void GenerateAdjustThunkStub(List<MethodDesc> methods, List<string> lines)
|
||||
{
|
||||
lines.Add($@"
|
||||
NativeAdjustThunkMethodInfo hybridclr::interpreter::g_adjustThunkStub[] =
|
||||
const NativeAdjustThunkMethodInfo hybridclr::interpreter::g_adjustThunkStub[] =
|
||||
{{
|
||||
");
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CallingConvention = System.Runtime.InteropServices.CallingConvention;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor.ReversePInvokeWrap
|
||||
@@ -21,7 +22,11 @@ namespace HybridCLR.Editor.ReversePInvokeWrap
|
||||
{
|
||||
public MethodDesc Method { get; set; }
|
||||
|
||||
public CallingConvention Callvention { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public string Signature { get; set; }
|
||||
}
|
||||
|
||||
public class Analyzer
|
||||
@@ -31,6 +36,8 @@ namespace HybridCLR.Editor.ReversePInvokeWrap
|
||||
|
||||
private readonly List<RawReversePInvokeMethodInfo> _reversePInvokeMethods = new List<RawReversePInvokeMethodInfo>();
|
||||
|
||||
public List<RawReversePInvokeMethodInfo> ReversePInvokeMethods => _reversePInvokeMethods;
|
||||
|
||||
public Analyzer(AssemblyCache cache, List<string> assemblyNames)
|
||||
{
|
||||
foreach (var assemblyName in assemblyNames)
|
||||
@@ -70,36 +77,6 @@ namespace HybridCLR.Editor.ReversePInvokeWrap
|
||||
}
|
||||
}
|
||||
|
||||
public List<ABIReversePInvokeMethodInfo> BuildABIMethods()
|
||||
{
|
||||
var methodsBySig = new Dictionary<string, ABIReversePInvokeMethodInfo>();
|
||||
var typeCreator = new TypeCreator();
|
||||
foreach(var method in _reversePInvokeMethods)
|
||||
{
|
||||
MethodDesc desc = new MethodDesc
|
||||
{
|
||||
MethodDef = method.Method,
|
||||
ReturnInfo = new ReturnInfo { Type = typeCreator.CreateTypeInfo(method.Method.ReturnType)},
|
||||
ParamInfos = method.Method.Parameters.Select(p => new ParamInfo { Type = typeCreator.CreateTypeInfo(p.Type)}).ToList(),
|
||||
};
|
||||
desc.Init();
|
||||
if (!methodsBySig.TryGetValue(desc.Sig, out var arm))
|
||||
{
|
||||
arm = new ABIReversePInvokeMethodInfo()
|
||||
{
|
||||
Method = desc,
|
||||
Count = 0,
|
||||
};
|
||||
methodsBySig.Add(desc.Sig, arm);
|
||||
}
|
||||
int preserveCount = method.GenerationAttribute != null ? (int)method.GenerationAttribute.ConstructorArguments[0].Value : 1;
|
||||
arm.Count += preserveCount;
|
||||
}
|
||||
var methods = methodsBySig.Values.ToList();
|
||||
methods.Sort((a, b) => String.CompareOrdinal(a.Method.Sig, b.Method.Sig));
|
||||
return methods;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
CollectReversePInvokeMethods();
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
using HybridCLR.Editor.ABI;
|
||||
using HybridCLR.Editor.Template;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor.ReversePInvokeWrap
|
||||
{
|
||||
public class Generator
|
||||
{
|
||||
public void Generate(List<ABIReversePInvokeMethodInfo> methods, string outputFile)
|
||||
{
|
||||
string template = File.ReadAllText(outputFile, Encoding.UTF8);
|
||||
var frr = new FileRegionReplace(template);
|
||||
var codes = new List<string>();
|
||||
|
||||
int methodIndex = 0;
|
||||
var stubCodes = new List<string>();
|
||||
foreach(var methodInfo in methods)
|
||||
{
|
||||
MethodDesc method = methodInfo.Method;
|
||||
string paramDeclaringListWithoutMethodInfoStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()} __arg{p.Index}"));
|
||||
string paramNameListWithoutMethodInfoStr = string.Join(", ", method.ParamInfos.Select(p => $"__arg{p.Index}").Concat(new string[] { "method" }));
|
||||
string paramTypeListWithMethodInfoStr = string.Join(", ", method.ParamInfos.Select(p => $"{p.Type.GetTypeName()}").Concat(new string[] { "const MethodInfo*" }));
|
||||
string methodTypeDef = $"typedef {method.ReturnInfo.Type.GetTypeName()} (*Callback)({paramTypeListWithMethodInfoStr})";
|
||||
for (int i = 0; i < methodInfo.Count; i++, methodIndex++)
|
||||
{
|
||||
codes.Add($@"
|
||||
{method.ReturnInfo.Type.GetTypeName()} __ReversePInvokeMethod_{methodIndex}({paramDeclaringListWithoutMethodInfoStr})
|
||||
{{
|
||||
il2cpp::vm::ScopedThreadAttacher _vmThreadHelper;
|
||||
const MethodInfo* method = MetadataModule::GetMethodInfoByReversePInvokeWrapperIndex({methodIndex});
|
||||
{methodTypeDef};
|
||||
{(method.ReturnInfo.IsVoid ? "" : "return ")}((Callback)(method->methodPointerCallByInterp))({paramNameListWithoutMethodInfoStr});
|
||||
}}
|
||||
");
|
||||
stubCodes.Add($"\t\t{{\"{method.Sig}\", (Il2CppMethodPointer)__ReversePInvokeMethod_{methodIndex}}},\n");
|
||||
}
|
||||
Debug.Log($"[ReversePInvokeWrap.Generator] method:{method.MethodDef} wrapperCount:{methodInfo.Count}");
|
||||
}
|
||||
|
||||
codes.Add(@"
|
||||
ReversePInvokeMethodData g_reversePInvokeMethodStub[]
|
||||
{
|
||||
");
|
||||
codes.AddRange(stubCodes);
|
||||
|
||||
codes.Add(@"
|
||||
{nullptr, nullptr},
|
||||
};
|
||||
");
|
||||
|
||||
frr.Replace("CODE", string.Join("", codes));
|
||||
frr.Commit(outputFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d883f182f206fa4db31f4085ce0ecdc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -73,7 +73,7 @@ namespace HybridCLR.Editor.Settings
|
||||
content.tooltip = "点击访问 HybridCLR 官方文档";
|
||||
if (GUI.Button(rect, content, buttonStyle))
|
||||
{
|
||||
Application.OpenURL("https://focus-creative-games.github.io/hybridclr/");
|
||||
Application.OpenURL("https://hybridclr.doc.code-philosophy.com/");
|
||||
}
|
||||
#endregion
|
||||
#region 绘制 Preset
|
||||
|
||||
Binary file not shown.
@@ -11,11 +11,11 @@
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
HybridCLR is a **almost perfect** full-platform native c# hot update solution for Unity with complete features, zero cost, high performance, and low memory**.
|
||||
HybridCLR is a nearly perfect Unity full-platform native c# hot update solution with complete features, zero cost, high performance, and low memory.
|
||||
|
||||
HybridCLR expands the ability of il2cpp, making it change from pure [AOT](https://en.wikipedia.org/wiki/Ahead-of-time_compilation) runtime to 'AOT+Interpreter' hybrid runtime, and then natively supports dynamic loading of assembly , so that the games packaged based on il2cpp backend can be executed not only on the Android platform, but also on IOS, Consoles and other platforms that limit JIT efficiently in **AOT+interpreter** hybrid mode, completely supporting hot updates from the bottom layer.
|
||||
HybridCLR expands the il2cpp runtime code, changing it from a pure [AOT](https://en.wikipedia.org/wiki/Ahead-of-time_compilation) runtime to an AOT+Interpreter hybrid runtime, and then natively supports dynamic loading of assemblies. Hot updates are fully supported from the bottom up. Games using HybridCLR technology can run efficiently not only on the Android platform, but also on IOS, Consoles, WebGL and other platforms supported by il2cpp.
|
||||
|
||||
HybridCLR not only supports the traditional fully interpreted execution mode, but also pioneered [Differential Hybrid Execution](https://hybridclr.doc.code-philosophy.com/en/docs/business/differentialhybridexecution) technique. That is, you can add, delete, or modify the AOT dll at will, and intelligently make the changed or newly added classes and functions run in interpreter mode, but the unchanged classes and functions run in AOT mode, so that the running performance of the hot-updated game logic basically reaches the original AOT level.
|
||||
Due to HybridCLR's good support for the ECMA-335 specification and its high compatibility with the Unity development workflow, the Unity project can almost seamlessly obtain the ability to hot update C# code after accessing HybridCLR. Developers do not need to change their daily development habits and Require. For the first time, HybridCLR has reduced the engineering difficulty of the Unity platform's full-platform code hot update solution to almost zero.
|
||||
|
||||
Welcome to embrace modern native C# hot update technology! ! !
|
||||
|
||||
@@ -25,67 +25,65 @@ Welcome to embrace modern native C# hot update technology! ! !
|
||||
- [Quickstart](https://hybridclr.doc.code-philosophy.com/en/docs/beginner/quickstart)
|
||||
- [Release Log](./RELEASELOG.md)
|
||||
|
||||
|
||||
## Features
|
||||
|
||||
- Features complete. A nearly complete implementation of the [ECMA-335 specification](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/), with only a very small number of [unsupported features](https://hybridclr.doc.code-philosophy.com/en/docs/basic/notsupportedfeatures).
|
||||
- Zero learning and use costs. HybridCLR enhances the pure AOT runtime into a complete runtime, making hot update code work seamlessly with AOT code. The script class and the AOT class are in the same runtime, and you can freely write codes such as inheritance, reflection, and multi-threading (volatile, ThreadStatic, Task, async). No need to write any special code, no code generation, almost unlimited.
|
||||
- Efficient execution. Implemented an extremely efficient register interpreter, all indicators are significantly better than other hot update schemes. [Performance Test Report](https://hybridclr.doc.code-philosophy.com/en/docs/basic/performance)
|
||||
- Memory efficient. The classes defined in the hot update script occupy the same memory space as ordinary c# classes, which is far superior to other hot update solutions. [Memory and GC](https://hybridclr.doc.code-philosophy.com/en/docs/basic/memory)
|
||||
- Due to the perfect support for generics, libraries that are not compatible with il2cpp due to AOT generics issues can now run perfectly under il2cpp
|
||||
- Support some features not supported by il2cpp, such as __makeref, __reftype, __refvalue directives
|
||||
- [Differential Hybrid Execution](https://hybridclr.doc.code-philosophy.com/en/docs/business/differentialhybridexecution)
|
||||
- A nearly complete implementation of the [ECMA-335 specification](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/), with only a very small number of [unsupported features](https ://hybridclr.doc.code-philosophy.com/docs/basic/notsupportedfeatures).
|
||||
- Zero learning and usage costs. For most developers, there are almost no limits to writing code. Hot update code works seamlessly with AOT code, and you can write code such as inheritance, **generics**, and **reflection** at will. No need to write any additional special code, no code generation
|
||||
- Fully supports multi-threading, including but not limited to volatile, ThreadStatic, async Task and other related functions and features. This is not supported by any other hot update solution
|
||||
- Almost fully compatible with Unity workflow. Including but not limited to supporting hot update **MonoBehaviour**, ScriptableObject, **DOTS** technology, the hot update script mounted on the resource can be instantiated correctly, which is not supported by all other hot update solutions.
|
||||
- Efficient execution. An extremely efficient register interpreter is implemented, and all indicators are significantly better than other hot update schemes. [Performance test report](https://hybridclr.doc.code-philosophy.com/docs/basic/performance)
|
||||
- Memory efficient. The classes defined in the hot update script occupy the same memory space as ordinary C# classes, which is far superior to other hot update solutions. [Memory Usage Report](https://hybridclr.doc.code-philosophy.com/docs/basic/memory)
|
||||
- Supports MonoPInvokeCallback, which can interact well with native code or other languages such as lua, javascript, and python
|
||||
- Supports some features not supported by il2cpp, such as __makeref, __reftype, and __refvalue instructions
|
||||
- Supports the original **Differential Hybrid Execution (DHE)** differential hybrid execution technology, that is, the AOT dll can be added, deleted or modified at will, and the unmodified functions will be intelligently run in AOT mode, and the changed or added functions will be run in interpreter mode. Run, so that the running performance of the hot updated game logic can basically reach the level of native AOT.
|
||||
- Supports **Hot Reload** technology, which can 100% uninstall the assembly
|
||||
- Supports modern dll encryption technology to effectively ensure code security
|
||||
|
||||
## Supported Unity Versions And Platforms
|
||||
|
||||
- Supports 2019.4.x, 2020.3.x, 2021.3.x, 2022.3.x, 2023.2.x、**6000.x.y** versions
|
||||
- Supports all il2cpp supported platforms
|
||||
- Supports Tuanjie Engine and Harmony Platform
|
||||
|
||||
## Working Principle
|
||||
|
||||
HybridCLR is inspired by mono's [mixed mode execution](https://www.mono-project.com/news/2017/11/13/mono-interpreter/) technology, and provides additional AOT runtimes such as unity's il2cpp The interpreter module is provided to transform them from pure AOT runtime to "AOT + Interpreter" hybrid operation mode.
|
||||
HybridCLR is inspired by mono's [mixed mode execution](https://www.mono-project.com/news/2017/11/13/mono-interpreter/) technology and provides additional AOT runtimes such as unity's il2cpp Interpreter modules are provided to transform them from pure AOT runtime to "AOT + Interpreter" hybrid runtime.
|
||||
|
||||

|
||||
|
||||
More specifically, HybridCLR does the following:
|
||||
|
||||
- Implemented an efficient metadata (dll) parsing library
|
||||
- Modified the metadata management module to realize the dynamic registration of metadata
|
||||
- The metadata management module has been transformed to realize dynamic registration of metadata.
|
||||
- Implemented a compiler from IL instruction set to custom register instruction set
|
||||
- Implemented an efficient register interpreter
|
||||
- Provide a large number of instinct functions to improve the performance of the interpreter
|
||||
|
||||
## The Difference From Other C# Hot-Update Solution
|
||||
|
||||
HybridCLR is a native c# hot update solution. In layman's terms, il2cpp is equivalent to the aot module of mono, and HybridCLR is equivalent to the interpreter module of mono, and the combination of the two becomes a complete mono. HybridCLR makes il2cpp a full-featured runtime, natively (that is, through System.Reflection.Assembly.Load) supports dynamic loading of dlls, thereby supporting hot updates of the ios platform.
|
||||
|
||||
Just because HybridCLR is implemented at the native runtime level, the types of the hot update part and the AOT part of the main project are completely equivalent and seamlessly unified. You can call, inherit, reflect, and multi-thread at will, without generating code or writing adapters.
|
||||
|
||||
Other hot update solutions are independent vm, and the relationship with il2cpp is essentially equivalent to the relationship of embedding lua in mono. Therefore, the type system is not uniform. In order to allow the hot update type to inherit some AOT types, an adapter needs to be written, and the type in the interpreter cannot be recognized by the type system of the main project. Incomplete features, troublesome development, and low operating efficiency.
|
||||
|
||||
## Supported Versions And Platforms
|
||||
|
||||
- Support 2019.4.x, 2020.3.x, 2021.3.x, 2022.3.x full series of LTS versions. The `2023.2.0ax` version is also supported, but not released to the public.
|
||||
- Supports all il2cpp supported platforms
|
||||
- Provides a large number of additional instinct functions to improve interpreter performance
|
||||
|
||||
## Stability Status
|
||||
|
||||
HybridCLR has been widely verified as a very efficient and stable solution for hot update of Unity.
|
||||
HybridCLR has been widely proven to be a very efficient and stable Unity hot update solution.
|
||||
|
||||
The official versions of **extremely stable** 1.x, 2.x, and 3.x are currently released, which are sufficient to meet the stability requirements of large and medium-sized commercial projects.
|
||||
At present, at least thousands of commercial game projects have been integrated, and hundreds of them have been launched on both ends. The online projects include MMORPG, heavy card, heavy tower defense and other games. **Most top game companies** (such as Tencent and NetEase) are already using HybridCLR.
|
||||
Currently, the **extremely stable** official versions of 1.x-5.x have been released, which are sufficient to meet the stability requirements of large and medium-sized commercial projects.
|
||||
Currently, thousands of commercial game projects have been connected, and hundreds of them have been launched on both ends. The online projects include MMORPG, heavy card, heavy tower defense and other games. **The vast majority of leading game companies** (such as Tencent and NetEase) are already using HybridCLR.
|
||||
|
||||
You can read the [game projects in top game companies](https://hybridclr.doc.code-philosophy.com/en/docs/other/businesscase) those are using HybridCLR and has been launched.
|
||||
You can view the [list of projects] (https://hybridclr.doc.code-philosophy.com/docs/other/businesscase) that use HybridCLR and have been launched in leading companies we know.
|
||||
|
||||
## Support And Contact
|
||||
## Support & Contact
|
||||
|
||||
- Official 1 group: 651188171 (full)
|
||||
- Novice QQ group 1: 428404198 (full)
|
||||
- Novice QQ group 2: **680274677 (recommended)**
|
||||
- discord channel [https://discord.gg/BATfNfJnm2](https://discord.gg/BATfNfJnm2)
|
||||
- Official group 1: 651188171 (full)
|
||||
- Novice group 1: 428404198 (full)
|
||||
- Newbie Group 2: **680274677 (recommended)**
|
||||
- discord channel https://discord.gg/BATfNfJnm2
|
||||
- Business cooperation email: business#code-philosophy.com
|
||||
- [Commercial Support](https://hybridclr.doc.code-philosophy.com/en/docs/business/intro)
|
||||
- [Business support](https://hybridclr.doc.code-philosophy.com/docs/business/intro)
|
||||
|
||||
## About The Author
|
||||
## About Author
|
||||
|
||||
**walon** : Founder of **Code Philosophy (code philosophy)**
|
||||
**walon**: **Code Philosophy** founder
|
||||
|
||||
Graduated from the Department of Physics of Tsinghua University, won the CMO gold medal in 2006, a member of the National Mathematical Olympiad Training Team, and was recommended to Tsinghua University for basic courses. Focus on game technology, good at developing architecture and basic technical facilities.
|
||||
Graduated from the Physics Department of Tsinghua University, won the CMO gold medal in 2006, was a member of the National Mathematical Olympiad training team, and was recommended to Tsinghua Basic Science Class. Focus on game technology, good at developing architecture and basic technical facilities.
|
||||
|
||||
## License
|
||||
|
||||
HybridCLR is licensed under the [MIT](https://github.com/focus-creative-games/hybridclr/blob/main/LICENSE) license
|
||||
HybridCLR is licensed under the [MIT](https://github.com/focus-creative-games/hybridclr/blob/main/LICENSE) license
|
||||
+22
-25
@@ -10,11 +10,11 @@
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
HybridCLR是一个**特性完整、零成本、高性能、低内存**的**近乎完美**的Unity全平台原生c#热更方案。
|
||||
HybridCLR是一个**特性完整、零成本、高性能、低内存**的**近乎完美**的Unity全平台原生c#热更新解决方案。
|
||||
|
||||
HybridCLR扩充了il2cpp的代码,使它由纯[AOT](https://en.wikipedia.org/wiki/Ahead-of-time_compilation) runtime变成‘AOT+Interpreter’ 混合runtime,进而原生支持动态加载assembly,使得基于il2cpp backend打包的游戏不仅能在Android平台,也能在IOS、Consoles等限制了JIT的平台上高效地以**AOT+interpreter**混合模式执行,从底层彻底支持了热更新。
|
||||
HybridCLR扩充了il2cpp运行时代码,使它由纯[AOT](https://en.wikipedia.org/wiki/Ahead-of-time_compilation) runtime变成AOT+Interpreter 混合runtime,进而原生支持动态加载assembly,从底层彻底支持了热更新。使用HybridCLR技术的游戏不仅能在Android平台,也能在IOS、Consoles、WebGL等所有il2cpp支持的平台上高效运行。
|
||||
|
||||
HybridCLR不仅支持传统的全解释执行模式,还开创性地实现了 [Differential Hybrid Execution(差分混合执行技术)](https://hybridclr.doc.code-philosophy.com/docs/business/differentialhybridexecution) 差分混合执行技术。即可以对AOT dll任意增删改,会智能地让变化或者新增的类和函数以interpreter模式运行,但未改动的类和函数以AOT方式运行,让热更新的游戏逻辑的运行性能基本达到原生AOT的水平。
|
||||
由于HybridCLR对ECMA-335规范 的良好支持以及对Unity开发工作流的高度兼容,Unity项目在接入HybridCLR后,可以几乎无缝地获得C#代码热更新的能力,开发者不需要改变日常开发习惯和要求。HybridCLR首次实现了将Unity平台的全平台代码热更新方案的工程难度降到几乎为零的水平。
|
||||
|
||||
欢迎拥抱现代原生C#热更新技术 !!!
|
||||
|
||||
@@ -22,17 +22,28 @@ HybridCLR不仅支持传统的全解释执行模式,还开创性地实现了 [
|
||||
|
||||
- [官方文档](https://hybridclr.doc.code-philosophy.com/docs/intro)
|
||||
- [快速上手](https://hybridclr.doc.code-philosophy.com/docs/beginner/quickstart)
|
||||
- [发布日志](./RELEASELOG.md)
|
||||
- [商业项目案例](https://hybridclr.doc.code-philosophy.com/docs/other/businesscase)
|
||||
|
||||
|
||||
## 特性
|
||||
|
||||
- 特性完整。 近乎完整实现了[ECMA-335规范](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/),只有极少量的[不支持的特性](https://hybridclr.doc.code-philosophy.com/docs/basic/notsupportedfeatures)。
|
||||
- 零学习和使用成本。 HybridCLR将纯AOT runtime增强为完整的runtime,使得热更新代码与AOT代码无缝工作。脚本类与AOT类在同一个运行时内,可以随意写继承、反射、多线程(volatile、ThreadStatic、Task、async)之类的代码。不需要额外写任何特殊代码、没有代码生成,几乎没有限制。
|
||||
- 近乎完整实现了[ECMA-335规范](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/),只有极少量的[不支持的特性](https://hybridclr.doc.code-philosophy.com/docs/basic/notsupportedfeatures)。
|
||||
- 零学习和使用成本。对绝大多数开发者来说写代码近乎没有限制。 热更新代码与AOT代码无缝工作,可以随意写继承、**泛型**、**反射**之类的代码。不需要额外写任何特殊代码、没有代码生成
|
||||
- 完全支持多线程,包含但不限于 volatile、ThreadStatic、async Task等相关功能和特性。这是其他所有热更新方案都不支持的
|
||||
- 几乎完全兼容Unity的工作流。包括且不限于支持热更新**MonoBehaviour**、ScriptableObject、**DOTS**技术,资源上挂载的热更新脚本可以正确实例化,这是其他所有热更新方案都不支持的
|
||||
- 执行高效。实现了一个极其高效的寄存器解释器,所有指标都大幅优于其他热更新方案。[性能测试报告](https://hybridclr.doc.code-philosophy.com/docs/basic/performance)
|
||||
- 内存高效。 热更新脚本中定义的类跟普通c#类占用一样的内存空间,远优于其他热更新方案。[内存与GC](https://hybridclr.doc.code-philosophy.com/docs/basic/memory)
|
||||
- 由于对泛型的完美支持,使得因为AOT泛型问题跟il2cpp不兼容的库现在能够完美地在il2cpp下运行
|
||||
- 内存高效。 热更新脚本中定义的类跟普通c#类占用一样的内存空间,远优于其他热更新方案。[内存占用报告](https://hybridclr.doc.code-philosophy.com/docs/basic/memory)
|
||||
- 支持MonoPInvokeCallback,可以与native代码或者其他语言如lua、javascript、python良好交互
|
||||
- 支持一些il2cpp不支持的特性,如__makeref、 __reftype、__refvalue指令
|
||||
- [Differential Hybrid Execution(差分混合执行技术)](https://hybridclr.doc.code-philosophy.com/docs/business/differentialhybridexecution)
|
||||
- 支持独创的 **Differential Hybrid Execution(DHE)** 差分混合执行技术,即可以对AOT dll任意增删改,会智能地让未改动的函数以AOT方式运行,变化或者新增的函数以interpreter模式运行,让热更新的游戏逻辑的运行性能基本达到原生AOT的水平
|
||||
- 支持 **热重载** 技术,可以100%卸载程序集
|
||||
- 支持现代的dll加密技术,有效保障代码安全
|
||||
|
||||
## 支持的版本与平台
|
||||
|
||||
- 支持2019.4.x、2020.3.x、2021.3.x、2022.3.x、2023.2.x、**6000.x.y**全系列LTS版本
|
||||
- 支持所有il2cpp支持的平台
|
||||
- 支持团结引擎和鸿蒙平台
|
||||
|
||||
## 工作原理
|
||||
|
||||
@@ -48,29 +59,15 @@ HybridCLR从mono的 [mixed mode execution](https://www.mono-project.com/news/201
|
||||
- 实现了一个高效的寄存器解释器
|
||||
- 额外提供大量的instinct函数,提升解释器性能
|
||||
|
||||
## 与其他流行的c#热更新方案的区别
|
||||
|
||||
HybridCLR是原生的c#热更新方案。通俗地说,il2cpp相当于mono的aot模块,HybridCLR相当于mono的interpreter模块,两者合一成为完整mono。HybridCLR使得il2cpp变成一个全功能的runtime,原生(即通过System.Reflection.Assembly.Load)支持动态加载dll,从而支持ios平台的热更新。
|
||||
|
||||
正因为HybridCLR是原生runtime级别实现,热更新部分的类型与主工程AOT部分类型是完全等价并且无缝统一的。可以随意调用、继承、反射、多线程,不需要生成代码或者写适配器。
|
||||
|
||||
其他热更新方案则是独立vm,与il2cpp的关系本质上相当于mono中嵌入lua的关系。因此类型系统不统一,为了让热更新类型能够继承AOT部分类型,需要写适配器,并且解释器中的类型不能为主工程的类型系统所识别。特性不完整、开发麻烦、运行效率低下。
|
||||
|
||||
## 支持的版本与平台
|
||||
|
||||
- 支持2019.4.x、2020.3.x、2021.3.x、2022.3.x全系列LTS版本。`2023.2.0ax`版本也已支持,但未对外发布。
|
||||
- 支持所有il2cpp支持的平台
|
||||
|
||||
## 稳定性状况
|
||||
|
||||
HybridCLR已经被广泛验证是非常高效、稳定的Unity热更新解决方案。
|
||||
|
||||
当前发布了**极其稳定**的1.x、2.x、3.x正式版本,足以满足大中型商业项目的稳定性要求。
|
||||
目前至少有上千个商业游戏项目完成接入,其中有几百款已经双端上线,上线的项目中包括MMORPG、重度卡牌、重度塔防之类的游戏。**绝大多数头部游戏公司**(如腾讯、网易)都已经在使用HybridCLR。
|
||||
当前发布了**极其稳定**的1.x-5.x正式版本,足以满足大中型商业项目的稳定性要求。
|
||||
目前有数千个商业游戏项目完成接入,其中有几百款已经双端上线,上线的项目中包括MMORPG、重度卡牌、重度塔防之类的游戏。**绝大多数头部游戏公司**(如腾讯、网易)都已经在使用HybridCLR。
|
||||
|
||||
可查看我们已知的头部公司中使用HybridCLR并且已经上线的[项目列表](https://hybridclr.doc.code-philosophy.com/docs/other/businesscase)。
|
||||
|
||||
|
||||
## 支持与联系
|
||||
|
||||
- 官方1群:651188171(满)
|
||||
|
||||
@@ -1,5 +1,89 @@
|
||||
# 发布日志
|
||||
|
||||
## 6.2.0
|
||||
|
||||
发布日期 2024.7.1.
|
||||
|
||||
### Runtime
|
||||
|
||||
- [merge] 合并2021.3.27f1-2021.3.40f1版本改动
|
||||
- [opt] 优化metadata元数据内存,内存占用减少了20-25%
|
||||
- [opt] 优化枚举类型调用GetHashCode的实现,不再产生GC
|
||||
|
||||
## 6.1.0
|
||||
|
||||
发布日期 2024.6.17.
|
||||
|
||||
### Runtime
|
||||
|
||||
- [merge] 合并2022.3.23f1-2022.3.33f1版本改动,修复对2022.3.33版本不兼容的问题
|
||||
- [new] 支持2022.3.33版本新增支持的函数返回值Attribute
|
||||
- [fix] 修复解释部分FieldInfo调用GetFieldMarshaledSizeForField时崩溃的bug
|
||||
|
||||
### Editor
|
||||
|
||||
- [fix] 升级dnlib版本,修复ModuleMD保存dll时将未加Assembly限定的mscorlib程序集中类型的程序集设置为当前程序集的严重bug
|
||||
- [fix] 修复`Generate/LinkXml`生成的link.xml中对UnityEngine.Debug preserve all导致在Unity 2023及更高版本的iOS、visionOS等平台上出现Undefined symbols for architecture arm64: "CheckApplicationIntegrity(IntegrityCheckLevel)" 编译错误的问题。此bug由Unity引起,我们通过在生成link.xml时忽略UnityEngine.Debug类来临时解决这个问题
|
||||
|
||||
## 6.0.0
|
||||
|
||||
发布日期 2024.6.11.
|
||||
|
||||
### Runtime
|
||||
|
||||
- [new] 支持Unity 6000.x.y及Unity 2023.2.x版本
|
||||
- [refactor] 合并ReversePInvokeMethodStub到MethodBridge,同时将MetadataModule中ReversePInvoke相关代码移到InterpreterModule
|
||||
- [new] 支持MonoPInvokeCallback函数的参数或返回类型为struct类型
|
||||
|
||||
### Editor
|
||||
|
||||
- [new] 支持Unity 6000.x.y及Unity 2023.2.x版本
|
||||
- [new] 支持MonoPInvokeCallback函数的参数或返回类型为struct类型
|
||||
- [new] 新增GeneratedAOTGenericReferenceExcludeExistsAOTClassAndMethods,计算热更新引用的AOT泛型类型和函数时排除掉AOT中已经存在的泛型和函数,最终生成更精准的补充元数据程序集列表
|
||||
- [fix] 修复在某些不支持visionOS的Unity版本上CopyStrippedAOTAssemblies类有编译错误的bug
|
||||
- [fix] 修复计算 MonoPInvokeCallback的CallingConvention时,如果delegate在其他程序集中定义,会被错误当作Winapi,导致wrapper签名计算错误的bug
|
||||
- [fix] PatchScriptingAssemblyList.cs在Unity 2023+版本webgl平台的编译错误
|
||||
- [fix] 修复计算Native2Manager桥接函数未考虑到MonoPInvokeCallback函数,导致从lua或者其他语言调用c#热更新函数有时候会出现UnsupportedNative2ManagedMethod的bug
|
||||
- [refactor] 合并ReversePInvokeMethodStub到MethodBridge,同时将MetadataModule中ReversePInvoke相关代码移到InterpreterModule
|
||||
- [opt] 打包时检查生成桥接函数时的development选项与当前development选项一致。`Generate/All`之后切换development选项再打包,将会产生严重的崩溃
|
||||
- [opt] `Generate/All`在生成之前检查是否已经安装HybridCLR
|
||||
|
||||
|
||||
## 5.4.1
|
||||
|
||||
发布日期 2024.5.30.
|
||||
|
||||
### Editor
|
||||
|
||||
- [new] 支持visionOS平台
|
||||
- [fix][**严重**] 修复计算 MonoPInvokeCallback的CallingConvention时,如果delegate在其他程序集中定义,会被错误当作Winapi,导致wrapper签名计算错误的bug
|
||||
- [fix] 修复tvOS平台使用了错误的Unity-iPhone.xcodeproj路径导致找不到project.pbxproj的bug
|
||||
|
||||
|
||||
## 5.4.0
|
||||
|
||||
发布日期 2024.5.20.
|
||||
|
||||
### Runtime
|
||||
|
||||
- [new] ReversePInvoke支持CallingConvention
|
||||
- [fix] 修复当参数个数为0时,由于argIdxs未赋值,calli的argBasePtr=argIdx[0]导致函数栈帧指向错误位置的bug
|
||||
- [fix] 修复MetadataModule::GetReversePInvokeWrappe中ComputeSignature可能死锁的bug
|
||||
- [fix] 修复AOT基类虚函数implements热更新interface函数时,虚函数调用使用CallInterpVirtual导致运行异常的bug
|
||||
- [fix] 修复Transform中 PREFIX1前缀指令的子指令有部分缺失并且未按指令号排序的问题
|
||||
- [fix] 修复no.{x} prefix指令长3字节,但Transform中错误当作2字节处理的bug
|
||||
- [fix] 修复unaligned.{x} prefix指令长3字节,但Transform中错误当作2字节处理的bug
|
||||
- [opt] 删除 Interpreter_Execute中不必要的INIT_CLASS操作,因为PREPARE_NEW_FRAME_FROM_NATIVE中一定会检查
|
||||
- [opt] 不再缓存非泛型函数的MethodBody,优化内存
|
||||
- [opt] **优化补充元数据内存**,大约节省了2.8倍元数据dll大小的内存
|
||||
- [refactor] Image::_rawImage字段的类型由RawImage改为RawImage*
|
||||
|
||||
### Editor
|
||||
|
||||
- [new] ReversePInvoke支持CallingConvention
|
||||
- [fix] 修复计算struct等价性时,将struct平铺展开计算等价,在某些平台并不适用的bug。例如 struct A { uint8_t x; A2 y; } struct A2 { uint8_t x; int32_t y;}; 跟 struct B {uint8_t x; uint8_t y; int32_t z;} 在x86_64 abi下并不等价
|
||||
- [fix] 修复当Append xcode项目到现存的xcode项目时,第1次会导致'Run Script'命令被重复追加,从第2次起将会找不到--external-lib-il2-cpp而打印错误日志的bug
|
||||
|
||||
## 5.3.0
|
||||
|
||||
发布日期 2024.4.22.
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "com.code-philosophy.hybridclr",
|
||||
"version": "5.3.0",
|
||||
"version": "6.2.0",
|
||||
"displayName": "HybridCLR",
|
||||
"description": "HybridCLR is a fully featured, zero-cost, high-performance, low-memory solution for Unity's all-platform native c# hotupdate.",
|
||||
"category": "Runtime",
|
||||
|
||||
Reference in New Issue
Block a user