Skip to content

Enable cross-architecture Native AOT tool packaging - #55250

Merged
baronfel merged 3 commits into
dotnet:mainfrom
baronfel:baronfel-enable-cross-arch-aot-tool-pack
Jul 14, 2026
Merged

baronfel merged 3 commits into
dotnet:mainfrom
baronfel:baronfel-enable-cross-arch-aot-tool-pack

Conversation

@baronfel

@baronfel baronfel commented Jul 12, 2026 •

Copy link
Copy Markdown
Member

Why

The .NET Tool packaging pipeline can create a pointer package plus RID-specific implementation packages in one invocation. Native AOT tools have historically been excluded from that orchestration because the base SDK cannot publish every requested RID from every host.

That restriction also blocks external packages from expanding the SDK's native cross-compilation capabilities. Packages such as AotAnywhere can provide additional Native AOT targets through toolchains such as Zig, but the Tool packaging pipeline currently has no supported way for them to tell the SDK which requested RIDs they can build. As a result, those packages cannot participate in multi-RID Native AOT tool packaging even when they can successfully publish all of the requested targets.

This change separates two responsibilities:

  • A toolchain determines which requested RIDs are buildable on the current host.
  • The SDK orchestrates one RID-specific inner Pack build for each selected RID.

What changed

  • Adds the empty ComputeToolPackageRuntimeIdentifiersToPack marker target as an extensibility point.
  • Consumers can run a target with BeforeTargets="ComputeToolPackageRuntimeIdentifiersToPack", inspect inputs such as ToolPackageRuntimeIdentifiers and RuntimeIdentifiers, and emit one ToolPackageRuntimeIdentifiersToPack item per supported RID.
  • If no consumer supplies items, the base SDK computes a conservative default set:
    • non-AOT tools can package every requested RID;
    • Windows x64 can package win-x64 and win-arm64 Native AOT tools;
    • macOS x64 and Arm64 can package both osx-x64 and osx-arm64 Native AOT tools;
    • other Native AOT hosts package only their current host RID.
  • _CreateRIDSpecificToolPackages then performs the existing inner-package orchestration for the selected items.

This keeps the base SDK's behavior limited to combinations supported by its native toolchain while allowing packages such as AotAnywhere to replace that capability decision without replacing the packaging pipeline.

Testing

  • Added coverage for non-AOT tools, the default Native AOT host/RID matrix, evaluation-time item overrides, and BeforeTargets customization.
  • GivenThatWeWantToPackAToolProject: 91 passed, 4 skipped.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 95142a7c-731e-4791-a2f5-ae0461aff70a
Copilot AI review requested due to automatic review settings July 12, 2026 16:48
@baronfel
baronfel requested a review from dsplaisted July 12, 2026 16:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Enables cross-architecture Native AOT tool packaging by adding an MSBuild extensibility point to compute which tool package RIDs should be packed, with SDK defaults that filter AOT packaging to host-supported target architectures.

Changes:

  • Added ComputeToolPackageRuntimeIdentifiersToPack target as an extensibility point for tool RID selection.
  • Implemented default RID filtering for AOT tools based on host RID capabilities when no explicit ToolPackageRuntimeIdentifiersToPack items are provided.
  • Added tests covering default filtering behavior, predefined item override, and BeforeTargets customization.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/Microsoft.NET.ToolPack.Tests/GivenThatWeWantToPackAToolProject.cs Adds coverage for default RID filtering and customization paths for tool RID packing.
src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.PackTool.targets Introduces the new extensibility target and default computation for ToolPackageRuntimeIdentifiersToPack, and wires it into RID-specific tool package creation.

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@baronfel

Copy link
Copy Markdown
Member Author

@slang25 with this change and a Target like

<Target Name="SelectAotAnywhereToolPackageRuntimeIdentifiers"
        BeforeTargets="ComputeToolPackageRuntimeIdentifiersToPack">
  <ItemGroup>
    <ToolPackageRuntimeIdentifiersToPack Include="$(ToolPackageRuntimeIdentifiers)" />
  </ItemGroup>
</Target>

in a project using AotAnywhere, I was able to create an entire NAOT-layout .NET Tool package including the RID-agnostic pointer package and the RID-specific NAOT implementation packages.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 95142a7c-731e-4791-a2f5-ae0461aff70a
@baronfel
baronfel merged commit d6efb39 into dotnet:main Jul 14, 2026
27 checks passed
@baronfel
baronfel deleted the baronfel-enable-cross-arch-aot-tool-pack branch July 14, 2026 15:36
slang25 added a commit to StuDevLabs/AotAnywhere that referenced this pull request Jul 14, 2026
Hook ComputeToolPackageRuntimeIdentifiersToPack (dotnet/sdk#55250,
.NET 11+) so a single 'dotnet pack' on one host produces RID-specific
AOT tool packages for every RID in ToolPackageRuntimeIdentifiers,
instead of only the RIDs the SDK's native toolchain can build there.

The new build/ToolPack.targets emits one ToolPackageRuntimeIdentifiersToPack
item per requested RID, mirroring the SDK's ToolPackageRuntimeIdentifiers ->
RuntimeIdentifiers fallback. It stays out of the way in inner RID-specific
builds, when RID-specific tool packaging is off, when the user predefined
their own items, or when AotAnywhereMultiRidToolPackaging=false. On SDKs
without the extensibility point the BeforeTargets reference is ignored and
the file is inert.

Closes #81

Co-authored-by: Claude Fable 5 <[email protected]>
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants