2023-10-07 21:59:48 +08:00
|
|
|
using HybridCLR.Editor.Installer;
|
2023-09-17 20:58:18 +08:00
|
|
|
using System;
|
2022-09-22 08:56:07 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using UnityEditor;
|
|
|
|
using UnityEditor.Build;
|
|
|
|
using UnityEditor.Build.Reporting;
|
|
|
|
using UnityEditor.UnityLinker;
|
|
|
|
using UnityEngine;
|
2024-05-20 11:44:38 +08:00
|
|
|
#if !UNITY_2021_1_OR_NEWER
|
|
|
|
using UnityEditor.Il2Cpp;
|
|
|
|
#endif
|
2022-09-22 08:56:07 +08:00
|
|
|
|
|
|
|
namespace HybridCLR.Editor.BuildProcessors
|
|
|
|
{
|
2023-10-07 21:59:48 +08:00
|
|
|
internal class CopyStrippedAOTAssemblies : IPostprocessBuildWithReport, IPreprocessBuildWithReport
|
2022-09-22 08:56:07 +08:00
|
|
|
#if !UNITY_2021_1_OR_NEWER
|
|
|
|
, IIl2CppProcessor
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
|
|
|
|
public int callbackOrder => 0;
|
|
|
|
|
|
|
|
#if UNITY_2021_1_OR_NEWER
|
|
|
|
public static string GetStripAssembliesDir2021(BuildTarget target)
|
|
|
|
{
|
|
|
|
string projectDir = SettingsUtil.ProjectDir;
|
2023-09-10 13:37:12 +08:00
|
|
|
switch (target)
|
|
|
|
{
|
|
|
|
case BuildTarget.StandaloneWindows:
|
|
|
|
case BuildTarget.StandaloneWindows64:
|
|
|
|
return $"{projectDir}/Library/Bee/artifacts/WinPlayerBuildProgram/ManagedStripped";
|
2023-09-17 20:58:18 +08:00
|
|
|
case BuildTarget.StandaloneLinux64:
|
|
|
|
return $"{projectDir}/Library/Bee/artifacts/LinuxPlayerBuildProgram/ManagedStripped";
|
2023-09-10 13:37:12 +08:00
|
|
|
case BuildTarget.Android:
|
|
|
|
return $"{projectDir}/Library/Bee/artifacts/Android/ManagedStripped";
|
|
|
|
case BuildTarget.iOS:
|
2024-05-29 14:48:05 +08:00
|
|
|
case BuildTarget.tvOS:
|
|
|
|
#if UNITY_2022_3_OR_NEWER
|
|
|
|
case BuildTarget.VisionOS:
|
|
|
|
#endif
|
2023-09-10 13:37:12 +08:00
|
|
|
return $"{projectDir}/Library/Bee/artifacts/iOS/ManagedStripped";
|
2024-05-29 14:48:05 +08:00
|
|
|
case BuildTarget.WebGL:
|
2023-09-10 13:37:12 +08:00
|
|
|
return $"{projectDir}/Library/Bee/artifacts/WebGL/ManagedStripped";
|
|
|
|
case BuildTarget.StandaloneOSX:
|
|
|
|
return $"{projectDir}/Library/Bee/artifacts/MacStandalonePlayerBuildProgram/ManagedStripped";
|
|
|
|
case BuildTarget.PS4:
|
|
|
|
return $"{projectDir}/Library/Bee/artifacts/PS4PlayerBuildProgram/ManagedStripped";
|
|
|
|
case BuildTarget.PS5:
|
|
|
|
return $"{projectDir}/Library/Bee/artifacts/PS5PlayerBuildProgram/ManagedStripped";
|
2024-04-08 22:25:48 +08:00
|
|
|
#if TUANJIE_2022_3_OR_NEWER
|
2024-01-03 17:30:28 +08:00
|
|
|
case BuildTarget.WeixinMiniGame:
|
|
|
|
return $"{projectDir}/Library/Bee/artifacts/WeixinMiniGame/ManagedStripped";
|
|
|
|
case BuildTarget.OpenHarmony:
|
|
|
|
return $"{projectDir}/Library/Bee/artifacts/OpenHarmonyPlayerBuildProgram/ManagedStripped";
|
|
|
|
#endif
|
2023-09-10 13:37:12 +08:00
|
|
|
default: return "";
|
|
|
|
}
|
2022-09-22 08:56:07 +08:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
private string GetStripAssembliesDir2020(BuildTarget target)
|
|
|
|
{
|
|
|
|
string subPath = target == BuildTarget.Android ?
|
|
|
|
"assets/bin/Data/Managed" :
|
|
|
|
"Data/Managed/";
|
|
|
|
return $"{SettingsUtil.ProjectDir}/Temp/StagingArea/{subPath}";
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnBeforeConvertRun(BuildReport report, Il2CppBuildPipelineData data)
|
2024-04-21 13:44:54 +08:00
|
|
|
{
|
2022-09-22 08:56:07 +08:00
|
|
|
// 此回调只在 2020中调用
|
2024-04-21 13:44:54 +08:00
|
|
|
BuildTarget target = report.summary.platform;
|
|
|
|
CopyStripDlls(GetStripAssembliesDir2020(target), target);
|
2022-09-22 08:56:07 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public static void CopyStripDlls(string srcStripDllPath, BuildTarget target)
|
|
|
|
{
|
2022-12-02 13:14:06 +08:00
|
|
|
if (!SettingsUtil.Enable)
|
|
|
|
{
|
|
|
|
Debug.Log($"[CopyStrippedAOTAssemblies] disabled");
|
|
|
|
return;
|
|
|
|
}
|
2022-09-22 08:56:07 +08:00
|
|
|
Debug.Log($"[CopyStrippedAOTAssemblies] CopyScripDlls. src:{srcStripDllPath} target:{target}");
|
|
|
|
|
|
|
|
var dstPath = SettingsUtil.GetAssembliesPostIl2CppStripDir(target);
|
|
|
|
|
|
|
|
Directory.CreateDirectory(dstPath);
|
|
|
|
|
|
|
|
foreach (var fileFullPath in Directory.GetFiles(srcStripDllPath, "*.dll"))
|
|
|
|
{
|
|
|
|
var file = Path.GetFileName(fileFullPath);
|
|
|
|
Debug.Log($"[CopyStrippedAOTAssemblies] copy strip dll {fileFullPath} ==> {dstPath}/{file}");
|
|
|
|
File.Copy($"{fileFullPath}", $"{dstPath}/{file}", true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnPostprocessBuild(BuildReport report)
|
|
|
|
{
|
2023-09-10 13:37:12 +08:00
|
|
|
#if UNITY_2021_1_OR_NEWER
|
2024-04-21 13:44:54 +08:00
|
|
|
BuildTarget target = report.summary.platform;
|
2023-09-10 13:37:12 +08:00
|
|
|
string srcStripDllPath = GetStripAssembliesDir2021(target);
|
|
|
|
if (!string.IsNullOrEmpty(srcStripDllPath) && Directory.Exists(srcStripDllPath))
|
|
|
|
{
|
|
|
|
CopyStripDlls(srcStripDllPath, target);
|
|
|
|
}
|
2022-09-22 08:56:07 +08:00
|
|
|
#endif
|
|
|
|
}
|
2023-10-07 21:59:48 +08:00
|
|
|
|
|
|
|
public void OnPreprocessBuild(BuildReport report)
|
|
|
|
{
|
2024-04-21 13:44:54 +08:00
|
|
|
BuildTarget target = report.summary.platform;
|
2023-10-07 21:59:48 +08:00
|
|
|
var dstPath = SettingsUtil.GetAssembliesPostIl2CppStripDir(target);
|
|
|
|
BashUtil.RecreateDir(dstPath);
|
|
|
|
}
|
2022-09-22 08:56:07 +08:00
|
|
|
}
|
|
|
|
}
|