[new] 新增菜单命令 `HybridCLR/Generate/AOTDlls` 快捷生成裁剪后的AOT dlls

main
walon 2022-12-16 11:03:03 +08:00
parent 00f94335c3
commit 0e04a66c91
4 changed files with 114 additions and 4 deletions

View File

@ -17,16 +17,18 @@ namespace HybridCLR.Editor.Commands
{
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
CompileDllCommand.CompileDll(target);
Il2CppDefGeneratorCommand.GenerateIl2CppDef();
// 这几个生成依赖HotUpdateDlls
LinkGeneratorCommand.GenerateLinkXml(target);
ReversePInvokeWrapperGeneratorCommand.GenerateReversePInvokeWrapper(target);
AOTReferenceGeneratorCommand.GenerateAOTGenericReference(target);
// 生成裁剪后的aot dll
StripAOTDllCommand.GenerateStripedAOTDlls(target, EditorUserBuildSettings.selectedBuildTargetGroup);
// 桥接函数生成依赖于AOT dll必须保证已经build过生成AOT dll
MethodBridgeGeneratorCommand.GenerateMethodBridge(target);
ReversePInvokeWrapperGeneratorCommand.GenerateReversePInvokeWrapper(target);
AOTReferenceGeneratorCommand.GenerateAOTGenericReference(target);
}
}
}

View File

@ -0,0 +1,97 @@
using HybridCLR.Editor.Installer;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;
namespace HybridCLR.Editor.Commands
{
public static class StripAOTDllCommand
{
[MenuItem("HybridCLR/Generate/AOTDlls", priority = 105)]
public static void GenerateStripedAOTDlls()
{
GenerateStripedAOTDlls(EditorUserBuildSettings.activeBuildTarget, EditorUserBuildSettings.selectedBuildTargetGroup);
}
private static string GetLocationPathName(string buildDir, BuildTarget target)
{
switch(target)
{
case BuildTarget.StandaloneWindows:
case BuildTarget.StandaloneWindows64: return $"{buildDir}/{target}";
case BuildTarget.StandaloneOSX: return buildDir;
case BuildTarget.iOS: return buildDir;
case BuildTarget.Android: return buildDir;
case BuildTarget.StandaloneLinux64: return buildDir;
default: return buildDir;
}
}
public static void GenerateStripedAOTDlls(BuildTarget target, BuildTargetGroup group)
{
string outputPath = $"{SettingsUtil.HybridCLRDataDir}/StrippedAOTDllsTempProj/{target}";
BashUtil.RemoveDir(outputPath);
var buildOptions = BuildOptions.BuildScriptsOnly;
bool oldExportAndroidProj = EditorUserBuildSettings.exportAsGoogleAndroidProject;
bool oldCreateSolutionWin = UnityEditor.WindowsStandalone.UserBuildSettings.createSolution;
bool oldBuildScriptsOnly = EditorUserBuildSettings.buildScriptsOnly;
EditorUserBuildSettings.buildScriptsOnly = true;
switch (target)
{
case BuildTarget.StandaloneWindows:
case BuildTarget.StandaloneWindows64:
{
UnityEditor.WindowsStandalone.UserBuildSettings.createSolution = true;
break;
}
case BuildTarget.Android:
{
EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
break;
}
}
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions()
{
scenes = EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray(),
locationPathName = GetLocationPathName(outputPath, target),
options = buildOptions,
target = target,
targetGroup = group,
};
var report = BuildPipeline.BuildPlayer(buildPlayerOptions);
EditorUserBuildSettings.buildScriptsOnly = oldBuildScriptsOnly;
switch (target)
{
case BuildTarget.StandaloneWindows:
case BuildTarget.StandaloneWindows64:
{
UnityEditor.WindowsStandalone.UserBuildSettings.createSolution = oldCreateSolutionWin;
break;
}
case BuildTarget.Android:
{
EditorUserBuildSettings.exportAsGoogleAndroidProject = oldExportAndroidProj;
break;
}
}
if (report.summary.result != UnityEditor.Build.Reporting.BuildResult.Succeeded)
{
Debug.LogError("GenerateStripedAOTDlls 失败");
return;
}
Debug.Log($"GenerateStripedAOTDlls target:{target} group:{group} path:{outputPath}");
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 21fb0a02f23185141a4a3df67fe61789
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,6 +1,6 @@
{
"name": "com.focus-creative-games.hybridclr_unity",
"version": "1.1.14",
"version": "1.1.15",
"displayName": "HybridCLR",
"description": "Unity package for HybridCLR. It includes editor and runtime scripts and assets for HybridCLR",
"category": "Runtime",