diff --git a/.github/actions/environment/action.yml b/.github/actions/environment/action.yml index 3820c61c4a..2a08e3d095 100644 --- a/.github/actions/environment/action.yml +++ b/.github/actions/environment/action.yml @@ -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 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bcb5af4243..731ec91d3b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index e04f22bc4f..3758187a1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/integration-test/aot.Tests.ps1 b/integration-test/aot.Tests.ps1 index 24dbc8e800..14849c332f 100644 --- a/integration-test/aot.Tests.ps1 +++ b/integration-test/aot.Tests.ps1 @@ -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 } diff --git a/src/Sentry/Platforms/Native/SentryNative.cs b/src/Sentry/Platforms/Native/SentryNative.cs index ed0c5cbbbc..c624d69e78 100644 --- a/src/Sentry/Platforms/Native/SentryNative.cs +++ b/src/Sentry/Platforms/Native/SentryNative.cs @@ -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; internal static bool IsAvailable => IsEnabled && IsAvailableCore; diff --git a/src/Sentry/Platforms/Native/buildTransitive/Sentry.Native.targets b/src/Sentry/Platforms/Native/buildTransitive/Sentry.Native.targets index c9ee5a0d85..f2292d9a2c 100644 --- a/src/Sentry/Platforms/Native/buildTransitive/Sentry.Native.targets +++ b/src/Sentry/Platforms/Native/buildTransitive/Sentry.Native.targets @@ -8,16 +8,6 @@ Note:Target framework conditions should be kept synchronized with src/Sentry/buildTransitive/Sentry.Native.targets --> - - - - - - - <_SentryTargetFrameworkVersion>$([MSBuild]::GetTargetFrameworkVersion($(TargetFramework))) @@ -26,12 +16,29 @@ + + true + + true + + true - true - + false + + true false + + + + + + +