Skip to content

fix: support musl on Linux #4188

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

fix: support musl on Linux #4188

wants to merge 2 commits into from

Conversation

jpnurmi
Copy link
Collaborator

@jpnurmi jpnurmi commented May 14, 2025

TODO:

Notes:

  • setup-dotnet is musl-compatible 👍
  • setup-java installs musl-incompatible binaries 👎
  • setup-android installs musl-incompatible prebuilt (Android SDK Build-Tools) binaries 👎

Close: #4127

@jpnurmi jpnurmi force-pushed the fix/musl branch 6 times, most recently from eee505e to 333332c Compare May 15, 2025 19:52
@jpnurmi
Copy link
Collaborator Author

jpnurmi commented May 16, 2025

Hi @jamescrosswell, I finally managed to get linux-musl-x64 to pass the whole CI pipeline, including integration tests. :) The last remaining TODO-item is to make the Docker image available:

Is the approach with Sentry-CI-Build-Linux-musl.slnf sensible? I wish we could use NO_MOBILE=true or NO_ANDROID=true with the existing Sentry-CI-Build-Linux.slnf, but it pulls in several projects that fail to build without Android SDK:

  • Sentry.Bindings.Android
  • Sentry.Samples.Android
  • Sentry.Samples.Maui
  • AndroidTestApp (Sentry.Android.AssemblyReader.Tests)

Comment on lines -17 to +20
<SentryNativeBuildOutputs Condition="$([MSBuild]::IsOsPlatform('Linux'))">$(SentryNativeOutputDirectory-linux-x64)lib$(SentryNativeLibraryName).a</SentryNativeBuildOutputs>
<SentryNativeBuildOutputs Condition="'$(RuntimeIdentifier)' == 'linux-x64'">$(SentryNativeOutputDirectory-linux-x64)lib$(SentryNativeLibraryName).a</SentryNativeBuildOutputs>
<SentryNativeBuildOutputs Condition="'$(RuntimeIdentifier)' == 'linux-musl-x64'">$(SentryNativeOutputDirectory-linux-musl-x64)lib$(SentryNativeLibraryName).a</SentryNativeBuildOutputs>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any potential downside to checking the runtime identifier instead of the platform reported by msbuild? Are there any relevant cross-build scenarios we should consider?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, I'm not sure. I know that RID can be explicitly set, to make a build that's specific for a platform.
Or not set (it's optinal is what I mean) in which case the build is not platform specific. But I haven't looked at it in details in years. Maybe @Flash0ver has tips/pointers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Publish the app for a specific runtime identifier using dotnet publish -r .

Looks like a RID is required in order to build for Native AOT (which makes a lot of sense) so this shouldn't be an isssue

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, checking for RID did not work as expected in this context :(

With RID checks:

$ dotnet build Sentry-CI-Build-Linux-musl.slnf -c Release
[...]
$ tree src/Sentry/Platforms/Native/
src/Sentry/Platforms/Native/
├── CFunctions.cs
├── NativeContextWriter.cs
├── NativeScopeObserver.cs
├── Sentry.Native.targets
├── SentryNative.cs
├── SentrySdk.cs
├── buildTransitive
│   └── Sentry.Native.targets
└── windows-config.cmake

Without RID checks:

$ dotnet build Sentry-CI-Build-Linux-musl.slnf -c Release
[...]
$ tree src/Sentry/Platforms/Native/
src/Sentry/Platforms/Native/
├── CFunctions.cs
├── NativeContextWriter.cs
├── NativeScopeObserver.cs
├── Sentry.Native.targets
├── SentryNative.cs
├── SentrySdk.cs
├── buildTransitive
│   └── Sentry.Native.targets
├── sentry-native
│   └── linux-musl-x64
│       └── libsentry-native.a # <==
└── windows-config.cmake

3 directories, 9 files

Copy link
Member

@Flash0ver Flash0ver May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we're fine with the slightly disjoint behavior for local builds between operating systems ... if I read it correctly:

For ordinary builds (dotnet build or simple build via IDE)

  • on Windows and macOS we also build the native dependencies, although not necessarily required, when out-of-date, because $(SentryNativeBuildOutputs) will be set
  • on Linux we do not build the native dependencies during ordinary builds locally, because$(SentryNativeBuildOutputs) will not be set when the $(RuntimeIdentifier) is empty

However, when building for a specific platform, and in particular AOT, then the $(RuntimeIdentifier) is set and we build the native dependencies also on Linux.

If I understand the Inputs="$(SentryNativeBuildInputs)" Outputs="$(SentryNativeBuildOutputs)" of the _BuildSentryNativeSDK Target correctly.
Actually, I'm not entirely certain: if $(SentryNativeBuildOutputs) is empty ... which it is in the case of an "ordinary" build on Linux when the $(RuntimeIdentifier) is not set, will the _BuildSentryNativeSDK Target below then be invoked or not invoked?

However, my thought here may be totally nit-picky, as when the Native Dependencies are required, they will be built, so we may have a slight build behavior disjoint between Operating Systems, but the runtime locally should be perfectly fine indeed.


UPDATE ... oops, I missed your previous comment @jpnurmi ... I believe I described the same behavior
An "ordinary" dotnet build does not set the $(RuntimeIdentifier).
Do we need the native dependency for just a dotnet build? Conversely, do we need the native dependencies only when specifying an RID?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, thanks! So it might just be my misunderstanding. ;) I compared what outputs were present after dotnet build Sentry-CI-Build-Linux(-musl).slnf on Ubuntu vs. Alpine Linux and tried to achieve the same.

On Ubuntu, if I run dotnet workload restore + dotnet build Sentry-CI-Build-Linux.slnf in a clean sentry-dotnet checkout of the main branch, it does seem to build src/Sentry/Platforms/Native/sentry-native/linux-x64/libsentry-native.a.

@jpnurmi jpnurmi changed the title WIP: fix: support musl on Linux fix: support musl on Linux May 17, 2025
@bruno-garcia
Copy link
Member

Is the approach with Sentry-CI-Build-Linux-musl.slnf sensible? I wish we could use NO_MOBILE=true or NO_ANDROID=true with the existing Sentry-CI-Build-Linux.slnf, but it pulls in several projects that fail to build without Android SDK:

I'd say so, and I copied your approach on #4187 (which won't land anytime soon since it's blocked on sentry-native win-arm64 support but at least will be ready once that lands

@jamescrosswell
Copy link
Collaborator

jamescrosswell commented May 19, 2025

Is the approach with Sentry-CI-Build-Linux-musl.slnf sensible? I wish we could use NO_MOBILE=true or NO_ANDROID=true with the existing Sentry-CI-Build-Linux.slnf, but it pulls in several projects that fail to build without Android SDK:

Yeah I think that makes sense. The names we give to these solutions are maybe what's confusing. Implicitly building musl we're trying to provide better support for SDK users deploying ASP.NET Core apps using docker containers... so no android required.

However Sentry-CI-Build-Linux.slnf is just the base solution for contributors to the Sentry SDK who are running Linux and they could well be building Android apps... so we can't really rip it out of there.

@jpnurmi jpnurmi force-pushed the fix/musl branch 2 times, most recently from 5eb47e5 to 9971b68 Compare May 19, 2025 10:11
@jamescrosswell
Copy link
Collaborator

I'm not sure if it's caused you any issues here but just FYI:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Errors with sentry-native launching with Sentry.AspNetCore on Dockerized Native AOT builds on Linux
4 participants