-
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
Conversation
The new default for trimming is equivalent to TrimmerDefaultAction=link. Since we're trying to stay away from the term link and TrimmerDefaultAction isn't a very clear name, this change repurposes TrimMode. The two new TrimModes are 'full' and 'partial'. The new default is equivalent to 'TrimMode=full'. These new modes are also recognized for earlier TFMs, but the defaults are only changed for net7.0+
I pushed a lot of stuff in this change into the task for two reasons: 1) it was getting really complicated to do this in MSBuild properties, and 2) it was much easier to test. @MichalStrehovsky this will probably look different for NativeAOT, but I haven't looked at the code yet to see how. |
This should root all non-trimmable assemblies, same as TrimmerDefaultAction=copy. We still support consuming ILCompiler through NuGet when targeting .NET 6, so recognize the old thing too. We might want to cut the .NET 6 support close to RC and at that time TrimmerDefaultAction handling can go away. Related: dotnet/linker#2856.
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.
Looks good to me but I would like Sven to see this too.
Happy to see the TrimMode/TrimmerDefaultAction confusion going away. I kept telling people to forget TrimMode exists. It's now getting a new/better life.
I assume we'll make sure ASP.NET doesn't get insta-broken by this by adding a <TrimMode>partial</>
somewhere in their SDK.
src/ILLink.Tasks/LinkTask.cs
Outdated
/// Roughly maps to the TargetFrameworkVersion. | ||
/// </summary> | ||
[Required] | ||
public int LinkVersion { get; set; } |
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:
- to make sure we don't break the ability to override defaults, and
- to keep the task a thin wrapper for the tool (unless we want to introduce TFM-versioned logic to the tool itself).
<!-- 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> |
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.
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 comment
The 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 comment
The 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)
<!-- In .NET 7, TrimmerDefaultAction is deprecated. TrimMode can be used for the supported configurations. --> | ||
<Warning Condition="'$(TrimmerDefaultAction)' != '' And $([MSBuild]::VersionGreaterThan('$(TargetFrameworkVersion)', '6.0'))" | ||
Text="Property 'TrimmerDefaultAction' is deprecated in .NET 7." /> |
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.
Please make the warning actionable - maybe just add "Please use TrimMode instead" or something like that.
This will also need a change in xamarin-android since they set the TrimmerDefaultAction: https://github.com/xamarin/xamarin-android/blob/2ca2a103d4e473eeeceecd7689961038bb374cdb/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets#L67 /cc @jonathanpeppers |
@@ -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 comment
The 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
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.
It might be worth running the SDK tests locally against this change to catch any breaks before insertion.
src/ILLink.Tasks/LinkTask.cs
Outdated
/// Roughly maps to the TargetFrameworkVersion. | ||
/// </summary> | ||
[Required] | ||
public int LinkVersion { get; set; } |
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.
In the process of switching over to setting defaults in the targets, but fixing things up in the tasks (with the intent of eventually passing things all the way through to the linker). I still have to set up SDK testing for this. |
Companion to dotnet/linker#2856
Companion to dotnet/linker#2856
What's the actual semantics between these modes? I'm guessing that:
Is this correct? |
Yup that’s right |
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.
LGTM, thanks a lot!
This should root all non-trimmable assemblies, same as TrimmerDefaultAction=copy. We still support consuming ILCompiler through NuGet when targeting .NET 6, so recognize the old thing too. We might want to cut the .NET 6 support close to RC and at that time TrimmerDefaultAction handling can go away. Related: dotnet/linker#2856.
Companion to dotnet/linker#2856 * Update src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets * Remove more usages of TrimMode * Update linker versions manually Co-authored-by: Jonathan Peppers <[email protected]>
Companion to dotnet/linker#2856 * Update src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets * Remove more usages of TrimMode * Update linker versions manually Co-authored-by: Jonathan Peppers <[email protected]>
Changes: dotnet/installer@85a0482...a9c056c Changes: dotnet/linker@ef2d0f2...d27ff61 Changes: dotnet/runtime@206dccb...072eda8 Changes: dotnet/emsdk@40e7c62...11a9acf Updates: * Microsoft.Dotnet.Sdk.Internal: from 7.0.100-preview.7.22361.1 to 7.0.100-rc.1.22368.2 * Microsoft.NET.ILLink.Tasks: from 7.0.100-1.22354.1 to 7.0.100-1.22365.1 * Microsoft.NETCore.App.Ref: from 7.0.0-preview.6.22356.1 to 7.0.0-rc.1.22366.5 * Microsoft.NET.Workload.Emscripten.Manifest-7.0.100: from 7.0.0-preview.7.22330.1 to 7.0.0-rc.1.22362.2 ~~ Set `$(TrimMode)` `partial` by default (#7132) ~~ Companion to dotnet/linker#2856 * Update src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets * Remove usages of `%(TrimMode)` for `$(AndroidLinkMode)` of `Full` * Update .apkdesc files ~~ Set `$(LangVersion)` to 10 in Mono.Android.csproj ~~ There appears to be a C# 11 IL size regression in: dotnet/roslyn#62832 We can use C# 10 for now to avoid this. * Fixed `Mono.Android.dll` size in `.apkdesc` files Co-authored-by: Andy Gocke <[email protected]> Co-authored-by: Jonathan Peppers <[email protected]>
Changes: dotnet/installer@d2fff6d...dbdda95 Changes: dotnet/linker@ef2d0f2...33a76b8 Changes: dotnet/runtime@206dccb...db5d4df Changes: dotnet/emsdk@40e7c62...7d27778 Updates: * Microsoft.Dotnet.Sdk.Internal: from 7.0.100-preview.7.22362.31 to 7.0.100-preview.7.22370.3 * Microsoft.NET.ILLink.Tasks: from 7.0.100-1.22354.1 to 7.0.100-1.22362.1 * Microsoft.NETCore.App.Ref: from 7.0.0-preview.6.22356.1 to 7.0.0-preview.7.22369.4 * Microsoft.NET.Workload.Emscripten.Manifest-7.0.100: from 7.0.0-preview.7.22330.1 to 7.0.0-preview.7.22361.2 ~~ Set `$(TrimMode)` `partial` by default (#7132) ~~ Companion to dotnet/linker#2856 * Update src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets * Remove usages of `%(TrimMode)` for `$(AndroidLinkMode)` of `Full` * Update .apkdesc files ~~ Set `$(LangVersion)` to 10 in Mono.Android.csproj ~~ There appears to be a C# 11 IL size regression in: dotnet/roslyn#62832 We can use C# 10 for now to avoid this. * Fixed `Mono.Android.dll` size in `.apkdesc` files Co-authored-by: Andy Gocke <[email protected]> Co-authored-by: Jonathan Peppers <[email protected]>
…ker#2856) The new default for trimming is equivalent to TrimmerDefaultAction=link. Since we're trying to stay away from the term link and TrimmerDefaultAction isn't a very clear name, this change repurposes TrimMode. The two new TrimModes are 'full' and 'partial'. The new default is equivalent to 'TrimMode=full'. These new modes are also recognized for earlier TFMs, but the defaults are only changed for net7.0+. Commit migrated from dotnet/linker@b6f1fb4
The new default for trimming is equivalent to TrimmerDefaultAction=link.
Since we're trying to stay away from the term link and TrimmerDefaultAction
isn't a very clear name, this change repurposes TrimMode.
The two new TrimModes are 'full' and 'partial'. The new default is equivalent
to 'TrimMode=full'. These new modes are also recognized for earlier TFMs, but
the defaults are only changed for net7.0+