Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable additional ways to opt in to trimming #16094

Merged
merged 2 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@
<Uri>https://github.com/microsoft/vstest</Uri>
<Sha>8ee2efd12c3781c5cf850f113f2252fda6a3312b</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="6.0.100-preview.2.21124.3">
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="6.0.100-preview.2.21125.1">
<Uri>https://github.com/mono/linker</Uri>
<Sha>6b3a3050c70577bd1b3fd7611eef56679e22a4f1</Sha>
<Sha>44907d98e524f65db0a0edc2cab8afe077ba812a</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.ILLink.Analyzers" Version="6.0.100-preview.2.21124.3">
<Dependency Name="Microsoft.NET.ILLink.Analyzers" Version="6.0.100-preview.2.21125.1">
<Uri>https://github.com/mono/linker</Uri>
<Sha>6b3a3050c70577bd1b3fd7611eef56679e22a4f1</Sha>
<Sha>44907d98e524f65db0a0edc2cab8afe077ba812a</Sha>
</Dependency>
<Dependency Name="System.CodeDom" Version="6.0.0-preview.3.21123.15">
<Uri>https://github.com/dotnet/runtime</Uri>
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
</PropertyGroup>
<PropertyGroup>
<!-- Dependencies from https://github.com/mono/linker -->
<MicrosoftNETILLinkTasksPackageVersion>6.0.100-preview.2.21124.3</MicrosoftNETILLinkTasksPackageVersion>
<MicrosoftNETILLinkTasksPackageVersion>6.0.100-preview.2.21125.1</MicrosoftNETILLinkTasksPackageVersion>
<MicrosoftNETILLinkAnalyzerPackageVersion>$(MicrosoftNETILLinkTasksPackageVersion)</MicrosoftNETILLinkAnalyzerPackageVersion>
</PropertyGroup>
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Copyright (c) .NET Foundation. All rights reserved.
ReferenceAssemblyPaths="@(ReferencePath)"
RootAssemblyNames="@(TrimmerRootAssembly)"
TrimMode="$(TrimMode)"
DefaultAction="$(_TrimmerDefaultAction)"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should _TrimmerDefaultAction use underscore? This is the only property the developers would need to change to make their apps fully linker, right?

Copy link
Member Author

@sbomer sbomer Mar 1, 2021

Choose a reason for hiding this comment

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

Yes - I would like it to be public - but in the discussions about a similar TrimAllAssemblies opt-in there were concerns about making it too easy to trim everything. I restarted the discussion in #16140.

RemoveSymbols="$(TrimmerRemoveSymbols)"
FeatureSettings="@(_TrimmerFeatureSettings)"
CustomData="@(_TrimmerCustomData)"
Expand Down Expand Up @@ -171,15 +172,24 @@ Copyright (c) .NET Foundation. All rights reserved.
in some cases. -->
<NETSdkError Condition="'$(SelfContained)' != 'true'" ResourceName="ILLinkNotSupportedError" />

<PropertyGroup>
<ILLinkWarningLevel Condition=" '$(ILLinkWarningLevel)' == '' And
'$(EffectiveAnalysisLevel)' != '' And
<PropertyGroup Condition=" '$(ILLinkWarningLevel)' == '' ">
<ILLinkWarningLevel Condition=" '$(EffectiveAnalysisLevel)' != '' And
$([MSBuild]::VersionGreaterThanOrEquals($(EffectiveAnalysisLevel), '5.0')) ">5</ILLinkWarningLevel>
<ILLinkWarningLevel Condition=" '$(ILLinkWarningLevel)' == '' ">0</ILLinkWarningLevel>
</PropertyGroup>

<PropertyGroup>
<ILLinkTreatWarningsAsErrors Condition=" '$(ILLinkTreatWarningsAsErrors)' == '' ">$(TreatWarningsAsErrors)</ILLinkTreatWarningsAsErrors>
<_ExtraTrimmerArgs>--skip-unresolved true $(_ExtraTrimmerArgs)</_ExtraTrimmerArgs>
<TrimMode Condition=" '$(TrimMode)' == '' ">copyused</TrimMode>
</PropertyGroup>

<PropertyGroup Condition=" '$(_TrimmerDefaultAction)' == '' ">
sbomer marked this conversation as resolved.
Show resolved Hide resolved
<!-- For .NET < 6, the defaults are the same regardless of whether the assembly has an IsTrimmable attribute. (The attribute didn't exist until .NET 6.) -->
<_TrimmerDefaultAction Condition=" $([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '6.0')) ">$(TrimMode)</_TrimmerDefaultAction>
sbomer marked this conversation as resolved.
Show resolved Hide resolved
<!-- For .NET 6+, assemblies without IsTrimmable attribute get the "copy" action. -->
<_TrimmerDefaultAction Condition=" '$(_TrimmerDefaultAction)' == '' ">copy</_TrimmerDefaultAction>
</PropertyGroup>

<!-- Suppress warnings produced by the linker. Any warnings shared with the analyzer should be
moved to the global PropertyGroup above. -->
Expand Down Expand Up @@ -221,17 +231,45 @@ Copyright (c) .NET Foundation. All rights reserved.
</PropertyGroup>

<ItemGroup>
<!-- Treat any assemblies that already have customized TrimMode as trimmable. -->
<!-- Set IsTrimmable for any assemblies that already have customized TrimMode. -->
<ManagedAssemblyToLink Condition=" '%(ManagedAssemblyToLink.TrimMode)' != '' ">
<IsTrimmable>true</IsTrimmable>
</ManagedAssemblyToLink>
<!-- Root and copy non-trimmable assemblies. -->

<!-- SetIsTrimmable for any assemblies listed in TrimmableAssembly. -->
<_ManagedAssemblyToLinkName Include="@(ManagedAssemblyToLink->'%(Filename)')">
<OriginalItemSpec>%(Identity)</OriginalItemSpec>
</_ManagedAssemblyToLinkName>
<_NonTrimmableManagedAssemblyToLinkName Include="@(_ManagedAssemblyToLinkName)" Exclude="@(TrimmableAssembly)" />
sbomer marked this conversation as resolved.
Show resolved Hide resolved
<_TrimmableManagedAssemblyToLinkName Include="@(_ManagedAssemblyToLinkName)" Exclude="@(_NonTrimmableManagedAssemblyToLinkName)" />
<_TrimmableManagedAssemblyToLink Include="@(_TrimmableManagedAssemblyToLinkName->'%(OriginalItemSpec)')" />
sbomer marked this conversation as resolved.
Show resolved Hide resolved
<ManagedAssemblyToLink Remove="@(_TrimmableManagedAssemblyToLink)" />
<ManagedAssemblyToLink Include="@(_TrimmableManagedAssemblyToLink)">
<IsTrimmable>true</IsTrimmable>
</ManagedAssemblyToLink>

<!-- Root the main assembly, whether or not it has IsTrimmable set. -->
<TrimmerRootAssembly Include="@(IntermediateAssembly)" />
</ItemGroup>

<!-- For .NET < 6, root and copy assemblies without IsTrimmable=true MSBuild metadata. -->
<ItemGroup Condition=" $([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '6.0')) ">
<TrimmerRootAssembly Include="@(ManagedAssemblyToLink)" Condition=" '%(ManagedAssemblyToLink.IsTrimmable)' != 'true' " />
<ManagedAssemblyToLink Condition=" '%(ManagedAssemblyToLink.IsTrimmable)' != 'true' ">
<TrimMode>copy</TrimMode>
</ManagedAssemblyToLink>
</ItemGroup>

<!-- In .NET6+, set the action explicitly for any with IsTrimmable MSBuild metadata -->
<ItemGroup Condition=" $([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '6.0')) ">
<ManagedAssemblyToLink Condition=" '%(ManagedAssemblyToLink.IsTrimmable)' == 'true' And '%(ManagedAssemblyToLink.TrimMode)' == '' ">
<TrimMode>$(TrimMode)</TrimMode>
</ManagedAssemblyToLink>
<ManagedAssemblyToLink Condition=" '%(ManagedAssemblyToLink.IsTrimmable)' == 'false' And '%(ManagedAssemblyToLink.TrimMode)' == '' ">
<TrimMode>$(_TrimmerDefaultAction)</TrimMode>
</ManagedAssemblyToLink>
</ItemGroup>

<ItemGroup>
<_TrimmerFeatureSettings Include="@(RuntimeHostConfigurationOption)" Condition="'%(RuntimeHostConfigurationOption.Trim)' == 'true'" />
</ItemGroup>
Expand Down
Loading