From 2efa36ea2cbd019436676b0627335d771f2bd89a Mon Sep 17 00:00:00 2001 From: johnche Date: Fri, 27 Dec 2024 11:02:38 +0800 Subject: [PATCH] =?UTF-8?q?[unity]il2cpp=E6=B7=BB=E5=8A=A0=E7=BA=AF?= =?UTF-8?q?=E5=8F=8D=E5=B0=84=E7=9A=84=E9=80=89=E9=A1=B9=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=9B=B8=E5=BA=94=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/unity_unittest.yml | 4 ++- .../Src/Generator/IL2Cpp/FileExporter.cs | 21 +++++++++++-- .../Editor/Src/Generator/IL2Cpp/UnityMenu.cs | 31 +++++++++++++++++-- unity/cli/test.mjs | 16 +++++++++- 4 files changed, 66 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unity_unittest.yml b/.github/workflows/unity_unittest.yml index 3e2320c64a..d917e84df3 100644 --- a/.github/workflows/unity_unittest.yml +++ b/.github/workflows/unity_unittest.yml @@ -47,8 +47,10 @@ jobs: cd unity/test/unity echo "testresult in v1" cat log1.txt | grep "Failed\|Passed" - echo "testresult in v2" + echo "testresult in v2(reflection)" cat log2.txt | grep "Failed\|Passed" + echo "testresult in v2" + cat log3.txt | grep "Failed\|Passed" # unittest-osx-unity: # runs-on: macos-latest diff --git a/unity/Assets/core/upm/Editor/Src/Generator/IL2Cpp/FileExporter.cs b/unity/Assets/core/upm/Editor/Src/Generator/IL2Cpp/FileExporter.cs index 7f3e4ded40..5f9eefaab3 100644 --- a/unity/Assets/core/upm/Editor/Src/Generator/IL2Cpp/FileExporter.cs +++ b/unity/Assets/core/upm/Editor/Src/Generator/IL2Cpp/FileExporter.cs @@ -187,7 +187,7 @@ private static void IterateAllType(Type type, HashSet allTypes) } } - public static void GenCPPWrap(string saveTo, bool onlyConfigure = false) + public static void GenCPPWrap(string saveTo, bool onlyConfigure = false, bool noWrapper = false) { Utils.SetFilters(Puerts.Configure.GetFilters()); @@ -308,7 +308,24 @@ from type in assembly.GetTypes() var genWrapperMethod = methodToWrap; var genWrapperField = fieldToWrapper; - if (onlyConfigure) + if (noWrapper) + { + genWrapperCtor = new ConstructorInfo[] { }; + genWrapperMethod = new MethodInfo[] { }; + genWrapperField = new FieldInfo[] { }; + + valueTypeInfos = new List(); + foreach (var type in delegateUsedTypes) + { + IterateAllValueType(type, valueTypeInfos); + } + + valueTypeInfos = valueTypeInfos + .GroupBy(s => s.Signature) + .Select(s => s.FirstOrDefault()) + .ToList(); + } + else if (onlyConfigure) { var configure = Puerts.Configure.GetConfigureByTags(new List() { "Puerts.BindingAttribute", diff --git a/unity/Assets/core/upm/Editor/Src/Generator/IL2Cpp/UnityMenu.cs b/unity/Assets/core/upm/Editor/Src/Generator/IL2Cpp/UnityMenu.cs index 8bff801b74..13a4cea6b5 100644 --- a/unity/Assets/core/upm/Editor/Src/Generator/IL2Cpp/UnityMenu.cs +++ b/unity/Assets/core/upm/Editor/Src/Generator/IL2Cpp/UnityMenu.cs @@ -20,7 +20,17 @@ namespace PuertsIl2cpp.Editor namespace Generator { public class UnityMenu { - [MenuItem(Puerts.Editor.Generator.UnityMenu.PUERTS_MENU_PREFIX + "/Generate For xIl2cpp mode (all in one)", false, 2)] + [MenuItem(Puerts.Editor.Generator.UnityMenu.PUERTS_MENU_PREFIX + "/Generate For xIl2cpp mode (all in one without wrapper)", false, 2)] + public static void GenV2WithoutWrapper() + { + GenerateEmptyCppWrappers(); + GenerateExtensionMethodInfos(); + GenerateLinkXML(); + GenerateCppPlugin(); + Puerts.Editor.Generator.UnityMenu.GenRegisterInfo(); + } + + [MenuItem(Puerts.Editor.Generator.UnityMenu.PUERTS_MENU_PREFIX + "/Generate For xIl2cpp mode (all in one with full wrapper)", false, 3)] public static void GenV2() { GenerateCppWrappers(); GenerateExtensionMethodInfos(); @@ -28,6 +38,7 @@ public static void GenV2() { GenerateCppPlugin(); Puerts.Editor.Generator.UnityMenu.GenRegisterInfo(); } + [MenuItem(Puerts.Editor.Generator.UnityMenu.PUERTS_MENU_PREFIX + "/Generate/il2cpp c file", false, 6)] public static void GenerateCppPlugin() @@ -46,7 +57,7 @@ public static void GenerateCppPlugin() Debug.Log("finished! use " + (DateTime.Now - start).TotalMilliseconds + " ms Outputed to " + saveTo); } - [MenuItem(Puerts.Editor.Generator.UnityMenu.PUERTS_MENU_PREFIX + "/Generate/il2cpp wrapper bridge", false, 6)] + [MenuItem(Puerts.Editor.Generator.UnityMenu.PUERTS_MENU_PREFIX + "/Generate/il2cpp wrapper bridge(Full)", false, 6)] public static void GenerateCppWrappers() { var start = DateTime.Now; @@ -80,6 +91,22 @@ public static void GenerateCppWrappersInConfigure() Debug.Log("finished! use " + (DateTime.Now - start).TotalMilliseconds + " ms Outputed to " + saveTo); } + public static void GenerateEmptyCppWrappers() + { + var start = DateTime.Now; +#if CPP_OUTPUT_TO_NATIVE_SRC + var saveTo = Path.Combine(Application.dataPath, "core/upm/Plugins/puerts_il2cpp/"); +#elif PUERTS_CPP_OUTPUT_TO_UPM + var saveTo = Path.Combine(Path.GetFullPath("Packages/com.tencent.puerts.core/"), "Plugins/puerts_il2cpp/"); +#else + var saveTo = Path.Combine(Puerts.Configure.GetCodeOutputDirectory(), "Plugins/puerts_il2cpp/"); +#endif + + Directory.CreateDirectory(saveTo); + FileExporter.GenCPPWrap(saveTo, false, true); + Debug.Log("finished! use " + (DateTime.Now - start).TotalMilliseconds + " ms Outputed to " + saveTo); + } + [MenuItem(Puerts.Editor.Generator.UnityMenu.PUERTS_MENU_PREFIX + "/Generate/il2cpp ExtensionMethodInfos_Gen.cs", false, 6)] public static void GenerateExtensionMethodInfos() { diff --git a/unity/cli/test.mjs b/unity/cli/test.mjs index 6dc3db8f8c..9264fd3e13 100644 --- a/unity/cli/test.mjs +++ b/unity/cli/test.mjs @@ -268,6 +268,20 @@ export async function unityTest(cwd, unityPath) { -define:PUERTS_CPP_OUTPUT_TO_UPM -define:PUERTS_IL2CPP_OPTIMIZATION `); + + console.log('-------------------------Without Wrapper test-------------------------'); + execUnityEditor(`-executeMethod TestBuilder.GenV2WithoutWrapper`); + rm("-rf", `${cwd}/Library/ScriptAssemblies`); + + console.log("[Puer] Building testplayer for v2"); + mkdir("-p", `${cwd}/build/v2`); + execUnityEditor(`-executeMethod TestBuilder.BuildWindowsV2`); + console.log("[Puer] Running test in v2"); + const v2code_reflection = exec(`${cwd}/build/v2/Tester${exeSuffix} -batchmode -nographics -logFile ${cwd}/log2.txt`).code; + + assert.equal(0, v2code_reflection); + + console.log('-------------------------With Full Wrapper test-------------------------'); execUnityEditor(`-executeMethod TestBuilder.GenV2`); rm("-rf", `${cwd}/Library/ScriptAssemblies`); @@ -275,7 +289,7 @@ export async function unityTest(cwd, unityPath) { mkdir("-p", `${cwd}/build/v2`); execUnityEditor(`-executeMethod TestBuilder.BuildWindowsV2`); console.log("[Puer] Running test in v2"); - const v2code = exec(`${cwd}/build/v2/Tester${exeSuffix} -batchmode -nographics -logFile ${cwd}/log2.txt`).code; + const v2code = exec(`${cwd}/build/v2/Tester${exeSuffix} -batchmode -nographics -logFile ${cwd}/log3.txt`).code; assert.equal(0, v2code); }