Skip to content

Commit 6845e75

Browse files
authored
fix: support musl on Linux (#4188)
* fix: support musl on Linux * ci: build linux-musl-x64
1 parent d622ff2 commit 6845e75

File tree

10 files changed

+167
-10
lines changed

10 files changed

+167
-10
lines changed

.github/actions/environment/action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ runs:
1111
echo "DOTNET_CLI_TELEMETRY_OPTOUT=1" >> $GITHUB_ENV
1212
echo "DOTNET_NOLOGO=1" >> $GITHUB_ENV
1313
14+
# Android SDK Build Tools are musl-incompatible
15+
- name: Set Environment Variables for Alpine Linux
16+
if: ${{ contains(matrix.container, 'alpine') }}
17+
shell: bash
18+
run: echo "NO_MOBILE=true" >> $GITHUB_ENV
19+
1420
# zstd is needed for cross OS actions/cache but missing from windows-11-arm
1521
# https://github.com/actions/partner-runner-images/issues/99
1622
- name: Install zstd on Windows ARM64
@@ -26,18 +32,21 @@ runs:
2632

2733
# Java 17 is needed for Android SDK setup step
2834
- name: Install Java 17
35+
if: ${{ !matrix.container }}
2936
uses: actions/setup-java@v4
3037
with:
3138
distribution: ${{ runner.os == 'Windows' && runner.arch == 'ARM64' && 'microsoft' || 'temurin' }}
3239
java-version: '17'
3340

3441
- name: Setup Android SDK
42+
if: ${{ !matrix.container }}
3543
uses: android-actions/setup-android@07976c6290703d34c16d382cb36445f98bb43b1f # v3.2.0
3644
with:
3745
log-accepted-android-sdk-licenses: false
3846

3947
# Java 11 is needed by .NET Android
4048
- name: Install Java 11
49+
if: ${{ !matrix.container }}
4150
uses: actions/setup-java@v4
4251
with:
4352
distribution: ${{ runner.os == 'Windows' && runner.arch == 'ARM64' && 'microsoft' || 'temurin' }}

.github/workflows/build.yml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ on:
1111

1212
jobs:
1313
build-sentry-native:
14-
name: sentry-native (${{ matrix.os }})
14+
name: sentry-native (${{ matrix.container || matrix.os }})
1515
runs-on: ${{ matrix.os }}
16+
container: ${{ matrix.container }}
1617
strategy:
1718
fail-fast: false
1819
matrix:
1920
include:
2021
- os: ubuntu-22.04 # Pin ubuntu to ensure mono is installed
22+
- os: ubuntu-latest
23+
target: Linux-musl
24+
container: ghcr.io/getsentry/sentry-dotnet-alpine:3.21
2125
- os: macos-15 # Pin macos to get the version of Xcode that we need: https://github.com/actions/runner-images/issues/10703
2226
- os: windows-latest
2327
- os: windows-11-arm
@@ -44,10 +48,11 @@ jobs:
4448
enableCrossOsArchive: true
4549

4650
- name: Remove unused applications
51+
if: ${{ !matrix.container }}
4752
uses: ./.github/actions/freediskspace
4853

4954
- name: Install build dependencies
50-
if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'Linux'
55+
if: steps.cache.outputs.cache-hit != 'true' && runner.os == 'Linux' && !matrix.container
5156
run: |
5257
sudo apt update
5358
sudo apt install libcurl4-openssl-dev
@@ -58,14 +63,18 @@ jobs:
5863

5964
build:
6065
needs: build-sentry-native
61-
name: .NET (${{ matrix.os }})
66+
name: .NET (${{ matrix.container || matrix.os }})
6267
runs-on: ${{ matrix.os }}
68+
container: ${{ matrix.container }}
6369

6470
strategy:
6571
fail-fast: false
6672
matrix:
6773
include:
6874
- os: ubuntu-22.04 # Pin ubuntu to ensure mono is installed
75+
- os: ubuntu-latest
76+
target: Linux-musl
77+
container: ghcr.io/getsentry/sentry-dotnet-alpine:3.21
6978
- os: macos-15 # Pin macos to get the version of Xcode that we need: https://github.com/actions/runner-images/issues/10703
7079
- os: windows-latest
7180
- os: windows-11-arm
@@ -83,6 +92,7 @@ jobs:
8392
fetch-depth: 2 # default is 1 and codecov needs > 1
8493

8594
- name: Remove unused applications
95+
if: ${{ !matrix.container }}
8696
uses: ./.github/actions/freediskspace
8797

8898
- name: Setup Environment
@@ -94,13 +104,21 @@ jobs:
94104
run: echo "CI_PUBLISHING_BUILD=true" >> $GITHUB_ENV
95105

96106
- name: Download sentry-native (Linux)
97-
if: ${{ (env.CI_PUBLISHING_BUILD == 'true') || (runner.os == 'Linux') }}
107+
if: ${{ (env.CI_PUBLISHING_BUILD == 'true') || (runner.os == 'Linux' && !matrix.container) }}
98108
uses: actions/cache/restore@v4
99109
with:
100110
path: src/Sentry/Platforms/Native/sentry-native
101111
key: sentry-native-Linux-${{ hashFiles('scripts/build-sentry-native.ps1') }}-${{ hashFiles('.git/modules/modules/sentry-native/HEAD') }}
102112
fail-on-cache-miss: true
103113

114+
- name: Download sentry-native (Linux musl)
115+
if: ${{ (env.CI_PUBLISHING_BUILD == 'true') || (matrix.target == 'Linux-musl') }}
116+
uses: actions/cache/restore@v4
117+
with:
118+
path: src/Sentry/Platforms/Native/sentry-native
119+
key: sentry-native-Linux-musl-${{ hashFiles('scripts/build-sentry-native.ps1') }}-${{ hashFiles('.git/modules/modules/sentry-native/HEAD') }}
120+
fail-on-cache-miss: true
121+
104122
- name: Download sentry-native (macOS)
105123
if: ${{ (env.CI_PUBLISHING_BUILD == 'true') || (runner.os == 'macOS') }}
106124
uses: actions/cache/restore@v4
@@ -128,6 +146,7 @@ jobs:
128146
enableCrossOsArchive: true
129147

130148
- name: Build Native Dependencies
149+
if: ${{ !matrix.container }}
131150
uses: ./.github/actions/buildnative
132151

133152
- name: Restore .NET Dependencies
@@ -175,14 +194,17 @@ jobs:
175194
176195
integration-test:
177196
needs: build
178-
name: Integration test (${{ matrix.os }})
197+
name: Integration test (${{ matrix.container || matrix.os }})
179198
runs-on: ${{ matrix.os }}
199+
container: ${{ matrix.container }}
180200

181201
strategy:
182202
fail-fast: false
183203
matrix:
184204
include:
185205
- os: ubuntu-22.04 # Pin ubuntu to ensure mono is installed
206+
- os: ubuntu-latest
207+
container: ghcr.io/getsentry/sentry-dotnet-alpine:3.21
186208
- os: macos-15 # Pin macos to get the version of Xcode that we need: https://github.com/actions/runner-images/issues/10703
187209
- os: windows-latest
188210
- os: windows-11-arm
@@ -204,7 +226,7 @@ jobs:
204226
path: src
205227

206228
- name: Install build dependencies
207-
if: runner.os == 'Linux'
229+
if: runner.os == 'Linux' && !matrix.container
208230
run: |
209231
sudo apt update
210232
sudo apt install libcurl4-openssl-dev

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Support musl on Linux ([#4188](https://github.com/getsentry/sentry-dotnet/pull/4188))
8+
39
## 5.8.0
410

511
### Features

Sentry-CI-Build-Linux-musl.slnf

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"solution": {
3+
"path": "Sentry.sln",
4+
"projects": [
5+
"benchmarks\\Sentry.Benchmarks\\Sentry.Benchmarks.csproj",
6+
"samples\\Sentry.Samples.AspNetCore.Basic\\Sentry.Samples.AspNetCore.Basic.csproj",
7+
"samples\\Sentry.Samples.AspNetCore.Blazor.Server\\Sentry.Samples.AspNetCore.Blazor.Server.csproj",
8+
"samples\\Sentry.Samples.AspNetCore.Blazor.Wasm\\Sentry.Samples.AspNetCore.Blazor.Wasm.csproj",
9+
"samples\\Sentry.Samples.AspNetCore.Grpc\\Sentry.Samples.AspNetCore.Grpc.csproj",
10+
"samples\\Sentry.Samples.AspNetCore.Mvc\\Sentry.Samples.AspNetCore.Mvc.csproj",
11+
"samples\\Sentry.Samples.AspNetCore.Serilog\\Sentry.Samples.AspNetCore.Serilog.csproj",
12+
"samples\\Sentry.Samples.AspNetCore.WebAPI.Profiling\\Sentry.Samples.AspNetCore.WebAPI.Profiling.csproj",
13+
"samples\\Sentry.Samples.Aws.Lambda.AspNetCoreServer\\Sentry.Samples.Aws.Lambda.AspNetCoreServer.csproj",
14+
"samples\\Sentry.Samples.Azure.Functions.Worker\\Sentry.Samples.Azure.Functions.Worker.csproj",
15+
"samples\\Sentry.Samples.Console.Basic\\Sentry.Samples.Console.Basic.csproj",
16+
"samples\\Sentry.Samples.Console.Customized\\Sentry.Samples.Console.Customized.csproj",
17+
"samples\\Sentry.Samples.Console.HeapDump\\Sentry.Samples.Console.HeapDump.csproj",
18+
"samples\\Sentry.Samples.Console.Native\\Sentry.Samples.Console.Native.csproj",
19+
"samples\\Sentry.Samples.Console.Profiling\\Sentry.Samples.Console.Profiling.csproj",
20+
"samples\\Sentry.Samples.EntityFramework\\Sentry.Samples.EntityFramework.csproj",
21+
"samples\\Sentry.Samples.GenericHost\\Sentry.Samples.GenericHost.csproj",
22+
"samples\\Sentry.Samples.Google.Cloud.Functions\\Sentry.Samples.Google.Cloud.Functions.csproj",
23+
"samples\\Sentry.Samples.GraphQL.Client.Http\\Sentry.Samples.GraphQL.Client.Http.csproj",
24+
"samples\\Sentry.Samples.GraphQL.Server\\Sentry.Samples.GraphQL.Server.csproj",
25+
"samples\\Sentry.Samples.Hangfire\\Sentry.Samples.Hangfire.csproj",
26+
"samples\\Sentry.Samples.Log4Net\\Sentry.Samples.Log4Net.csproj",
27+
"samples\\Sentry.Samples.ME.Logging\\Sentry.Samples.ME.Logging.csproj",
28+
"samples\\Sentry.Samples.NLog\\Sentry.Samples.NLog.csproj",
29+
"samples\\Sentry.Samples.OpenTelemetry.AspNetCore\\Sentry.Samples.OpenTelemetry.AspNetCore.csproj",
30+
"samples\\Sentry.Samples.OpenTelemetry.Console\\Sentry.Samples.OpenTelemetry.Console.csproj",
31+
"samples\\Sentry.Samples.Serilog\\Sentry.Samples.Serilog.csproj",
32+
"src\\Sentry.Analyzers\\Sentry.Analyzers.csproj",
33+
"src\\Sentry.AspNetCore.Blazor.WebAssembly\\Sentry.AspNetCore.Blazor.WebAssembly.csproj",
34+
"src\\Sentry.AspNetCore.Grpc\\Sentry.AspNetCore.Grpc.csproj",
35+
"src\\Sentry.AspNetCore\\Sentry.AspNetCore.csproj",
36+
"src\\Sentry.Azure.Functions.Worker\\Sentry.Azure.Functions.Worker.csproj",
37+
"src\\Sentry.DiagnosticSource\\Sentry.DiagnosticSource.csproj",
38+
"src\\Sentry.EntityFramework\\Sentry.EntityFramework.csproj",
39+
"src\\Sentry.Extensions.Logging\\Sentry.Extensions.Logging.csproj",
40+
"src\\Sentry.Google.Cloud.Functions\\Sentry.Google.Cloud.Functions.csproj",
41+
"src\\Sentry.Hangfire\\Sentry.Hangfire.csproj",
42+
"src\\Sentry.Log4Net\\Sentry.Log4Net.csproj",
43+
"src\\Sentry.NLog\\Sentry.NLog.csproj",
44+
"src\\Sentry.OpenTelemetry\\Sentry.OpenTelemetry.csproj",
45+
"src\\Sentry.Profiling\\Sentry.Profiling.csproj",
46+
"src\\Sentry.Serilog\\Sentry.Serilog.csproj",
47+
"src\\Sentry.SourceGenerators\\Sentry.SourceGenerators.csproj",
48+
"src\\Sentry\\Sentry.csproj",
49+
"test\\Sentry.Analyzers.Tests\\Sentry.Analyzers.Tests.csproj",
50+
"test\\Sentry.AspNet.Tests\\Sentry.AspNet.Tests.csproj",
51+
"test\\Sentry.AspNetCore.Grpc.Tests\\Sentry.AspNetCore.Grpc.Tests.csproj",
52+
"test\\Sentry.AspNetCore.Tests\\Sentry.AspNetCore.Tests.csproj",
53+
"test\\Sentry.AspNetCore.TestUtils\\Sentry.AspNetCore.TestUtils.csproj",
54+
"test\\Sentry.Azure.Functions.Worker.Tests\\Sentry.Azure.Functions.Worker.Tests.csproj",
55+
"test\\Sentry.DiagnosticSource.IntegrationTests\\Sentry.DiagnosticSource.IntegrationTests.csproj",
56+
"test\\Sentry.DiagnosticSource.Tests\\Sentry.DiagnosticSource.Tests.csproj",
57+
"test\\Sentry.EntityFramework.Tests\\Sentry.EntityFramework.Tests.csproj",
58+
"test\\Sentry.Extensions.Logging.Tests\\Sentry.Extensions.Logging.Tests.csproj",
59+
"test\\Sentry.Google.Cloud.Functions.Tests\\Sentry.Google.Cloud.Functions.Tests.csproj",
60+
"test\\Sentry.Hangfire.Tests\\Sentry.Hangfire.Tests.csproj",
61+
"test\\Sentry.Log4Net.Tests\\Sentry.Log4Net.Tests.csproj",
62+
"test\\Sentry.NLog.Tests\\Sentry.NLog.Tests.csproj",
63+
"test\\Sentry.OpenTelemetry.Tests\\Sentry.OpenTelemetry.Tests.csproj",
64+
"test\\Sentry.Profiling.Tests\\Sentry.Profiling.Tests.csproj",
65+
"test\\Sentry.Serilog.Tests\\Sentry.Serilog.Tests.csproj",
66+
"test\\Sentry.SourceGenerators.Tests\\Sentry.SourceGenerators.Tests.csproj",
67+
"test\\Sentry.Testing.CrashableApp\\Sentry.Testing.CrashableApp.csproj",
68+
"test\\Sentry.Testing\\Sentry.Testing.csproj",
69+
"test\\Sentry.Tests\\Sentry.Tests.csproj",
70+
"test\\SingleFileTestApp\\SingleFileTestApp.csproj"
71+
]
72+
}
73+
}

integration-test/cli.Tests.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Set-StrictMode -Version Latest
33
$ErrorActionPreference = 'Stop'
44
. $PSScriptRoot/common.ps1
5+
$IsLinuxMusl = $IsLinux -and (ldd --version 2>&1) -match 'musl'
56

67
Describe 'Console apps (<framework>) - normal build' -ForEach @(
78
@{ framework = "net8.0" }
@@ -107,7 +108,7 @@ Describe 'Console apps (<framework>) - native AOT publish' -ForEach @(
107108

108109
Describe 'MAUI' -ForEach @(
109110
@{ framework = "net8.0" }
110-
) {
111+
) -Skip:$IsLinuxMusl {
111112
BeforeAll {
112113
RegisterLocalPackage 'Sentry.Android.AssemblyReader'
113114
RegisterLocalPackage 'Sentry.Bindings.Android'

integration-test/runtime.Tests.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ internal class FakeTransport : ITransport
5858
return "./console-app/bin/Release/$framework/win-x64/publish/console-app.exe"
5959
}
6060
}
61+
elseif ((ldd --version 2>&1) -match 'musl')
62+
{
63+
return "./console-app/bin/Release/$framework/linux-musl-x64/publish/console-app"
64+
}
6165
else
6266
{
6367
return "./console-app/bin/Release/$framework/linux-x64/publish/console-app"

scripts/build-sentry-native.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ try
3737
}
3838
elseif ($IsLinux)
3939
{
40-
$outDir += '/linux-x64'
40+
if ((ldd --version 2>&1) -match 'musl')
41+
{
42+
$outDir += '/linux-musl-x64'
43+
}
44+
else
45+
{
46+
$outDir += '/linux-x64'
47+
}
4148
}
4249
else
4350
{

scripts/generate-solution-filters-config.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ filterConfigs:
4949
- "**/*DeviceTests*.csproj"
5050
- "**/*Maui.Device.TestApp.csproj"
5151

52+
- outputPath: Sentry-CI-Build-Linux-musl.slnf
53+
include:
54+
groups:
55+
- "allProjects"
56+
exclude:
57+
groups:
58+
- "macOnly"
59+
- "windowsOnly"
60+
- "artefacts"
61+
- "trimTests"
62+
patterns:
63+
- "**/*Android*.csproj"
64+
- "**/*DeviceTests*.csproj"
65+
- "**/*Maui*.csproj"
66+
5267
- outputPath: Sentry-CI-Build-macOS.slnf
5368
include:
5469
groups:

src/Sentry/Platforms/Native/Sentry.Native.targets

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
<SentryNativeOutputDirectory-win-arm64>$(SentryNativeOutputDirectory)$(NativeLibRelativePath-win-arm64)\</SentryNativeOutputDirectory-win-arm64>
1414
<NativeLibRelativePath-linux-x64>linux-x64</NativeLibRelativePath-linux-x64>
1515
<SentryNativeOutputDirectory-linux-x64>$(SentryNativeOutputDirectory)$(NativeLibRelativePath-linux-x64)\</SentryNativeOutputDirectory-linux-x64>
16+
<NativeLibRelativePath-linux-musl-x64>linux-musl-x64</NativeLibRelativePath-linux-musl-x64>
17+
<SentryNativeOutputDirectory-linux-musl-x64>$(SentryNativeOutputDirectory)$(NativeLibRelativePath-linux-musl-x64)\</SentryNativeOutputDirectory-linux-musl-x64>
1618
<NativeLibRelativePath-osx>osx</NativeLibRelativePath-osx>
1719
<SentryNativeOutputDirectory-osx>$(SentryNativeOutputDirectory)$(NativeLibRelativePath-osx)\</SentryNativeOutputDirectory-osx>
1820
<SentryNativeBuildOutputs Condition="'$(RuntimeIdentifier)' == 'win-x64'">$(SentryNativeOutputDirectory-win-x64)lib$(SentryNativeLibraryName).lib</SentryNativeBuildOutputs>
1921
<SentryNativeBuildOutputs Condition="'$(RuntimeIdentifier)' == 'win-arm64'">$(SentryNativeOutputDirectory-win-arm64)lib$(SentryNativeLibraryName).lib</SentryNativeBuildOutputs>
20-
<SentryNativeBuildOutputs Condition="$([MSBuild]::IsOsPlatform('Linux'))">$(SentryNativeOutputDirectory-linux-x64)lib$(SentryNativeLibraryName).a</SentryNativeBuildOutputs>
22+
<SentryNativeBuildOutputs Condition="'$(RuntimeIdentifier)' == 'linux-x64'">$(SentryNativeOutputDirectory-linux-x64)lib$(SentryNativeLibraryName).a</SentryNativeBuildOutputs>
23+
<SentryNativeBuildOutputs Condition="'$(RuntimeIdentifier)' == 'linux-musl-x64'">$(SentryNativeOutputDirectory-linux-musl-x64)lib$(SentryNativeLibraryName).a</SentryNativeBuildOutputs>
2124
<SentryNativeBuildOutputs Condition="$([MSBuild]::IsOsPlatform('OSX'))">$(SentryNativeOutputDirectory-osx)lib$(SentryNativeLibraryName).a</SentryNativeBuildOutputs>
2225
</PropertyGroup>
2326

@@ -42,13 +45,20 @@
4245
</None>
4346
</ItemGroup>
4447

45-
<ItemGroup Condition="'$(CI_PUBLISHING_BUILD)' == 'true' or $([MSBuild]::IsOsPlatform('Linux'))">
48+
<ItemGroup Condition="'$(CI_PUBLISHING_BUILD)' == 'true' or '$(RuntimeIdentifier)' == 'linux-x64'">
4649
<None Include="$(SentryNativeOutputDirectory-linux-x64)lib$(SentryNativeLibraryName).a">
4750
<Pack>true</Pack>
4851
<PackagePath>\sentry-native\$(NativeLibRelativePath-linux-x64)</PackagePath>
4952
</None>
5053
</ItemGroup>
5154

55+
<ItemGroup Condition="'$(CI_PUBLISHING_BUILD)' == 'true' or '$(RuntimeIdentifier)' == 'linux-musl-x64'">
56+
<None Include="$(SentryNativeOutputDirectory-linux-musl-x64)lib$(SentryNativeLibraryName).a">
57+
<Pack>true</Pack>
58+
<PackagePath>\sentry-native\$(NativeLibRelativePath-linux-musl-x64)</PackagePath>
59+
</None>
60+
</ItemGroup>
61+
5262
<ItemGroup Condition="'$(CI_PUBLISHING_BUILD)' == 'true' or $([MSBuild]::IsOsPlatform('OSX'))">
5363
<None Include="$(SentryNativeOutputDirectory-osx)lib$(SentryNativeLibraryName).a">
5464
<Pack>true</Pack>

src/Sentry/Platforms/Native/buildTransitive/Sentry.Native.targets

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@
4040
<NativeSystemLibrary Include="curl" />
4141
</ItemGroup>
4242

43+
<ItemGroup Condition="'$(FrameworkSupportsNative)' == 'true' and '$(RuntimeIdentifier)' == 'linux-musl-x64'">
44+
<DirectPInvoke Include="sentry-native" />
45+
<!-- When musl is detected, static sentry-native links to static libunwind -->
46+
<LinkerArg Include="-Wl,-Bstatic -Wl,--whole-archive -lunwind -Wl,--no-whole-archive -Wl,-Bdynamic" />
47+
<NativeSystemLibrary Include="lzma" />
48+
<NativeLibrary Include="$(MSBuildThisFileDirectory)..\sentry-native\linux-musl-x64\libsentry-native.a" />
49+
<!-- See: https://github.com/dotnet/runtime/issues/97414 -->
50+
<NativeSystemLibrary Include="curl" />
51+
</ItemGroup>
52+
4353
<ItemGroup Condition="'$(FrameworkSupportsNative)' == 'true' and ('$(RuntimeIdentifier)' == 'osx-x64' or '$(RuntimeIdentifier)' == 'osx-arm64')">
4454
<DirectPInvoke Include="sentry-native" />
4555
<NativeLibrary Include="$(MSBuildThisFileDirectory)..\sentry-native\osx\libsentry-native.a" />

0 commit comments

Comments
 (0)