2
2
// Licensed under the MIT License.
3
3
4
4
using System . IO ;
5
+ using System . Xml ;
5
6
using UnityEngine ;
6
7
7
8
namespace Microsoft . MixedReality . Toolkit . Utilities . Editor
@@ -17,42 +18,42 @@ internal static class MixedRealityToolkitPreserveSettings
17
18
/// behalf of the project.
18
19
/// </summary>
19
20
private const string defaultLinkXmlContents =
20
- "<linker> \n " +
21
- " <!-- \n " +
22
- " This link.xml file is provided to prevent MRTK code from being optimized away \n " +
23
- " during IL2CPP builds.More details on when this is needed and why this is needed \n " +
24
- " can be found here: https://github.com/microsoft/MixedRealityToolkit-Unity/issues/5273 \n " +
25
- " If your application doesn't use some specific services (for example, if teleportation system is \n " +
26
- " disabled in the profile), it is possible to remove their corresponding lines down \n " +
27
- " below (in the previous example, we would remove the TeleportSystem below). \n " +
28
- " It's recommended to start with this list and narrow down if you want to ensure \n " +
29
- " specific bits of code get optimized away. \n " +
30
- " --> \n " +
31
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit\" preserve=\" all\" /> \n " +
32
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.SDK\" preserve=\" all\" /> \n " +
33
- " <!-- Core systems --> \n " +
34
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Services.BoundarySystem\" preserve=\" all\" /> \n " +
35
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Services.CameraSystem\" preserve=\" all\" /> \n " +
36
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Services.DiagnosticsSystem\" preserve=\" all\" /> \n " +
37
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Services.InputSystem\" preserve=\" all\" /> \n " +
38
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Services.SceneSystem\" preserve=\" all\" /> \n " +
39
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Services.SpatialAwarenessSystem\" preserve=\" all\" /> \n " +
40
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Services.TeleportSystem\" preserve=\" all\" /> \n " +
41
- " <!-- Data providers --> \n " +
42
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Providers.LeapMotion\" preserve=\" all\" /> \n " +
43
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Providers.OpenVR\" preserve=\" all\" /> \n " +
44
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Providers.OpenXR\" preserve=\" all\" /> \n " +
45
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Providers.UnityAR\" preserve=\" all\" /> \n " +
46
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Providers.WindowsMixedReality.Shared\" preserve=\" all\" /> \n " +
47
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Providers.WindowsMixedReality\" preserve=\" all\" /> \n " +
48
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality\" preserve=\" all\" /> \n " +
49
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Providers.WindowsVoiceInput\" preserve=\" all\" /> \n " +
50
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Providers.XRSDK\" preserve=\" all\" /> \n " +
51
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Providers.WindowsSceneUnderstanding\" preserve=\" all\" /> \n " +
52
- " <!-- Extension services --> \n " +
53
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Extensions.HandPhysics\" preserve=\" all\" /> \n " +
54
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Extensions.Tracking\" preserve=\" all\" /> \n " +
55
- " <assembly fullname = \" Microsoft.MixedReality.Toolkit.Extensions.SceneTransitionService\" preserve=\" all\" /> \n " +
21
+ "<linker>\n " +
22
+ " <!--\n " +
23
+ " This link.xml file is provided to prevent MRTK code from being optimized away\n " +
24
+ " during IL2CPP builds. More details on when this is needed and why this is needed\n " +
25
+ " can be found here: https://github.com/microsoft/MixedRealityToolkit-Unity/issues/5273\n " +
26
+ " If your application doesn't use some specific services (for example, if teleportation system is\n " +
27
+ " disabled in the profile), it is possible to remove their corresponding lines down\n " +
28
+ " below (in the previous example, we would remove the TeleportSystem below).\n " +
29
+ " It's recommended to start with this list and narrow down if you want to ensure\n " +
30
+ " specific bits of code get optimized away.\n " +
31
+ " -->\n " +
32
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
33
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.SDK\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
34
+ " <!-- Core systems -->\n " +
35
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Services.BoundarySystem\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
36
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Services.CameraSystem\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
37
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Services.DiagnosticsSystem\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
38
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Services.InputSystem\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
39
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Services.SceneSystem\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
40
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Services.SpatialAwarenessSystem\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
41
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Services.TeleportSystem\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
42
+ " <!-- Data providers -->\n " +
43
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Providers.LeapMotion\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
44
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Providers.OpenVR\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
45
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Providers.OpenXR\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
46
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Providers.UnityAR\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
47
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Providers.WindowsMixedReality.Shared\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
48
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Providers.WindowsMixedReality\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
49
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Providers.XRSDK.WindowsMixedReality\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
50
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Providers.WindowsVoiceInput\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
51
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Providers.XRSDK\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
52
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Providers.WindowsSceneUnderstanding\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
53
+ " <!-- Extension services -->\n " +
54
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Extensions.HandPhysics\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
55
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Extensions.Tracking\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
56
+ " <assembly fullname= \" Microsoft.MixedReality.Toolkit.Extensions.SceneTransitionService\" preserve=\" all\" ignoreIfMissing= \" 1 \" /> \n " +
56
57
"</linker>" ;
57
58
58
59
/// <summary>
@@ -63,17 +64,49 @@ public static void EnsureLinkXml()
63
64
{
64
65
string generatedFolder = MixedRealityToolkitFiles . MapRelativeFolderPathToAbsolutePath ( MixedRealityToolkitModuleType . Generated , "" ) ;
65
66
string linkXmlPath = Path . Combine ( generatedFolder , "link.xml" ) ;
67
+
66
68
if ( File . Exists ( linkXmlPath ) )
67
69
{
68
- // Do not touch the existing file.
70
+ bool xmlUpdated = false ;
71
+
72
+ // Update to ensure Unity's okay ignoring missing assemblies
73
+ XmlDocument doc = new XmlDocument ( ) ;
74
+ doc . Load ( linkXmlPath ) ;
75
+
76
+ XmlNodeList assemblyNodes = doc . SelectNodes ( @"/linker/assembly" ) ;
77
+
78
+ if ( assemblyNodes != null )
79
+ {
80
+ XmlAttribute newAttr = doc . CreateAttribute ( "ignoreIfMissing" ) ;
81
+ newAttr . Value = "1" ;
82
+
83
+ foreach ( XmlNode assembly in assemblyNodes )
84
+ {
85
+ XmlNode fullname = assembly . Attributes . GetNamedItem ( "fullname" ) ;
86
+ XmlNode ignoreIfMissing = assembly . Attributes . GetNamedItem ( "ignoreIfMissing" ) ;
87
+ if ( ignoreIfMissing == null && fullname . InnerText . StartsWith ( "Microsoft.MixedReality.Toolkit" ) )
88
+ {
89
+ assembly . Attributes . SetNamedItem ( newAttr ) ;
90
+ xmlUpdated = true ;
91
+ }
92
+ }
93
+ }
94
+
95
+ if ( xmlUpdated )
96
+ {
97
+ Debug . Log ( $ "The link.xml file in { MixedRealityToolkitFiles . GetGeneratedFolder } was updated to include \" ignoreIfMissing\" tags.\n " +
98
+ "This is required in Unity 2021 or later for legacy XR assemblies that are no longer used and is okay if this project is on an earlier version." ) ;
99
+ doc . Save ( linkXmlPath ) ;
100
+ }
101
+
69
102
return ;
70
103
}
71
104
72
105
// Create a default link.xml with an initial set of assembly preservation rules.
73
106
using ( StreamWriter writer = new StreamWriter ( linkXmlPath ) )
74
107
{
75
108
writer . WriteLine ( defaultLinkXmlContents ) ;
76
- Debug . Log ( $ "A link.xml file was created in { MixedRealityToolkitFiles . GetGeneratedFolder } . \n " +
109
+ Debug . Log ( $ "A link.xml file was created in { MixedRealityToolkitFiles . GetGeneratedFolder } .\n " +
77
110
"This file is used to control preservation of MRTK code during linking. It is recommended to add link.xml (and link.xml.meta) to source control." ) ;
78
111
}
79
112
}
0 commit comments