Phase 29 of 30 · Topic 29.5

Cross-Compilation & Target Architecture Matrix

1Concept

Native AOT binaries target specific OS and CPU architectures (e.g. `linux-x64`, `linux-arm64`, `win-x64`). Using multi-stage Docker builds ensures seamless compilation for target cloud environments.

2Architecture Diagram

dotnet publish -c Release -r linux-x64 --self-contained
       │
   Emits Native Linux ELF Executable ──> Copy to Distroless Container!

3Code Example

C# 13 & .NET 9
using System;

public class CrossCompileDemo
{
    public static void Main()
    {
        Console.WriteLine("Target RIDs: linux-x64, linux-arm64, win-x64, osx-arm64.");
    }
}

4Expected Output

Target RIDs: linux-x64, linux-arm64, win-x64, osx-arm64.

5Key Takeaways

  • Native AOT produces platform-specific native binaries (not portable bytecode).
  • Use Docker multi-stage builds on GitHub Actions / GitLab CI for Linux deployment.
  • Ensure native C library dependencies (`libssl`, `glibc`/`musl`) match the target container.