Skip to content

Skip ILC LinkNative target for NativeAOT, remove llvm-ar dependency - #11329

Merged
simonrozsival merged 3 commits into
mainfrom
dev/sbomer/skip-llvm-ar
May 13, 2026
Merged

Skip ILC LinkNative target for NativeAOT, remove llvm-ar dependency#11329
simonrozsival merged 3 commits into
mainfrom
dev/sbomer/skip-llvm-ar

Conversation

@sbomer

@sbomer sbomer commented May 12, 2026

Copy link
Copy Markdown
Member

Summary

Override ILC's LinkNative target with a no-op for NativeAOT builds. With NativeLib=static, LinkNative only runs llvm-ar to create a .a archive from the ILC-compiled .o file. We never consume that .a_AndroidLinkNativeAotSharedLibrary links the .o directly into a .so.

This eliminates the need for:

Changes

  • Microsoft.Android.Sdk.NativeAOT.targets: Remove CppLibCreator and LinkerFlavor properties that were only needed for the LinkNative target we no longer run.
  • Microsoft.Android.Sdk.NativeAOT.After.targets (new): Define the LinkNative no-op override. This must be imported after the ILC NuGet package targets (last target definition wins in MSBuild).
  • Microsoft.Android.Sdk.After.targets: Import the new file with a _AndroidRuntime == 'NativeAOT' condition, keeping this file as a pure import list.

sbomer and others added 2 commits May 12, 2026 11:02
Override ILC's LinkNative target as a no-op in Microsoft.Android.Sdk.After.targets.
With NativeLib=static, LinkNative only runs llvm-ar to create a .a archive from
the ILC-compiled .o file.  We never consume that .a — _AndroidLinkNativeAotSharedLibrary
links the .o directly into a .so.

The override must be in After.targets because:
1. MSBuild uses the last target definition (last definition wins)
2. The ILC NuGet package targets are imported after the workload SDK targets
3. After.targets is imported after both, so its definition takes precedence

This eliminates the need for llvm-ar (not shipped in the workload toolchain),
CppLibCreator, and the LinkerFlavor workaround for dotnet/runtime#126978.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Assisted-by: Claude:claude-opus-4.6-1m
Extract the inline LinkNative no-op target from After.targets into a
dedicated Microsoft.Android.Sdk.NativeAOT.After.targets file. This
keeps After.targets as a pure import list and puts the NativeAOT-specific
ILC override in its own file, consistent with the pattern of separating
runtime-specific logic.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Assisted-by: Claude:claude-opus-4.6-1m
Copilot AI review requested due to automatic review settings May 12, 2026 18:17

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

This PR adjusts the NativeAOT build pipeline in the Android MSBuild targets to avoid running ILC’s LinkNative archive step (which invokes llvm-ar) when NativeLib=static, since Android’s _AndroidLinkNativeAotSharedLibrary links the ILC-produced .o directly into the final .so.

Changes:

  • Remove NativeAOT properties (CppLibCreator, LinkerFlavor) that were only needed to support ILC’s LinkNative behavior.
  • Add a new Microsoft.Android.Sdk.NativeAOT.After.targets file to override LinkNative with a no-op for NativeAOT builds.
  • Import the new “After” targets file from Microsoft.Android.Sdk.After.targets when $(_AndroidRuntime) == 'NativeAOT'.
Show a summary per file
File Description
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.targets Removes properties that were previously required to make ILC’s LinkNative step work (now intended to be skipped).
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.After.targets Introduces a post-import override of LinkNative to avoid the llvm-ar archive creation step for NativeAOT.
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.After.targets Imports the new NativeAOT “After” targets file conditionally for NativeAOT runtime builds.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 1

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sbomer
sbomer enabled auto-merge (squash) May 12, 2026 21:49
@sbomer sbomer self-assigned this May 13, 2026
@simonrozsival
simonrozsival disabled auto-merge May 13, 2026 06:08
@simonrozsival
simonrozsival merged commit d470b5c into main May 13, 2026
3 checks passed
@simonrozsival
simonrozsival deleted the dev/sbomer/skip-llvm-ar branch May 13, 2026 06:08
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants