You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Publish NativeAOT on Ubuntu doesn't work with -r linux-musl-x64 #92294
Is the problem that the native toolchain we picked up is not the cross toolchain? I.e. Is this is a crosscompilation, but it's misconfigured so the native linker and native libraries we use are from the host system? What's the output if you add <ItemGroup><LinkerArg Include="-v" /></ItemGroup>?
If misconfigured cross toolchain is the problem, this is similar to #88942. The issue is that we don't control the native build tools. The user needs to configure them. It is very hard for us to check that the environment is properly configured. This is Linux after all, there's a bazillion ways how a valid native toolchain could look like. We could smoke test the output of the linker and if the binary depends on glibc, it's probably not musl, but that's a bit of an overreach.
We'll not be able to solve this unless we start shipping our own native toolchain and sysroot instead of relying on user to configure this.
Is this unique to PublishContainer? Or does it also repro separately?
I don't believe it is unique to PublishContainer. To try it, you can just dotnet publish -r linux-musl-x64 on your Ubuntu machine, put the executable into an alpine container and try to run it.
I had a look at this. I don't know if there's anything we can do here.
I thought that maybe if clang is used as the linker, we could force passing --target=x86_64-alpine-linux-musl to clang and clang would error out if this is not a matching sysroot. But we already do pass --target=aarch64-alpine-linux-musl when doing arm64 crosscompile and that one fails with:
I.e. clang didn't do anything to check if we're actually configured for arm64 musl and just passed the host system's libs to the linker along with our arm64 object file. This failed to link for obvious reason. This means that even clang doesn't care/cannot validate we can actually target the thing we try to target in the current configuration.
The only way I see we could make this fail to link is if we reference some symbol that only exists in musl libc so that an attempt to link against glibc fails. The hello world produced with -r linux-musl-x64 actually works fine on Ubuntu because we successfully linked it with glibc from the host system.
If the problem is that the native toolchain needs to be correctly configured this should be somewhere in the docs and the cli should handle it if the toolchain is misconfigured. The user is not expected to know that using -r linux-musl-x64 will not work.
That said, have you taken a look at what the developers did with Cross? It is a docker based approach and it just works.
I'm actually going to try to now build with an sdk Alpine container image to see if it works... If that works, getting it into a tool shouldn't be that hard. It would also solve other platforms, like arm64 etc.
Ok, I got it work on Alpine. This is a simple Bash script that will compile with the help of containers.
This will build native AOT binaries in the apps directory (notice -v on the app directory docker run), and add them to a dotnet/runtime-deps:8.0-alpine based image using dotnet's container tooling.
I'm removing symbols to get the image smaller, so -p:DebugType=none is optional.
This is just a quick script, it could be improved by prebuilding a base image with the apk packages. Still, it takes less than 10 seconds to add them, so that's not really a big problem.
The only thing that changed was the cross, added to the line.
The build of the tool is reproducible and done by Github actions, you can verify everything.
The .nupkg will become smaller when Docker.DotNet drops JSON .NET.
Reacted by Enissay, Cameron Taggart, imxcstar and DPH
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.
This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.
Activity
agocke commentedon Sep 19, 2023
Is this unique to
PublishContainer? Or does it also repro separately?MichalStrehovsky commentedon Sep 20, 2023
Is the problem that the native toolchain we picked up is not the cross toolchain? I.e. Is this is a crosscompilation, but it's misconfigured so the native linker and native libraries we use are from the host system? What's the output if you add
<ItemGroup><LinkerArg Include="-v" /></ItemGroup>?If misconfigured cross toolchain is the problem, this is similar to #88942. The issue is that we don't control the native build tools. The user needs to configure them. It is very hard for us to check that the environment is properly configured. This is Linux after all, there's a bazillion ways how a valid native toolchain could look like. We could smoke test the output of the linker and if the binary depends on glibc, it's probably not musl, but that's a bit of an overreach.
We'll not be able to solve this unless we start shipping our own native toolchain and sysroot instead of relying on user to configure this.
eerhardt commentedon Sep 20, 2023
I don't believe it is unique to PublishContainer. To try it, you can just
dotnet publish -r linux-musl-x64on your Ubuntu machine, put the executable into an alpine container and try to run it.MichalPetryka commentedon Sep 20, 2023
Are there any plans to make that the default now?
MichalStrehovsky commentedon Sep 20, 2023
We don't even have plans to "make that", so no plans to make that the default either :).
MichalStrehovsky commentedon Sep 21, 2023
I had a look at this. I don't know if there's anything we can do here.
I thought that maybe if clang is used as the linker, we could force passing
--target=x86_64-alpine-linux-muslto clang and clang would error out if this is not a matching sysroot. But we already do pass--target=aarch64-alpine-linux-muslwhen doing arm64 crosscompile and that one fails with:I.e. clang didn't do anything to check if we're actually configured for arm64 musl and just passed the host system's libs to the linker along with our arm64 object file. This failed to link for obvious reason. This means that even clang doesn't care/cannot validate we can actually target the thing we try to target in the current configuration.
The only way I see we could make this fail to link is if we reference some symbol that only exists in musl libc so that an attempt to link against glibc fails. The hello world produced with
-r linux-musl-x64actually works fine on Ubuntu because we successfully linked it with glibc from the host system.giggio commentedon Oct 8, 2023
If the problem is that the native toolchain needs to be correctly configured this should be somewhere in the docs and the cli should handle it if the toolchain is misconfigured. The user is not expected to know that using
-r linux-musl-x64will not work.That said, have you taken a look at what the developers did with Cross? It is a docker based approach and it just works.
I'm actually going to try to now build with an sdk Alpine container image to see if it works... If that works, getting it into a tool shouldn't be that hard. It would also solve other platforms, like arm64 etc.
giggio commentedon Oct 8, 2023
Ok, I got it work on Alpine. This is a simple Bash script that will compile with the help of containers.
This will build native AOT binaries in the apps directory (notice
-von the app directorydocker run), and add them to adotnet/runtime-deps:8.0-alpinebased image using dotnet's container tooling.I'm removing symbols to get the image smaller, so
-p:DebugType=noneis optional.This is just a quick script, it could be improved by prebuilding a base image with the apk packages. Still, it takes less than 10 seconds to add them, so that's not really a big problem.
As I mentioned before, this could easily be built into a tool. Doing a
dotnet-cross build -r linux-musl-x64would then do the right thing.giggio commentedon Oct 14, 2023
Ok, I built
dotnet-cross, install instructions:https://github.com/giggio/dotnet-cross#installing-dotnet-cli-tool
TLDR:
It demands docker to be able to build.
@eerhardt, just install it and run:
The only thing that changed was the
cross, added to the line.The build of the tool is reproducible and done by Github actions, you can verify everything.
The .nupkg will become smaller when
Docker.DotNetdrops JSON .NET.dotnet-policy-service commentedon Aug 21, 2025
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.
This process is part of our issue cleanup automation.
dotnet-policy-service commentedon Sep 4, 2025
This issue will now be closed since it had been marked
no-recent-activitybut received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.