Skip to content

Commit 28a632f

Browse files
committed
Make sure the settings can be found by not using StrippingProjectSettings.ActiveSettings
This was not an issue locally, but for CI builds
1 parent 42e58c3 commit 28a632f

File tree

10 files changed

+96
-10
lines changed

10 files changed

+96
-10
lines changed

Assets/BuildSettings.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!114 &11400000
4+
MonoBehaviour:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
m_GameObject: {fileID: 0}
10+
m_Enabled: 1
11+
m_EditorHideFlags: 0
12+
m_Script: {fileID: 11500000, guid: fcd00e435a104d7e87e22cbf3da9e251, type: 3}
13+
m_Name: BuildSettingsData
14+
m_EditorClassIdentifier:
15+
webSubmoduleStrippingSettings: {fileID: 11400000, guid: 9e2d86301b7954d0a94862ec5307a414,
16+
type: 2}

Assets/BuildSettings/BuildSettingsData.asset.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
File renamed without changes.

Assets/Scripts/Editor/BuildScript.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using UnityEditor.Compilation;
2020
using UnityEngine;
2121
using UnityEngine.Rendering;
22+
using Object = UnityEngine.Object;
2223
#if UNITY_6000_1_OR_NEWER
2324
using Unity.Web.Stripping.Editor;
2425
using UnityEngine.Assertions;
@@ -252,7 +253,7 @@ private static void SetGraphicsApi(string[] tagParameters)
252253
PlayerSettings.WebGL.wasm2023 = true;
253254
#endif
254255
#else
255-
LogError("WebGPU not supported yet");
256+
LogError("WebGPU not supported yet");
256257
#endif
257258
}
258259

@@ -394,16 +395,31 @@ private static void Build(BuildTarget buildTarget, string filePath)
394395
{
395396
Log("Run Submodule Stripping for WebGL build...");
396397
var webBuild = WebBuildReportList.Instance.GetBuild(buildSummary.outputPath);
398+
399+
var baseSettings = BuildSettingsData.Instance.WebSubmoduleStrippingSettings;
400+
Assert.IsNotNull(baseSettings, "Could not find stripping settings in BuildSettingsData.");
401+
var settings = Object.Instantiate(baseSettings);
402+
var graphicsAPIs = PlayerSettings.GetGraphicsAPIs(buildTarget);
403+
if (graphicsAPIs.All(api => api != GraphicsDeviceType.WebGPU))
404+
{
405+
Log("WebGPU is not used, stripping WebGPU support.");
406+
settings.SubmodulesToStrip.Add("WebGPU Support");
407+
}
408+
if (graphicsAPIs.All(api => api != GraphicsDeviceType.OpenGLES3 ))
409+
{
410+
Log("WebGL is not used, stripping WebGL support.");
411+
settings.SubmodulesToStrip.Add("WebGL Support");
412+
}
397413

398-
var settings = StrippingProjectSettings.ActiveSettings;
399-
Assert.IsNotNull(settings, "Could not find active stripping settings for WebGL build.");
400414
Log($"Using stripping settings {settings.name} with modules to strip: {string.Join(", ", settings.SubmodulesToStrip)}");
401415

402416
var successfulStripping = WebBuildProcessor.StripBuild(webBuild, settings);
403417
if (successfulStripping)
404418
{
405419
Log("The build was stripped successfully.");
406-
string functionsJsonPath = Path.Combine(buildSummary.outputPath, "Build", "functions.json");
420+
// Apparently the json files are read by unity,
421+
// it will work without them but the console is full of errors then
422+
/*string functionsJsonPath = Path.Combine(buildSummary.outputPath, "Build", "functions.json");
407423
if (File.Exists(functionsJsonPath))
408424
{
409425
File.Delete(functionsJsonPath);
@@ -422,7 +438,7 @@ private static void Build(BuildTarget buildTarget, string filePath)
422438
else
423439
{
424440
LogWarning($"Could not find file to delete: {labelsJsonPath}");
425-
}
441+
}*/
426442
}
427443
else
428444
{

Assets/Scripts/Editor/BuildScriptMenu.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace UnityBuilderAction
1717
{
1818
/// <summary>
19-
/// Menu items for <see cref="BuildScript"> to build the project in the editor
19+
/// Menu items for <see cref="BuildScript" /> to build the project in the editor
2020
/// Helpful for testing the CI behavior and semi-automated builds
2121
/// </summary>
2222
public class BuildScriptMenu
@@ -55,10 +55,10 @@ public static void BuildWebGL2MinSize()
5555
BuildWebGL($"{Application.unityVersion}-minsize-webgl2-manualBuild");
5656
}
5757

58-
[MenuItem("Tools/Build WebGL/minsize-stripped-webgl2")]
59-
public static void BuildWebGL2MinSizeStripped()
58+
[MenuItem("Tools/Build WebGL/minsize-stripping-webgl2")]
59+
public static void BuildWebGL2MinSizeStripping()
6060
{
61-
BuildWebGL($"{Application.unityVersion}-minsize-stripped-webgl2-manualBuild");
61+
BuildWebGL($"{Application.unityVersion}-minsize-stripping-webgl2-manualBuild");
6262
}
6363

6464
#if UNITY_2023_2_OR_NEWER
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Linq;
2+
using NUnit.Framework;
3+
using Unity.Web.Stripping.Editor;
4+
using UnityEditor;
5+
using UnityEngine;
6+
7+
namespace UnityBuilderAction
8+
{
9+
10+
[CreateAssetMenu(menuName = "Create BuildSettingsData", fileName = "BuildSettingsData", order = 0)]
11+
public class BuildSettingsData : ScriptableObject
12+
{
13+
private static BuildSettingsData _instance;
14+
15+
public static BuildSettingsData Instance
16+
{
17+
get
18+
{
19+
if (_instance == null)
20+
{
21+
_instance = AssetDatabase.FindAssets($"t:{nameof(BuildSettingsData)}")
22+
.Select(guid => AssetDatabase.LoadAssetAtPath<BuildSettingsData>(AssetDatabase.GUIDToAssetPath(guid)))
23+
.FirstOrDefault();
24+
Assert.IsNotNull(_instance, "BuildSettingsData not found, create it first.");
25+
}
26+
return _instance;
27+
}
28+
}
29+
30+
[SerializeField]
31+
private SubmoduleStrippingSettings webSubmoduleStrippingSettings;
32+
33+
public SubmoduleStrippingSettings WebSubmoduleStrippingSettings => webSubmoduleStrippingSettings;
34+
}
35+
}

Assets/Scripts/Editor/BuildSettingsData.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ProjectSettings/Packages/com.unity.web.stripping-tool/Settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"type": "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
66
"key": "StrippingProjectSettings.ActiveSettings.AssetPath",
7-
"value": "{\"m_Value\":\"Assets/DefaultSubmoduleStrippingSettings.asset\"}"
7+
"value": "{\"m_Value\":\"Assets/BuildSettings/DefaultSubmoduleStrippingSettings.asset\"}"
88
},
99
{
1010
"type": "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",

0 commit comments

Comments
 (0)