Skip ILC LinkNative target for NativeAOT, remove llvm-ar dependency - #11329
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
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’sLinkNativebehavior. - Add a new
Microsoft.Android.Sdk.NativeAOT.After.targetsfile to overrideLinkNativewith a no-op for NativeAOT builds. - Import the new “After” targets file from
Microsoft.Android.Sdk.After.targetswhen$(_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>
simonrozsival
approved these changes
May 12, 2026
sbomer
enabled auto-merge (squash)
May 12, 2026 21:49
simonrozsival
disabled auto-merge
May 13, 2026 06:08
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Override ILC's
LinkNativetarget with a no-op for NativeAOT builds. WithNativeLib=static,LinkNativeonly runsllvm-arto create a.aarchive from the ILC-compiled.ofile. We never consume that.a—_AndroidLinkNativeAotSharedLibrarylinks the.odirectly into a.so.This eliminates the need for:
llvm-ar(not shipped in the workload toolchain)CppLibCreatorproperty pointing tollvm-arLinkerFlavorworkaround for NativeAOT: LinkNative target fails with MSB4086 when NativeLib=Static and LinkerFlavor=lld runtime#126978Changes
Microsoft.Android.Sdk.NativeAOT.targets: RemoveCppLibCreatorandLinkerFlavorproperties that were only needed for theLinkNativetarget we no longer run.Microsoft.Android.Sdk.NativeAOT.After.targets(new): Define theLinkNativeno-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.