Skip to content

Commit

Permalink
[unity]il2cpp添加纯反射的选项,并增加相应的测试
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Dec 27, 2024
1 parent cc6189a commit 2efa36e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/unity_unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 19 additions & 2 deletions unity/Assets/core/upm/Editor/Src/Generator/IL2Cpp/FileExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private static void IterateAllType(Type type, HashSet<Type> 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());

Expand Down Expand Up @@ -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<ValueTypeInfo>();
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<string>() {
"Puerts.BindingAttribute",
Expand Down
31 changes: 29 additions & 2 deletions unity/Assets/core/upm/Editor/Src/Generator/IL2Cpp/UnityMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,25 @@ 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();
GenerateLinkXML();
GenerateCppPlugin();
Puerts.Editor.Generator.UnityMenu.GenRegisterInfo();
}


[MenuItem(Puerts.Editor.Generator.UnityMenu.PUERTS_MENU_PREFIX + "/Generate/il2cpp c file", false, 6)]
public static void GenerateCppPlugin()
Expand All @@ -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;
Expand Down Expand Up @@ -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()
{
Expand Down
16 changes: 15 additions & 1 deletion unity/cli/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,28 @@ 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`);

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 = 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);
}

0 comments on commit 2efa36e

Please sign in to comment.