Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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: 8 additions & 0 deletions .github/actions/environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ runs:
shell: bash
run: sudo chmod 666 /var/run/docker.sock

- name: Install Linux ARM 32-bit dependencies
if: ${{ matrix.rid == 'linux-arm' }}
shell: bash
run: |
sudo dpkg --add-architecture armhf
sudo apt-get update
sudo apt-get install -y gcc-arm-linux-gnueabihf libc6:armhf

# zstd is needed for cross OS actions/cache but missing from windows-11-arm
# https://github.com/actions/partner-runner-images/issues/99
- name: Install zstd on Windows ARM64
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,47 @@ jobs:
msbuild.binlog
if-no-files-found: ignore

# Unsupported Native AOT runtimes should have SentryNative auto-disabled
# to avoid native library loading errors on startup.
unsupported-aot:
needs: build
name: Unsupported AOT (${{ matrix.rid }})
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04-arm
rid: linux-arm
- os: windows-latest
rid: win-x86

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup Environment
uses: ./.github/actions/environment

- name: Build Native Dependencies
uses: ./.github/actions/buildnative

- name: Fetch NuGet Packages
uses: actions/download-artifact@v4
with:
name: ${{ github.sha }}
path: src

- name: Test AOT
uses: getsentry/github-workflows/sentry-cli/integration-test/@v2
env:
RuntimeIdentifier: ${{ matrix.rid }}
with:
path: integration-test/aot.Tests.ps1

trim-analysis:
needs: build-sentry-native
name: Trim analysis
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

- Native AOT: don't load SentryNative on unsupported platforms ([#4347](https://github.com/getsentry/sentry-dotnet/pull/4347))

### Dependencies

- Bump CLI from v2.47.0 to v2.47.1 ([#4348](https://github.com/getsentry/sentry-dotnet/pull/4348))
Expand Down
15 changes: 13 additions & 2 deletions integration-test/aot.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,22 @@ Console.WriteLine("Hello, Sentry!");
}

It 'Aot' {
dotnet publish -c Release | Write-Host
$rid = $env:RuntimeIdentifier
if ($rid)
{
dotnet publish -c Release -r $rid | Write-Host
}
else
{
dotnet publish -c Release | Write-Host
}
$LASTEXITCODE | Should -Be 0

$tfm = (Get-ChildItem -Path "bin/Release" -Directory | Select-Object -First 1).Name
$rid = (Get-ChildItem -Path "bin/Release/$tfm" -Directory | Select-Object -First 1).Name
if (-not $rid)
{
$rid = (Get-ChildItem -Path "bin/Release/$tfm" -Directory | Select-Object -First 1).Name
}
& "bin/Release/$tfm/$rid/publish/hello-sentry" | Write-Host
$LASTEXITCODE | Should -Be 0
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry/Platforms/Native/SentryNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static class SentryNative
// This way, `SentryNative.IsEnabled` should be treated as a compile-time constant for trimmed apps.
[FeatureSwitchDefinition(SentryNativeIsEnabledSwitchName)]
#endif
private static bool IsEnabled => !AppContext.TryGetSwitch(SentryNativeIsEnabledSwitchName, out var isEnabled) || isEnabled;
private static bool IsEnabled => AppContext.TryGetSwitch(SentryNativeIsEnabledSwitchName, out var isEnabled) && isEnabled;
Comment thread
jpnurmi marked this conversation as resolved.

internal static bool IsAvailable => IsEnabled && IsAvailableCore;

Expand Down
31 changes: 19 additions & 12 deletions src/Sentry/Platforms/Native/buildTransitive/Sentry.Native.targets
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@
Note:Target framework conditions should be kept synchronized with src/Sentry/buildTransitive/Sentry.Native.targets -->
<Project>

<ItemGroup>
<!-- When user sets <SentryNative>false</SentryNative> or <SentryNative>disable</SentryNative> in their project -->
<!-- SentryNative.IsEnabled should result in compile-time constant for trimmed applications -->
<!-- Effectively disabling native library -->
<RuntimeHostConfigurationOption Include="Sentry.Native.IsEnabled"
Condition="'$(SentryNative)' == 'false' or '$(SentryNative)' == 'disable'"
Value="false"
Trim="true" />
</ItemGroup>

<!-- Helpful properties copied from Sentry.props -->
<PropertyGroup Condition="'$(TargetFramework)' != ''">
<_SentryTargetFrameworkVersion>$([MSBuild]::GetTargetFrameworkVersion($(TargetFramework)))</_SentryTargetFrameworkVersion>
Expand All @@ -26,12 +16,29 @@
</PropertyGroup>

<PropertyGroup>
<!-- Windows -->
<FrameworkSupportsNative Condition="'$(RuntimeIdentifier)' == 'win-x64' or '$(RuntimeIdentifier)' == 'win-arm64'">true</FrameworkSupportsNative>
<!-- Linux -->
<FrameworkSupportsNative Condition="'$(RuntimeIdentifier)' == 'linux-x64' or '$(RuntimeIdentifier)' == 'linux-arm64' or '$(RuntimeIdentifier)' == 'linux-musl-x64'">true</FrameworkSupportsNative>
<!-- macOS -->
<FrameworkSupportsNative Condition="'$(RuntimeIdentifier)' == 'osx-x64' or '$(RuntimeIdentifier)' == 'osx-arm64'">true</FrameworkSupportsNative>
<!-- net8.0 or greater -->
<FrameworkSupportsNative Condition="'$(_SentryIsNet8OrGreater)' == 'true' and ('$(OutputType)' == 'Exe' or '$(OutputType)' == 'WinExe')">true</FrameworkSupportsNative>
<!-- Make it opt-out -->
<FrameworkSupportsNative Condition="'$(_SentryIsNet8OrGreater)' != 'true' or !('$(OutputType)' == 'Exe' or '$(OutputType)' == 'WinExe')">false</FrameworkSupportsNative>
<!-- Make it opt-in/out -->
<FrameworkSupportsNative Condition="'$(SentryNative)' == 'true' or '$(SentryNative)' == 'enable'">true</FrameworkSupportsNative>
<FrameworkSupportsNative Condition="'$(SentryNative)' == 'false' or '$(SentryNative)' == 'disable'">false</FrameworkSupportsNative>
Comment thread
jpnurmi marked this conversation as resolved.
</PropertyGroup>

<ItemGroup>
<!-- When user sets <SentryNative>false</SentryNative> or <SentryNative>disable</SentryNative> in their project -->
<!-- SentryNative.IsEnabled should result in compile-time constant for trimmed applications -->
<!-- Effectively disabling native library -->
<RuntimeHostConfigurationOption Include="Sentry.Native.IsEnabled"
Condition="'$(FrameworkSupportsNative)' == 'true'"
Value="true"
Trim="true" />
</ItemGroup>

<ItemGroup Condition="'$(FrameworkSupportsNative)' == 'true' and ('$(RuntimeIdentifier)' == 'win-x64' or '$(RuntimeIdentifier)' == 'win-arm64')">
<DirectPInvoke Include="sentry-native" />
<NativeLibrary Include="$(MSBuildThisFileDirectory)..\sentry-native\$(RuntimeIdentifier)\sentry-native.lib" />
Expand Down
Loading