diff --git a/eng/dockerfile-templates/sdk/Dockerfile.linux.aot b/eng/dockerfile-templates/sdk/Dockerfile.linux.aot index c003c9209a..a014b0ebe0 100644 --- a/eng/dockerfile-templates/sdk/Dockerfile.linux.aot +++ b/eng/dockerfile-templates/sdk/Dockerfile.linux.aot @@ -7,28 +7,80 @@ set isUbuntu to find(OS_ARCH_HYPHENATED, "Ubuntu") >= 0 ^ set ubuntuVersion to when(find(OS_VERSION, "jammy") >= 0, "jammy", "noble") ^ + _ Native AOT only requires gcc. Native AOT in .NET really only needs a linker and something to drive the linker. + The runtime falls back to using gcc to drive linking when clang is not present, and both use the same bfd linker + under the hood, so dropping clang/llvm meaningfully shrinks the image. This optimization was made in .NET 11, + hence the conditional below. ^ + set useGcc to dotnetVersion != "8.0" && dotnetVersion != "9.0" && dotnetVersion != "10.0" ^ + + _ The gcc package alone isn't always sufficient to link Native AOT binaries: + - Alpine: gcc pulls in binutils, but musl-dev (crt objects/headers) must be added. + - Azure Linux 3.0: gcc pulls in neither binutils (objcopy/ld) nor glibc-devel + (crt objects and -ldl/-lrt), so both are added explicitly. + - Azure Linux 4.0 and Ubuntu: gcc transitively pulls in binutils and libc dev + packages, so gcc alone is enough. + Installing these specific packages avoids the much larger build-base / + build-essential meta-packages that bundle make, g++, autotools, etc. ^ + set pkgs to cat(sort( - when(isAlpine, - [ - "build-base", - "clang", - "zlib-dev" - ], - when(isAzureLinux, - when(OS_VERSION_NUMBER = "3.0", - [ - "build-essential", - "clang", - "zlib-devel" - ], - [ - "gcc" - ]), - [ - "clang", - "zlib1g-dev", - "llvm" - ])))) + when( + useGcc, + when( + isAlpine, + [ + "gcc", + "musl-dev", + "zlib-dev" + ], + when( + isAzureLinux, + when( + OS_VERSION_NUMBER = "3.0", + [ + "binutils", + "gcc", + "glibc-devel", + "zlib-devel" + ], + [ + "gcc" + ] + ), + [ + "gcc", + "zlib1g-dev" + ] + ) + ), + when( + isAlpine, + [ + "build-base", + "clang", + "zlib-dev" + ], + when( + isAzureLinux, + when( + OS_VERSION_NUMBER = "3.0", + [ + "build-essential", + "clang", + "zlib-devel" + ], + [ + "gcc" + ] + ), + [ + "clang", + "zlib1g-dev", + "llvm" + ] + ) + ) + ) + )) }}ARG REPO=mcr.microsoft.com/dotnet/sdk FROM {{baseImageTag}} diff --git a/src/sdk/11.0/alpine3.23-aot/amd64/Dockerfile b/src/sdk/11.0/alpine3.23-aot/amd64/Dockerfile index 03e6d3c837..d3737afcb4 100644 --- a/src/sdk/11.0/alpine3.23-aot/amd64/Dockerfile +++ b/src/sdk/11.0/alpine3.23-aot/amd64/Dockerfile @@ -2,6 +2,6 @@ ARG REPO=mcr.microsoft.com/dotnet/sdk FROM $REPO:11.0.100-preview.5-alpine3.23-amd64 RUN apk add --upgrade --no-cache \ - build-base \ - clang \ + gcc \ + musl-dev \ zlib-dev diff --git a/src/sdk/11.0/alpine3.23-aot/arm64v8/Dockerfile b/src/sdk/11.0/alpine3.23-aot/arm64v8/Dockerfile index 317c915362..6d6d9872be 100644 --- a/src/sdk/11.0/alpine3.23-aot/arm64v8/Dockerfile +++ b/src/sdk/11.0/alpine3.23-aot/arm64v8/Dockerfile @@ -2,6 +2,6 @@ ARG REPO=mcr.microsoft.com/dotnet/sdk FROM $REPO:11.0.100-preview.5-alpine3.23-arm64v8 RUN apk add --upgrade --no-cache \ - build-base \ - clang \ + gcc \ + musl-dev \ zlib-dev diff --git a/src/sdk/11.0/azurelinux3.0-aot/amd64/Dockerfile b/src/sdk/11.0/azurelinux3.0-aot/amd64/Dockerfile index 39f6b2567c..4dd191eb83 100644 --- a/src/sdk/11.0/azurelinux3.0-aot/amd64/Dockerfile +++ b/src/sdk/11.0/azurelinux3.0-aot/amd64/Dockerfile @@ -2,7 +2,8 @@ ARG REPO=mcr.microsoft.com/dotnet/sdk FROM $REPO:11.0.100-preview.5-azurelinux3.0-amd64 RUN tdnf install -y \ - build-essential \ - clang \ + binutils \ + gcc \ + glibc-devel \ zlib-devel \ && tdnf clean all diff --git a/src/sdk/11.0/azurelinux3.0-aot/arm64v8/Dockerfile b/src/sdk/11.0/azurelinux3.0-aot/arm64v8/Dockerfile index cebb3e9677..0c64264c3e 100644 --- a/src/sdk/11.0/azurelinux3.0-aot/arm64v8/Dockerfile +++ b/src/sdk/11.0/azurelinux3.0-aot/arm64v8/Dockerfile @@ -2,7 +2,8 @@ ARG REPO=mcr.microsoft.com/dotnet/sdk FROM $REPO:11.0.100-preview.5-azurelinux3.0-arm64v8 RUN tdnf install -y \ - build-essential \ - clang \ + binutils \ + gcc \ + glibc-devel \ zlib-devel \ && tdnf clean all diff --git a/src/sdk/11.0/resolute-aot/amd64/Dockerfile b/src/sdk/11.0/resolute-aot/amd64/Dockerfile index ef7cab079a..cdaf6c1ffe 100644 --- a/src/sdk/11.0/resolute-aot/amd64/Dockerfile +++ b/src/sdk/11.0/resolute-aot/amd64/Dockerfile @@ -3,7 +3,6 @@ FROM $REPO:11.0.100-preview.5-resolute-amd64 RUN apt-get update \ && apt-get install -y --no-install-recommends \ - clang \ - llvm \ + gcc \ zlib1g-dev \ && rm -rf /var/lib/apt/lists/* diff --git a/src/sdk/11.0/resolute-aot/arm64v8/Dockerfile b/src/sdk/11.0/resolute-aot/arm64v8/Dockerfile index b736ae2dca..8243e1c3a7 100644 --- a/src/sdk/11.0/resolute-aot/arm64v8/Dockerfile +++ b/src/sdk/11.0/resolute-aot/arm64v8/Dockerfile @@ -3,7 +3,6 @@ FROM $REPO:11.0.100-preview.5-resolute-arm64v8 RUN apt-get update \ && apt-get install -y --no-install-recommends \ - clang \ - llvm \ + gcc \ zlib1g-dev \ && rm -rf /var/lib/apt/lists/* diff --git a/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-alpine3.23-aot-amd64-Dockerfile.approved.txt b/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-alpine3.23-aot-amd64-Dockerfile.approved.txt index 1e41f1a95a..38c0f13dfc 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-alpine3.23-aot-amd64-Dockerfile.approved.txt +++ b/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-alpine3.23-aot-amd64-Dockerfile.approved.txt @@ -2,6 +2,6 @@ ARG REPO=mcr.microsoft.com/dotnet/sdk FROM $REPO:0.0.0-alpine3.XX-amd64 RUN apk add --upgrade --no-cache \ - build-base \ - clang \ + gcc \ + musl-dev \ zlib-dev diff --git a/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-alpine3.23-aot-arm64v8-Dockerfile.approved.txt b/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-alpine3.23-aot-arm64v8-Dockerfile.approved.txt index 08b5490921..76c6fb7d0b 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-alpine3.23-aot-arm64v8-Dockerfile.approved.txt +++ b/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-alpine3.23-aot-arm64v8-Dockerfile.approved.txt @@ -2,6 +2,6 @@ ARG REPO=mcr.microsoft.com/dotnet/sdk FROM $REPO:0.0.0-alpine3.XX-arm64v8 RUN apk add --upgrade --no-cache \ - build-base \ - clang \ + gcc \ + musl-dev \ zlib-dev diff --git a/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-azurelinux3.0-aot-amd64-Dockerfile.approved.txt b/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-azurelinux3.0-aot-amd64-Dockerfile.approved.txt index 9f786aa5b2..a1c8544cd0 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-azurelinux3.0-aot-amd64-Dockerfile.approved.txt +++ b/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-azurelinux3.0-aot-amd64-Dockerfile.approved.txt @@ -2,7 +2,8 @@ ARG REPO=mcr.microsoft.com/dotnet/sdk FROM $REPO:0.0.0-azurelinux3.0-amd64 RUN tdnf install -y \ - build-essential \ - clang \ + binutils \ + gcc \ + glibc-devel \ zlib-devel \ && tdnf clean all diff --git a/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-azurelinux3.0-aot-arm64v8-Dockerfile.approved.txt b/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-azurelinux3.0-aot-arm64v8-Dockerfile.approved.txt index a571885bdc..04105723a9 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-azurelinux3.0-aot-arm64v8-Dockerfile.approved.txt +++ b/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-azurelinux3.0-aot-arm64v8-Dockerfile.approved.txt @@ -2,7 +2,8 @@ ARG REPO=mcr.microsoft.com/dotnet/sdk FROM $REPO:0.0.0-azurelinux3.0-arm64v8 RUN tdnf install -y \ - build-essential \ - clang \ + binutils \ + gcc \ + glibc-devel \ zlib-devel \ && tdnf clean all diff --git a/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-resolute-aot-amd64-Dockerfile.approved.txt b/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-resolute-aot-amd64-Dockerfile.approved.txt index 46cc956529..db9d3bfebf 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-resolute-aot-amd64-Dockerfile.approved.txt +++ b/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-resolute-aot-amd64-Dockerfile.approved.txt @@ -3,7 +3,6 @@ FROM $REPO:0.0.0-resolute-amd64 RUN apt-get update \ && apt-get install -y --no-install-recommends \ - clang \ - llvm \ + gcc \ zlib1g-dev \ && rm -rf /var/lib/apt/lists/* diff --git a/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-resolute-aot-arm64v8-Dockerfile.approved.txt b/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-resolute-aot-arm64v8-Dockerfile.approved.txt index 3f7a45495a..eed7e06c54 100644 --- a/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-resolute-aot-arm64v8-Dockerfile.approved.txt +++ b/tests/Microsoft.DotNet.Docker.Tests/Baselines/GeneratedArtifactTests/VerifyInternalDockerfilesOutput/sdk-11.0-resolute-aot-arm64v8-Dockerfile.approved.txt @@ -3,7 +3,6 @@ FROM $REPO:0.0.0-resolute-arm64v8 RUN apt-get update \ && apt-get install -y --no-install-recommends \ - clang \ - llvm \ + gcc \ zlib1g-dev \ && rm -rf /var/lib/apt/lists/*