dotnet / dotnet-docker

Docker images for .NET and the .NET Tools.
https://hub.docker.com/_/microsoft-dotnet
MIT License
4.44k stars 1.93k forks source link

.NET SDK docker images needs to include C/C++ compiler for PublishAot to work out of the box #3884

Closed timmydo closed 2 years ago

timmydo commented 2 years ago

Describe the Bug

The new PublishAot option in .NET 7 will precompile your application offering various benefits...etc. But for it to work, the SDK needs a C/C++ compiler.

/usr/share/dotnet/sdk/7.0.100-preview.5.22307.18/Sdks/Microsoft.DotNet.ILCompiler/build/Microsoft.NETCore.Native.Unix.props(110,5): error : Platform linker ('clang') not found. Try installing clang or the appropriate package for your platform to resolve the problem.

Steps to Reproduce

Using dotnet publish -r RID --self-contained with -p:PublishAot=true fails due to SDK images not having clang installed.

cc @MichalStrehovsky @agocke

richlander commented 2 years ago

I'm not super enthusiastic about adding clang by default for all our users.

There are three options:

It seems like we should go with the first one until more people start asking for it. That can be handled with documentation.

Fair?

@jkotas

jkotas commented 2 years ago

It seems like we should go with the first one until more people start asking for it

Yes, I agree.

It is not just clang. We have the prerequisites documented at https://docs.microsoft.com/en-us/dotnet/core/deploying/native-aot.

timmydo commented 2 years ago

@jkotas I'm not sure those instructions are straightforward for installing toolchain in a windows container? I think https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022 might work also, but it would be nice to have option 3, an -aot SDK version that works out of the box.

mthalman commented 2 years ago

[Triage] - We're in agreement that adding these packages to the sdk image is out of scope at this point. We'll listen for feedback to see if there's more demand as time goes on.

It does seem worthwhile to include some form of documentation on this repo. The question is whether it should be a scenario document or if it should be more front-and-center as a sample.

Given that Windows and Linux have different requirements for dependencies, it would be good to provide examples of both of these. Installing in a container environment differs in some ways than non-container environments and would be useful to have that specific use case documented for customers.

The Windows case is notable because it would only be possible in Windows Server Core because the VS Tools require .NET Fx which is not available in Nano Server. We do provide Windows Server Core sdk images that would be suitable for this scenario.

richlander commented 2 years ago

it would be nice to have option 3, an -aot SDK version that works out of the box.

Sure. We're not going to do that until we see higher demand.

Visual Studio

This is what we do for a related need with .NET Framework:

https://github.com/microsoft/dotnet-framework-docker/blob/main/src/sdk/4.8/windowsservercore-ltsc2022/Dockerfile#L21

jkotas commented 2 years ago

I am adding sample Linux and Windows x64 NativeAOT build Dockerfiles as part of https://github.com/dotnet/samples/pull/5222

richlander commented 2 years ago

We have added a sample to this repo in the past. I'd suggest that this repo is the better place.

https://github.com/dotnet/dotnet-docker/issues/2814

jkotas commented 2 years ago

The guidance has been to have all samples that are linked from the docs in the samples repo. It means that you pretty much always want the sample to be in the samples repo to make it discoverable.

The samples repo has samples with Dockerfiles too. For example, https://github.com/dotnet/samples/tree/main/orleans/Voting

Why would be this repo be better for the nativeaot hello world sample than the samples repo?

richlander commented 2 years ago

I see. I didn't realize that there were other Dockerfile samples in that repo and that you were going to link from docs.

mthalman commented 2 years ago

Since there are some samples that cover this in other repos, we'll just close this issue.