Skip to content

Commit df4465a

Browse files
committed
Change use LTO option for builds
1 parent de7bdf9 commit df4465a

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

Assets/Scripts/Editor/BuildScript.cs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Linq;
1515
using JetBrains.Annotations;
1616
using UnityEditor;
17+
using UnityEditor.Build;
1718
using UnityEditor.Build.Reporting;
1819
using UnityEngine;
1920
using UnityEngine.Rendering;
@@ -31,6 +32,25 @@ public static class BuildScript
3132
private static readonly string Eol = Environment.NewLine;
3233
private static bool LogVerboseBatchMode = true;
3334
private static bool LogVerboseInEditor = false;
35+
private const string CodeOptimizationSpeed =
36+
#if UNITY_2021_3_OR_NEWER
37+
"runtimespeedlto";
38+
#else
39+
"speed";
40+
#endif
41+
private const string CodeOptimizationSize =
42+
#if UNITY_2021_3_OR_NEWER
43+
"disksizelto";
44+
#else
45+
"size";
46+
#endif
47+
48+
private const string CodeOptimizationBuildTimes =
49+
#if UNITY_2021_3_OR_NEWER
50+
"buildtimes";
51+
#else
52+
"size";
53+
#endif
3454

3555
private static readonly string[] Secrets =
3656
{ "androidKeystorePass", "androidKeyaliasName", "androidKeyaliasPass" };
@@ -84,6 +104,7 @@ public static void Build(string[] args)
84104
#if UNITY_2021_2_OR_NEWER
85105
// Use ASTC texture compression, since we are also targeting mobile versions - Don't use this for desktop only targets
86106
buildPlayerOptions.subtarget = (int)WebGLTextureSubtarget.ASTC;
107+
var namedBuildTarget = NamedBuildTarget.WebGL;
87108
#endif
88109

89110
if (options.TryGetValue("tag", out string tagVersion) &&
@@ -93,17 +114,22 @@ public static void Build(string[] args)
93114
if (tagParameters.Contains("minsize"))
94115
{
95116
PlayerSettings.WebGL.template = "PROJECT:Release";
96-
SetWebGlOptimization("size");
117+
SetWebGlOptimization(CodeOptimizationSize);
118+
buildPlayerOptions.options |= BuildOptions.CompressWithLz4HC;
97119
PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.None;
98120
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Master);
121+
#if UNITY_2021_2_OR_NEWER
122+
PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSize);
123+
#endif
99124
}
100125
else if (tagParameters.Contains("debug"))
101126
{
102127
PlayerSettings.WebGL.template = "PROJECT:Develop";
103-
SetWebGlOptimization("size");
104128
PlayerSettings.WebGL.exceptionSupport = WebGLExceptionSupport.FullWithStacktrace;
105129
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Debug);
130+
SetWebGlOptimization(CodeOptimizationBuildTimes);
106131
#if UNITY_2021_2_OR_NEWER
132+
PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSize);
107133
PlayerSettings.WebGL.debugSymbolMode = WebGLDebugSymbolMode.Embedded;
108134
#else
109135
PlayerSettings.WebGL.debugSymbols = true;
@@ -117,8 +143,12 @@ public static void Build(string[] args)
117143
else
118144
{
119145
PlayerSettings.WebGL.template = "PROJECT:Develop";
146+
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.WebGL, Il2CppCompilerConfiguration.Master);
120147
// By default use the speed setting
121-
SetWebGlOptimization("speed");
148+
SetWebGlOptimization(CodeOptimizationSpeed);
149+
#if UNITY_2021_2_OR_NEWER
150+
PlayerSettings.SetIl2CppCodeGeneration(namedBuildTarget, Il2CppCodeGeneration.OptimizeSpeed);
151+
#endif
122152
}
123153

124154
List<GraphicsDeviceType> graphicsAPIs = new List<GraphicsDeviceType>();
@@ -155,7 +185,7 @@ public static void Build(string[] args)
155185
// Additional options for local builds
156186
if (!Application.isBatchMode)
157187
{
158-
if (options.TryGetValue("autorunplayer", out string autorunplayer))
188+
if (options.TryGetValue("autorunplayer", out string _))
159189
{
160190
buildPlayerOptions.options |= BuildOptions.AutoRunPlayer;
161191
}

0 commit comments

Comments
 (0)