Skip to content

Commit 9b50c20

Browse files
authored
Ensure AOT Compatibility (#100)
1 parent a0f59fe commit 9b50c20

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

Cpp2IL.Core/Attributes/RegisterCpp2IlPluginAttribute.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ namespace Cpp2IL.Core.Attributes;
77
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
88
public class RegisterCpp2IlPluginAttribute : Attribute
99
{
10-
#if NET6_0
1110
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
12-
#endif
1311
public Type PluginType { get; }
1412

15-
public RegisterCpp2IlPluginAttribute(Type pluginType)
13+
public RegisterCpp2IlPluginAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type pluginType)
1614
{
1715
if (!typeof(Cpp2IlPlugin).IsAssignableFrom(pluginType))
1816
throw new ArgumentException("Plugin type to register must extend Cpp2IlPlugin", nameof(pluginType));
@@ -22,4 +20,4 @@ public RegisterCpp2IlPluginAttribute(Type pluginType)
2220

2321
PluginType = pluginType;
2422
}
25-
}
23+
}

Cpp2IL.Core/Cpp2IL.Core.csproj

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@
1616
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1717
<RepositoryType>git</RepositoryType>
1818
<RepositoryUrl>https://github.com/SamboyCoding/Cpp2IL.git</RepositoryUrl>
19-
<TargetFrameworks>net7.0;net6.0;netstandard2.0</TargetFrameworks>
19+
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.0</TargetFrameworks>
2020
<Title>Cpp2IL.Core</Title>
2121
<VersionPrefix>2022.1.0</VersionPrefix>
22-
<!--Plugins make this non-trimmable-->
2322

2423
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
24+
<PolySharpIncludeRuntimeSupportedAttributes>true</PolySharpIncludeRuntimeSupportedAttributes>
25+
</PropertyGroup>
26+
27+
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
28+
<IsTrimmable>true</IsTrimmable>
29+
</PropertyGroup>
30+
31+
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
32+
<IsAotCompatible>true</IsAotCompatible>
2533
</PropertyGroup>
2634

2735
<ItemGroup>
@@ -40,7 +48,7 @@
4048
<!--Not used at runtime, but needed for the build-->
4149
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
4250

43-
<PackageReference Include="PolySharp" Version="1.12.1" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
51+
<PackageReference Include="PolySharp" Version="1.14.1" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
4452
</ItemGroup>
4553

4654
<ItemGroup Condition="'$(TargetFramework)' != 'net6.0'">

Cpp2IL.Core/Cpp2IlApi.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public static class Cpp2IlApi
2020
{
2121
public static ApplicationAnalysisContext? CurrentAppContext;
2222

23+
[RequiresUnreferencedCode("Plugins are loaded dynamically.")]
2324
public static void Init(string pluginsDir = "Plugins")
2425
{
2526
Cpp2IlPluginManager.LoadFromDirectory(Path.Combine(Environment.CurrentDirectory, pluginsDir));

Cpp2IL.Core/Cpp2IlPluginManager.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.IO;
45
using System.Linq;
56
using System.Reflection;
@@ -13,6 +14,7 @@ public static class Cpp2IlPluginManager
1314
{
1415
private static List<Cpp2IlPlugin> _loadedPlugins = new();
1516

17+
[RequiresUnreferencedCode("Plugins are loaded dynamically.")]
1618
internal static void LoadFromDirectory(string pluginsDir)
1719
{
1820
Logger.InfoNewline($"Loading plugins from {pluginsDir}...", "Plugins");
@@ -101,4 +103,4 @@ public static void CallOnFinish()
101103
cpp2IlPlugin.CallOnFinish();
102104
}
103105
}
104-
}
106+
}

LibCpp2IL/LibCpp2IL.csproj

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,25 @@
1717
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1818
<Description>Library for interacting with IL2CPP metadata and binaries</Description>
1919
<Configurations>Debug;Release</Configurations>
20-
<TargetFrameworks>net7.0;net6.0;netstandard2.0</TargetFrameworks>
20+
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.0</TargetFrameworks>
21+
<PolySharpIncludeRuntimeSupportedAttributes>true</PolySharpIncludeRuntimeSupportedAttributes>
2122
</PropertyGroup>
2223

2324
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
2425
<IsTrimmable>true</IsTrimmable>
2526
</PropertyGroup>
2627

28+
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
29+
<IsAotCompatible>true</IsAotCompatible>
30+
</PropertyGroup>
31+
2732
<ItemGroup>
2833
<PackageReference Include="AssetRipper.Primitives" Version="2.1.0" />
34+
<PackageReference Include="PolySharp" Version="1.14.1" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
2935
</ItemGroup>
3036

3137
<ItemGroup Condition="'$(TargetFramework)' != 'net6.0'">
32-
<PackageReference Include="IndexRange" Version="1.0.2" />
3338
<PackageReference Include="System.Memory" Version="4.5.5" />
34-
<PackageReference Include="Nullable" Version="1.3.1" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
3539
</ItemGroup>
3640

3741
<ItemGroup>

WasmDisassembler/WasmDisassembler.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@
1515
<RepositoryUrl>https://github.com/SamboyCoding/Cpp2IL.git</RepositoryUrl>
1616
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1717
<Description>Simple, zero-dependency disassembler for WebAssembly bytecode</Description>
18-
<TargetFrameworks>net7.0;net6.0;netstandard2.0</TargetFrameworks>
18+
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.0</TargetFrameworks>
19+
</PropertyGroup>
20+
21+
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
1922
<IsTrimmable>true</IsTrimmable>
2023
</PropertyGroup>
2124

25+
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
26+
<IsAotCompatible>true</IsAotCompatible>
27+
</PropertyGroup>
28+
2229
</Project>

0 commit comments

Comments
 (0)