-
Notifications
You must be signed in to change notification settings - Fork 522
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
Do not suppress trim analysis warnings when NativeAOT is enabled #20767
Do not suppress trim analysis warnings when NativeAOT is enabled #20767
Conversation
f220e23
to
d44d2c4
Compare
@rolfbjarne do you think this change (if approved) should go into |
This comment has been minimized.
This comment has been minimized.
/azp run |
Azure Pipelines successfully started running 1 pipeline(s), but failed to run 2 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
/azp run |
Had to re-trigger, something funny was going on with VSTS. |
Azure Pipelines successfully started running 2 pipeline(s), but failed to run 1 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@@ -150,13 +150,13 @@ | |||
</PropertyGroup> | |||
<PropertyGroup Condition="'$(TrimMode)' == ''"> | |||
<!-- Linking is always on for all assemblies when using NativeAOT - this is because we need to modify all assemblies in the linker for them to be compatible with NativeAOT --> | |||
<_DefaultLinkMode Condition="'$(_UseNativeAot)' == 'true'">Full</_DefaultLinkMode> | |||
<_DefaultLinkMode Condition="'$(PublishAot)' == 'true'">Full</_DefaultLinkMode> |
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 will slow down debug/simulator builds significantly.
How does this work in desktop/console apps? Will setting PublishAot=true enable the trimmer for debug builds as well?
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 wanted to align projects with <PublishAot>true</PublishAot>
with projects that have <TrimMode>full</TrimMode>
. Now that you pointed this out, I'm realizing that we're telling devs to only enable TrimMode=full in Release builds and not in Debug builds and this change is incorrect.
The goal of this PR is to make sure we don't suppress trimming warnings in Debug builds so I'll make sure to achieve that without changing the trim mode.
/cc @ivanpovazan
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.
How does this work in desktop/console apps? Will setting PublishAot=true enable the trimmer for debug builds as well?
Yes, when we set PublishAot=true
debug builds will enable trim analyzers:
ivanpovazan@EONE-MAC-ARM64 ~/tmp/abcd $ dotnet build -c Debug -p:PublishAot=true
Restore complete (0.7s)
You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
abcd succeeded with 1 warning(s) (0.4s) → bin/Debug/net9.0/abcd.dll
/Users/ivan/tmp/abcd/Program.cs(9,21): warning IL2075: 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'System.Type.GetProperties()'. The return value of method 'System.Object.GetType()' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to.
Build succeeded with 1 warning(s) in 1.3s
Workload updates are available. Run `dotnet workload list` for more information.
ivanpovazan@EONE-MAC-ARM64 ~/tmp/abcd $ rm -rf bin obj
ivanpovazan@EONE-MAC-ARM64 ~/tmp/abcd $ dotnet build -c Debug -p:PublishAot=false
Restore complete (0.5s)
You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
abcd succeeded (0.4s) → bin/Debug/net9.0/abcd.dll
Build succeeded in 1.1s
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
In the case of NativeAOT builds, the trim warnings will be produced either by the ILLink roslyn analyzer in Debug builds | ||
or by the ILC when publishing. We want to suppress the ILLink warnings in all build configurations to avoid duplicates. | ||
--> | ||
<SuppressTrimAnalysisWarnings Condition="'$(PublishAot)' == '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.
I think this should be:
<SuppressTrimAnalysisWarnings Condition="'$(PublishAot)' == 'true'">true</SuppressTrimAnalysisWarnings> | |
<SuppressTrimAnalysisWarnings Condition="'$(PublishAot)' == 'true' And '$(_IsPublishing)' != 'true'">true</SuppressTrimAnalysisWarnings> |
As we could have a project file with both '$(TrimMode)' == 'full'
and '$(PublishAot)' == 'true'.
If that is the case and we do dotnet build
, ILC will not run, so we want warnings from ILLink.
When both PublishAot
and _IsPublishing
are true
aka _UseNativeAot=true
we already suppress the warnings in props, so we got that covered.
FWIW, to avoid confusion, I think we should rename _UseNativeAot
to something like _PublishWithNativeAot
or something like that.
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.
Changing this condition won't make any difference, but it might make it a bit more confusing and harder to follow the values of SuppressTrimAnalysisWarnings
. "Why shouldn't this be set to true
when publishing?" I don't have a strong preference but I would lean towards keeping the condition simple.
I agree that _UseNativeAot
is a bit confusing. It's a combination of PublishAot
and _IsPublishing
so I suggest _IsPublishingUsingNativeAot
or _IsPublishingWithNativeAot
.
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.
Changing this condition won't make any difference
Yes, you are right, my suggestion was not correct, and it should include check on TrimMode
as well.
With the current state of the condition, users who have their project files configured like:
<TrimMode>full</TrimMode>
<PublishAot>true</PublishAot>
and do dotnet build
will not see any warnings:
- from ILLink, because we suppress warnings here based on just
PublishAot
- from ILC, because they are running
build
instead ofpublish
<!-- Suppress trimmer warnings unless we're trimming all assemblies --> | ||
<SuppressTrimAnalysisWarnings Condition="'$(SuppressTrimAnalysisWarnings)' == '' And '$(TrimMode)' == 'full'">false</SuppressTrimAnalysisWarnings> | ||
<SuppressTrimAnalysisWarnings Condition="'$(SuppressTrimAnalysisWarnings)' == ''">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.
Yes, it looks like all the SuppressTrimAnalysisWarnings property setters here are no-ops, because SuppressTrimAnalysisWarnings shouldn't be empty at this point.
Then below, add the _ExtraTrimmerArgs like this:
<_ExtraTrimmerArgs Condition="'$(SuppressTrimAnalysisWarnings)' == 'true' Or '$(_UseNativeAot)' == 'true'">$(_ExtraTrimmerArgs) --notrimwarn</_ExtraTrimmerArgs>
This way we'll:
- Suppress ILLink's trimmer warnings when using NativeAOT
- Honor SuppressTrimAnalysisWarnings otherwise.
Btw the test now fails with:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@rolfbjarne with the changes in the last comment, the new tests are now passing (finally). There are just failing Windows tests but I saw this on other PRs and the error message hints that this is an infra issue and not related to this PR:
|
<!-- | ||
In the case of NativeAOT builds, the trim warnings will be produced either by the ILLink roslyn analyzer in Debug builds | ||
or by the ILC when publishing. We want to suppress the ILLink warnings in all build configurations to avoid duplicates. | ||
We choose not to suppress the ILLink warnings when TrimMode is set to 'full' and we're not publishing. In this scenario | ||
ILC will not run at a later stage of the build. | ||
--> | ||
<SuppressTrimAnalysisWarnings Condition="'$(PublishAot)' == 'true' And '$(_IsPublishing)' != 'true' And '$(TrimMode)' != 'full'">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.
@jonathanpeppers regarding your changes for Android:
We will need to add something like this in: https://github.com/dotnet/android/blob/77f5fdd1d32b6ff2a2b36008f966cb4abffb8231/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.ILLink.targets#L12
and additionally the changes from lines 659-661:
https://github.com/xamarin/xamarin-macios/pull/20767/files#diff-2e24f1b6f44df7580244d00f106fa1a9e2257536fbca9d7bbdc74571549324a9R659-R661
the only difference would be that we would exchange PublishAot
with IsAotCompatible
📚 [CI Build] Artifacts 📚Packages generatedView packagesPipeline on Agent |
💻 [CI Build] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
❌ [CI Build] Windows Integration Tests failed ❌❌ Failed ❌ Pipeline on Agent |
💻 [CI Build] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
💻 [CI Build] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
🚀 [CI Build] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 170 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
The windows test failure is a known issue. |
We noticed we weren't seeing trim analysis warnings in VS Code when PublishAot was set to true. There was a recent change that correctly disabled the suppressions when TrimMode is full. We need to make sure that we're also getting the trim analysis warnings in dotnet build with PublishAot but suppress them when publishing (in that case the warnings will come later from ILC). This PR aligns the behavior of PublishAot=true and TrimMode=true in debug builds.
/cc @ivanpovazan @rolfbjarne @jonathanpeppers