Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions eng/illink.targets
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<Project>

<PropertyGroup>
<!-- Custom trimming logic should always use live ILLink, even when none of the
trimming-related SDK properties are set. -->
<_RequiresLiveILLink>true</_RequiresLiveILLink>
</PropertyGroup>

<PropertyGroup>
<IsTrimmable Condition="'$(IsTrimmable)' == ''">true</IsTrimmable>
<PrepareResourcesDependsOn>_EmbedILLinkXmls;$(PrepareResourcesDependsOn)</PrepareResourcesDependsOn>
Expand Down Expand Up @@ -210,7 +204,8 @@
<!-- trim the target assembly -->
<ILLinkArgs>$(ILLinkArgs) --action link $(TargetName)</ILLinkArgs>
<ILLinkArgs Condition="'$(ILLinkRewritePDBs)' == 'true' and Exists('$(ILLinkTrimAssemblySymbols)')">$(ILLinkArgs) -b true</ILLinkArgs>
<ILLinkArgs Condition="'$(ILLinkRewritePDBs)' == 'true' and Exists('$(ILLinkTrimAssemblySymbols)') and '$(DeterministicSourcePaths)' == 'true'">$(ILLinkArgs) --preserve-symbol-paths</ILLinkArgs>
<!-- The preserve-symbol-paths option was introduced in .NET 9 -->
<ILLinkArgs Condition="'$(ILLinkRewritePDBs)' == 'true' and Exists('$(ILLinkTrimAssemblySymbols)') and '$(DeterministicSourcePaths)' == 'true' and $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))">$(ILLinkArgs) --preserve-symbol-paths</ILLinkArgs>
<!-- pass the non-embedded descriptors xml file on the command line -->
<ILLinkArgs Condition="'@(ILLinkDescriptorsLibraryBuildXml)' != ''">$(ILLinkArgs) -x "@(ILLinkDescriptorsLibraryBuildXml->'%(FullPath)', '" -x "')"</ILLinkArgs>
<ILLinkArgs Condition="'$(ILLinkSubstitutionsLibraryBuildXml)' != ''">$(ILLinkArgs) --substitutions "$(ILLinkSubstitutionsLibraryBuildXml)"</ILLinkArgs>
Expand Down
16 changes: 8 additions & 8 deletions eng/liveILLink.targets
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
<Project>

<!-- NOTE: these targets should be a no-op, unless _RequiresLiveILLink, computed below, is true. -->
<!-- NOTE: these targets should be a no-op, unless UseLiveILLink, computed below, is true. -->

<PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetCoreAppCurrent)'))">
<!-- Keep these conditions in sync with _RequiresILLinkPack in
https://github.com/dotnet/sdk/blob/main/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets -->
<_RequiresLiveILLink Condition="'$(_RequiresLiveILLink)' == '' And (
<UseLiveILLink Condition="'$(UseLiveILLink)' == '' And (
'$(PublishAot)' == 'true' Or
'$(IsAotCompatible)' == 'true' Or '$(EnableAotAnalyzer)' == 'true' Or
'$(PublishTrimmed)' == 'true' Or
'$(IsTrimmable)' == 'true' Or '$(EnableTrimAnalyzer)' == 'true' Or
'$(EnableSingleFileAnalyzer)' == 'true')">true</_RequiresLiveILLink>
'$(EnableSingleFileAnalyzer)' == 'true')">true</UseLiveILLink>
</PropertyGroup>

<PropertyGroup Condition="'$(_RequiresLiveILLink)' == 'true'">
<PropertyGroup Condition="'$(UseLiveILLink)' == 'true'">
<_ILLinkTasksSourceDir>$(ToolsProjectRoot)illink\src\ILLink.Tasks\</_ILLinkTasksSourceDir>
<ILLinkAnalyzersPropsPath>$(ToolsProjectRoot)illink\src\ILLink.RoslynAnalyzer\build\Microsoft.NET.ILLink.Analyzers.props</ILLinkAnalyzersPropsPath>
</PropertyGroup>

<Import Project="$(_ILLinkTasksSourceDir)build\Microsoft.NET.ILLink.Tasks.props" Condition="'$(_RequiresLiveILLink)' == 'true'" />
<Import Project="$(_ILLinkTasksSourceDir)build\Microsoft.NET.ILLink.Tasks.props" Condition="'$(UseLiveILLink)' == 'true'" />

<PropertyGroup Condition="'$(_RequiresLiveILLink)' == 'true'">
<PropertyGroup Condition="'$(UseLiveILLink)' == 'true'">
<!-- Don't use SDK's trimming functionality. -->
<_RequiresILLinkPack>false</_RequiresILLinkPack>
<ILLinkTasksAssembly Condition="'$(MSBuildRuntimeType)' == 'Core'">$(ToolsILLinkDir)net\ILLink.Tasks.dll</ILLinkTasksAssembly>
<ILLinkTasksAssembly Condition="'$(MSBuildRuntimeType)' != 'Core'">$(ToolsILLinkDir)netframework\ILLink.Tasks.dll</ILLinkTasksAssembly>
</PropertyGroup>

<ItemGroup Condition="'$(_RequiresLiveILLink)' == 'true'">
<ItemGroup Condition="'$(UseLiveILLink)' == 'true'">
<!-- The assembly shouldn't be referenced, nor promoted to a package dependency, nor copied to the output directory. -->
<ProjectReference Include="$(_ILLinkTasksSourceDir)ILLink.Tasks.csproj"
ReferenceOutputAssembly="false"
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/cdac-build-tool/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<!-- we don't trim cdac-build-tool; we don't need the live trimmer -->
<PropertyGroup>
<_RequiresLiveILLink>false</_RequiresLiveILLink>
<UseLiveILLink>false</UseLiveILLink>
</PropertyGroup>
<Import Project="..\Directory.Build.props" />
</Project>
2 changes: 0 additions & 2 deletions src/libraries/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
<!-- Nullability is enabled by default except for test projects, which instead default to annotations. -->
<Nullable Condition="'$(Nullable)' == '' and '$(IsTestProject)' != 'true'">enable</Nullable>
<Nullable Condition="'$(Nullable)' == '' and '$(IsTestProject)' == 'true'">annotations</Nullable>
<!-- AOT compatibility is enabled by default for src/ref projects. -->
<IsAotCompatible Condition="'$(IsAotCompatible)' == '' and ('$(IsSourceProject)' == 'true' or '$(IsReferenceAssemblyProject)' == 'true')">true</IsAotCompatible>
</PropertyGroup>

<!-- Set up common paths -->
Expand Down
13 changes: 12 additions & 1 deletion src/libraries/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<DisableImplicitFrameworkReferences Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and
'$(TargetFrameworkVersion)' == 'v$(NetCoreAppCurrentVersion)' and
('$(IsNETCoreAppRef)' == 'true' or '$(IsNETCoreAppSrc)' == 'true')">true</DisableImplicitFrameworkReferences>
<!-- AOT compatibility is enabled by default for src/ref projects. -->
<IsAotCompatible Condition="'$(IsAotCompatible)' == '' and ('$(IsSourceProject)' == 'true' or '$(IsReferenceAssemblyProject)' == 'true')">true</IsAotCompatible>
<!-- Source-build only builds the current TFM, so there's an intentional "gap" in downlevel TFMs.
The SDK warns about this gap (NETSDK1210), but it's expected for source-build since those
downlevel TFMs aren't shipped. Silence the warning. -->
<_SilenceIsAotCompatibleUnsupportedWarning Condition="'$(DotNetBuildSourceOnly)' == 'true'">true</_SilenceIsAotCompatibleUnsupportedWarning>
<!-- Enable trimming for any source project that's part of the shared framework.
Don't attempt to trim PNSE assemblies which are generated from the reference source. -->
<ILLinkTrimAssembly Condition="'$(ILLinkTrimAssembly)' == '' and
Expand Down Expand Up @@ -140,7 +146,12 @@
<Import Project="$(RepositoryEngineeringDir)testing\runsettings.targets" Condition="'$(EnableRunSettingsSupport)' == 'true'" />
<Import Project="$(RepositoryEngineeringDir)testing\coverage.targets" Condition="'$(EnableRunSettingsSupport)' == 'true' or '$(EnableCoverageSupport)' == 'true'" />

<Import Project="$(RepositoryEngineeringDir)illink.targets" Condition="'$(IsSourceProject)' == 'true' or '$(IsReferenceAssemblyProject)' == 'true' or '$(ExplicitlyImportCustomILLinkTargets)' == 'true'" />
<PropertyGroup>
<ImportCustomILLinkTargets Condition="'$(ImportCustomILLinkTargets)' == '' And
('$(IsSourceProject)' == 'true' Or '$(IsReferenceAssemblyProject)' == 'true') And
$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</ImportCustomILLinkTargets>
</PropertyGroup>
<Import Project="$(RepositoryEngineeringDir)illink.targets" Condition="'$(ImportCustomILLinkTargets)' == 'true'" />
<Import Project="$(RepositoryEngineeringDir)liveILLink.targets" />
<Import Project="$(RepositoryEngineeringDir)nativeSanitizers.targets" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;$(NetFrameworkMinimum);netstandard2.1</TargetFrameworks>
<!-- Use live ILLink so that the shim assembly gets IsAotCompatible and IsTrimmable metadata despite
not targeting a TFM supported by the shipping trimming tooling. -->
<UseLiveILLink>true</UseLiveILLink>
<IsPackable>true</IsPackable>
<!-- This assembly should never be placed inbox as it is only for downlevel compatibility. -->
<PackageDescription>Provides the IAsyncEnumerable&lt;T&gt; and IAsyncDisposable interfaces and helper types for .NET Standard 2.0. This package is not required starting with .NET Standard 2.1 and .NET Core 3.0.</PackageDescription>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;$(NetFrameworkMinimum);netstandard2.1</TargetFrameworks>
<!-- Use live ILLink so that the shim assembly gets IsAotCompatible and IsTrimmable metadata despite
not targeting a TFM supported by the shipping trimming tooling. -->
<UseLiveILLink>true</UseLiveILLink>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsPackable>true</IsPackable>
<!-- This assembly should never be placed inbox as it is only for downlevel compatibility. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<!-- this assembly doesn't need to be binplaced -->
<EnableBinPlacing>false</EnableBinPlacing>
<IsTrimmable>false</IsTrimmable>
<IsAotCompatible>false</IsAotCompatible>
<!-- TODO: Add package README file: https://github.com/dotnet/runtime/issues/99358 -->
<EnableDefaultPackageReadmeFile>false</EnableDefaultPackageReadmeFile>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
<StrongNameKeyId>ECMA</StrongNameKeyId>
<IsTrimmable>false</IsTrimmable>
<IsAotCompatible>false</IsAotCompatible>
<!-- Need ILLink task to generate resource substitutions -->
<UseLiveILLink>true</UseLiveILLink>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<IsTrimmable>false</IsTrimmable>
<IsAotCompatible>false</IsAotCompatible>
<!-- Need ILLink task to generate resource substitutions -->
<UseLiveILLink>true</UseLiveILLink>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
<IsPackable>true</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<RootNamespace>System.Composition</RootNamespace>
<IsTrimmable>false</IsTrimmable>
<IsAotCompatible>false</IsAotCompatible>
<!-- Need ILLink task to generate resource substitutions -->
<UseLiveILLink>true</UseLiveILLink>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<UseCompilerGeneratedDocXmlFile>false</UseCompilerGeneratedDocXmlFile>
<IsPackable>true</IsPackable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
<!-- opt-out of trimming until it works https://github.com/dotnet/runtime/issues/49062 -->
<IsTrimmable>false</IsTrimmable>
<IsAotCompatible>false</IsAotCompatible>
<!-- Need ILLink task to generate resource substitutions -->
<UseLiveILLink>true</UseLiveILLink>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<!-- This assembly doesn't contain any code and does not participate in trim analysis. -->
<IsAotCompatible>false</IsAotCompatible>
<IsTrimmable>false</IsTrimmable>
<Nullable>disable</Nullable>
<Win32Resource>EventLogMessages.res</Win32Resource>
<!-- Override the parent Directory.Build.props -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text.Encodings.Web;
Expand Down Expand Up @@ -523,7 +524,7 @@ private static EnumFieldInfo[] ResolveEnumFields(JsonNamingPolicy? namingPolicy)
Debug.Assert(names.Length == values.Length);

Dictionary<string, string>? enumMemberAttributes = null;
foreach (FieldInfo field in typeof(T).GetFields(BindingFlags.Public | BindingFlags.Static))
foreach (FieldInfo field in GetFields())
{
if (field.GetCustomAttribute<JsonStringEnumMemberNameAttribute>() is { } attribute)
{
Expand Down Expand Up @@ -561,6 +562,12 @@ private static EnumFieldInfo[] ResolveEnumFields(JsonNamingPolicy? namingPolicy)
}

return enumFields;

#if !NET9_0_OR_GREATER
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2090:UnrecognizedReflectionPattern",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd want folks from @dotnet/area-system-text-json to review all these. cc @eiriktsarpalis

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The STJ changes look good to me.

Justification = "Enum fields are always preserved by trimming.")]
#endif
static IEnumerable<FieldInfo> GetFields() => typeof(T).GetFields(BindingFlags.Public | BindingFlags.Static);
}

private static string ResolveAndValidateJsonName(string name, JsonNamingPolicy? namingPolicy, EnumFieldNameKind kind)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ public override JsonConverter CreateConverter(Type type, JsonSerializerOptions o
return Create(type, EnumConverterOptions.AllowNumbers, namingPolicy: null, options);
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2071:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage(
"ReflectionAnalysis",
#if NET9_0_OR_GREATER
"IL2071:UnrecognizedReflectionPattern",
#else
"IL2070:UnrecognizedReflectionPattern",
#endif
Justification = "'EnumConverter<T> where T : struct' implies 'T : new()', so the trimmer is warning calling MakeGenericType here because enumType's constructors are not annotated. " +
"But EnumConverter doesn't call new T(), so this is safe.")]
public static JsonConverter Create(Type enumType, EnumConverterOptions converterOptions, JsonNamingPolicy? namingPolicy, JsonSerializerOptions options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ public static JsonConverter CreateValueConverter(Type valueTypeToConvert, JsonCo
culture: null)!;
}

[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2071:UnrecognizedReflectionPattern",
[UnconditionalSuppressMessage(
"ReflectionAnalysis",
#if NET9_0_OR_GREATER
"IL2071:UnrecognizedReflectionPattern",
#else
"IL2070:UnrecognizedReflectionPattern",
#endif
Justification = "'NullableConverter<T> where T : struct' implies 'T : new()', so the trimmer is warning calling MakeGenericType here because valueTypeToConvert's constructors are not annotated. " +
"But NullableConverter doesn't call new T(), so this is safe.")]
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ public override JsonTypeInfo.ParameterizedConstructorDelegate<T, TArg0, TArg1, T
return dynamicMethod;
}

#if !NET9_0_OR_GREATER
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2046",
Justification = "The type is annotated with RequiresUnreferencedCode, so the trimmer will warn at construction time.")]
#endif
public override Action<TCollection, object?> CreateAddMethodDelegate<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] TCollection>() =>
CreateDelegate<Action<TCollection, object?>>(CreateAddMethodDelegate(typeof(TCollection)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public override JsonTypeInfo.ParameterizedConstructorDelegate<T, TArg0, TArg1, T
};
}

#if !NET9_0_OR_GREATER
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2046",
Justification = "The type is annotated with RequiresUnreferencedCode, so the trimmer will warn at construction time.")]
#endif
public override Action<TCollection, object?> CreateAddMethodDelegate<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] TCollection>()
{
Type collectionType = typeof(TCollection);
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/oob-trim.proj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>$(NetCoreAppCurrent)-$(TargetOS)</TargetFramework>
<!-- Import the illink file which contains some of the logic required to illink the out-of-band assemblies. -->
<ExplicitlyImportCustomILLinkTargets>true</ExplicitlyImportCustomILLinkTargets>
<ImportCustomILLinkTargets>true</ImportCustomILLinkTargets>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/sfx-finish.proj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NoDefaultSlnGenSolutionFolder>true</NoDefaultSlnGenSolutionFolder>
<FrameworkListOutputPath>$(MicrosoftNetCoreAppRefPackDataDir)FrameworkList.xml</FrameworkListOutputPath>
<!-- Import the illink file which contains some of the logic required to illink the shared framework assemblies. -->
<ExplicitlyImportCustomILLinkTargets>true</ExplicitlyImportCustomILLinkTargets>
<ImportCustomILLinkTargets>true</ImportCustomILLinkTargets>

<PackageOverridesInputPath>$(InstallerProjectRoot)pkg\sfx\Microsoft.NETCore.App\PackageOverrides.txt</PackageOverridesInputPath>
<PackageOverridesOutputPath>$(MicrosoftNetCoreAppRefPackDataDir)PackageOverrides.txt</PackageOverridesOutputPath>
Expand Down
Loading