-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add more trimming options to TrimMode and change defaults #2856
Changes from 1 commit
774a7b5
d284611
67a526a
6e5faa3
381e390
92f1b11
ea1ea46
06fcb73
17055e1
46518c5
c7f5e88
11e5cd3
83620fa
1d93fe4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,8 +51,8 @@ Copyright (c) .NET Foundation. All rights reserved. | |
<PropertyGroup Condition="'$(SuppressTrimAnalysisWarnings)' == '' And '$(PublishTrimmed)' == 'true' And '$(EnableTrimAnalyzer)' != 'true'"> | ||
<!-- Trim analysis warnings are suppressed for .NET < 6. --> | ||
<SuppressTrimAnalysisWarnings Condition="$([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '6.0'))">true</SuppressTrimAnalysisWarnings> | ||
<!-- Suppress for WPF/WinForms (unless linking everything) --> | ||
<SuppressTrimAnalysisWarnings Condition="'$(TrimmerDefaultAction)' != 'link' And ('$(UseWpf)' == 'true' Or '$(UseWindowsForms)' == 'true')">true</SuppressTrimAnalysisWarnings> | ||
<!-- Suppress for WPF/WinForms --> | ||
<SuppressTrimAnalysisWarnings Condition="'$(UseWpf)' == 'true' Or '$(UseWindowsForms)' == 'true'">true</SuppressTrimAnalysisWarnings> | ||
Comment on lines
-54
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? If I trim WinForms app and ask for TrimMode=full, I should get all the warnings. Similarly I would expect this behavior in all other places, basically if I say TrimMode=full - I should get warnings by default (since I asked for the "hard " mode). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's currently blocked off completely, which is why we hide the warnings at all. I think we should either show the warnings or disallow trimming. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK - if we rely on the error for this, then I agree. We should at least add a comment here (why it's OK to suppress). Ideally if the error is disabled we would reenable the warnings (this should really only affect analyzer anyway, the error will trigger before we get to run the linker anyway) |
||
<!-- Otherwise, for .NET 6+, warnings are on by default --> | ||
<SuppressTrimAnalysisWarnings Condition="'$(SuppressTrimAnalysisWarnings)' == ''">false</SuppressTrimAnalysisWarnings> | ||
</PropertyGroup> | ||
|
@@ -154,12 +154,21 @@ Copyright (c) .NET Foundation. All rights reserved. | |
<_DotNetHostFileName Condition="$([MSBuild]::IsOSPlatform(`Windows`))">dotnet.exe</_DotNetHostFileName> | ||
</PropertyGroup> | ||
|
||
<!-- Define a LinkVersion to support different options behavior based on TFM. --> | ||
<PropertyGroup> | ||
<_LinkVersion Condition="$([MSBuild]::VersionGreaterThan('$(TargetFrameworkVersion)', '6.0'))">7</_LinkVersion> | ||
<_LinkVersion Condition="$([MSBuild]::VersionEquals('$(TargetFrameworkVersion)', '6.0'))">6</_LinkVersion> | ||
<_LinkVersion Condition="$([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '6.0'))">5</_LinkVersion> | ||
<_LinkVersion Condition="$([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '5.0'))">3</_LinkVersion> | ||
</PropertyGroup> | ||
|
||
<Delete Files="@(_LinkedResolvedFileToPublishCandidate)" /> | ||
<ILLink AssemblyPaths="@(ManagedAssemblyToLink)" | ||
ReferenceAssemblyPaths="@(ReferencePath)" | ||
RootAssemblyNames="@(TrimmerRootAssembly)" | ||
LinkVersion="$(_LinkVersion)" | ||
TrimMode="$(TrimMode)" | ||
DefaultAction="$(TrimmerDefaultAction)" | ||
DefaultAction="$(_TrimmerDefaultAction)" | ||
RemoveSymbols="$(TrimmerRemoveSymbols)" | ||
FeatureSettings="@(_TrimmerFeatureSettings)" | ||
CustomData="@(_TrimmerCustomData)" | ||
|
@@ -212,6 +221,10 @@ Copyright (c) .NET Foundation. All rights reserved. | |
potentially problematic when warnings are suppressed. --> | ||
<NETSdkInformation Condition="'$(PublishTrimmed)' == 'true' And '$(SuppressTrimAnalysisWarnings)' == 'true'" ResourceName="ILLinkOptimizedAssemblies" /> | ||
|
||
<!-- In .NET 7, TrimmerDefaultAction is deprecated. TrimMode can be used for the supported configurations. --> | ||
<Warning Condition="'$(TrimmerDefaultAction)' != '' And $([MSBuild]::VersionGreaterThan('$(TargetFrameworkVersion)', '6.0'))" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change will need to be propagated to all SDKs like https://github.com/xamarin/xamarin-macios/blob/main/msbuild/Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Common.After.targets#L333 |
||
Text="Property 'TrimmerDefaultAction' is deprecated in .NET 7." /> | ||
agocke marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make the warning actionable - maybe just add "Please use TrimMode instead" or something like that. |
||
|
||
<!-- The defaults currently root non-framework assemblies, which | ||
is a no-op for portable apps. If we later support more ways | ||
to customize the behavior we can allow linking portable apps | ||
|
@@ -225,16 +238,9 @@ Copyright (c) .NET Foundation. All rights reserved. | |
<ILLinkWarningLevel Condition=" '$(ILLinkWarningLevel)' == '' ">0</ILLinkWarningLevel> | ||
</PropertyGroup> | ||
|
||
<!-- Defaults for .NET < 6 --> | ||
<PropertyGroup Condition=" $([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '6.0')) "> | ||
<TrimMode Condition=" '$(TrimMode)' == '' ">copyused</TrimMode> | ||
<!-- Action is the same regardless of whether the assembly has an IsTrimmable attribute. (The attribute didn't exist until .NET 6.) --> | ||
<TrimmerDefaultAction>$(TrimMode)</TrimmerDefaultAction> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TrimMode Condition=" '$(TrimMode)' == '' ">link</TrimMode> | ||
<!-- For .NET 6+, assemblies without IsTrimmable attribute get the "copy" action. --> | ||
<TrimmerDefaultAction Condition=" '$(TrimmerDefaultAction)' == '' ">copy</TrimmerDefaultAction> | ||
<!-- Set TrimmerDefaultAction for compat --> | ||
<_TrimmerDefaultAction>$(TrimmerDefaultAction)</_TrimmerDefaultAction> | ||
agocke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<ILLinkTreatWarningsAsErrors Condition=" '$(ILLinkTreatWarningsAsErrors)' == '' ">$(TreatWarningsAsErrors)</ILLinkTreatWarningsAsErrors> | ||
<_ExtraTrimmerArgs>--skip-unresolved true $(_ExtraTrimmerArgs)</_ExtraTrimmerArgs> | ||
<TrimmerSingleWarn Condition=" '$(TrimmerSingleWarn)' == '' ">true</TrimmerSingleWarn> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works - but I would prefer if we simply passed something like TargetFrameworkVersion - could be the same numerical value, but make it clear that it's the TFM version - I don't want to introduce yet another version number to think about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to introduce any version to this task. The task should aim to be a straightforward mapping to the command-line arguments. Introducing version-based logic here increases the probability that we set version-specific defaults in the task that can't be overridden by the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to make that work, but that means we have to do all of the mapping logic in MSBuild properties. That seems much harder to get right, and also very hard to test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have end-to-end tests that exercise the targets+task either way.
It is unfortunately harder to get right. I personally think that is a price worth paying: