-
-
Notifications
You must be signed in to change notification settings - Fork 223
fix: Native AOT linking #4298
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
fix: Native AOT linking #4298
Conversation
Without Directory.Build.props, nuget.config etc.
the integration test reads sentry version from there
Background: As you might notice from the commit history, I started with trying to make the existing integration test fail but eventually gave up. Since I had a set of commands (#4296 (comment)) I was able to use to reproduce the error locally, I decided to try running those in the CI. First, directly in the workflow for Linux, then as a manual test script for all platforms, and finally, I turned it into a Pester test script. The second last commit shows what kind of failures the new integration test produces when the properties are not correctly evaluated: ubuntu-22.04 (linux-x64)
https://github.com/getsentry/sentry-dotnet/actions/runs/15779751203/job/44482314804 windows-latest (win-x64)
https://github.com/getsentry/sentry-dotnet/actions/runs/15779751203/job/44482314808 |
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 but please make sure tests also pass on mac before merging:
Describing Publish
Determining projects to restore...
Restored /private/var/folders/x7/ch5v91h56_zbvbd1y2f600dm0000gn/T/qc3adnir.lmp/hello-sentry.csproj (in 1.45 sec).
Error: /private/var/folders/x7/ch5v91h56_zbvbd1y2f600dm0000gn/T/qc3adnir.lmp/Program.cs(1,1): error CS0103: The name 'SentrySdk' does not exist in the current context [/private/var/folders/x7/ch5v91h56_zbvbd1y2f600dm0000gn/T/qc3adnir.lmp/hello-sentry.csproj]
Workload updates are available. Run `dotnet workload list` for more information.
Error: [-] Aot 2.73s (2.[71](https://github.com/getsentry/sentry-dotnet/actions/runs/15780852336/job/44485984274?pr=4298#step:24:75)s|19ms)
Message
Expected 0, but got 1.
at $LASTEXITCODE | Should -Be 0, /Users/runner/work/sentry-dotnet/sentry-dotnet/integration-test/aot.Tests.ps1:52
at <ScriptBlock>, /Users/runner/work/sentry-dotnet/sentry-dotnet/integration-test/aot.Tests.ps1:52
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 really need to get to the bottom of why these props are not being read from:
sentry-dotnet/src/Sentry/buildTransitive/Sentry.props
Lines 5 to 7 in be9d67e
<_SentryTargetFrameworkVersion>$([MSBuild]::GetTargetFrameworkVersion($(TargetFramework)))</_SentryTargetFrameworkVersion> | |
<_SentryIsNet8OrGreater>$([MSBuild]::VersionGreaterThanOrEquals($(_SentryTargetFrameworkVersion), 8.0))</_SentryIsNet8OrGreater> | |
<_SentryIsNet9OrGreater>$([MSBuild]::VersionGreaterThanOrEquals($(_SentryTargetFrameworkVersion), 9.0))</_SentryIsNet9OrGreater> |
... and the closely related:
sentry-dotnet/Directory.Build.props
Lines 44 to 45 in be9d67e
Note: The following platform-specific properties need to be set in both Directory.Build.props and Directory.Build.targets. | |
TODO: Figure out how to consolidate to a single location. |
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.
Sentry.props
is read but before TargetFramework
is 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 don't think so no. See:
I think MS Build runs a couple of passes though... once to do stuff that is framework specific (when the TargetFramework
is set) and once to do stuff that is framework agnostic. That's why this condition was added to the props file:
<PropertyGroup Condition="'$(TargetFramework)' != ''"> |
In the experimenting that I did, the agnostic run seems to happen after the specific stuff.
Any code in the props/targets/csproj files that depends on the TargetFramework
being set really needs to be guarded by that condition then, since otherwise it will get executed with an effective target framework version of 0
(and likely do something unexpected).
All of this is just from experimenting and trying to reverse engineer it though... I'd feel way more comfortable if there were some docs somewhere explaining what the heck is going on. Whatever it is, it's not very intuitive.
This PR fixes a regression introduced by #4275: the
_SentryIsNet8OrGreater
helper property was not correctly evaluated when publishing AOT, and Sentry was used as a NuGet package.The newly introduced integration test creates a minimal AOT app out of the tree in the system temp directory, and tests both
PublishAot
and alsoPublishContainer
on Linux with Docker available.Fixes: #4296