Skip to content

[xabt] Invalidate linker cache when Android properties change - #13218

Merged
jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers-main-linker-cache-fix
Oct 21, 2026
Merged

jonathanpeppers merged 2 commits into
mainfrom
jonathanpeppers-main-linker-cache-fix

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

Port the linker-cache fix from #13158 to main.

When Android build properties change, build.props changes, but _RunILLink does not track it. On the release branch, switching from CoreCLR to Mono can therefore reuse incompatible linked assemblies and fail Mono AOT with Runtime critical type System.Diagnostics.MonoStackFrame not found.

Add the Android-owned _AndroidInvalidateLinkerCache target from commit 3dd8d4e. Before linking, it deletes each RID's semaphore if build.props is newer. Unchanged builds still skip linking. No changes to MSBuildAllProjects. Main already has the runtime cache entries and the timestamp fix from #13144.

Extend PostTrimmingPipelineIsSkippedOnSecondBuild in IncrementalBuildTest.cs to check cached property changes and subsequent unchanged builds for arm64 and x64. No new test file or test helpers.

Validation:

  • .\dotnet-local.cmd test src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Xamarin.Android.Build.Tests.csproj --filter Name~PostTrimmingPipelineIsSkippedOnSecondBuild -v minimal -bl:bin\BuildDebug\incremental-linker-tests.binlog: test project builds, but both cases fail on the first app build with NETSDK1147: the local SDK is missing android and wasm-tools-net11 workloads. Confirmed with binlogtool search bin\TestDebug\temp\PostTrimmingPipelineIsSkippedOnSecondBuildarm64-v8a\build.binlog '$error'. The new assertions remain unverified.
  • .\build.cmd: previously attempted twice; SDK preparation stops at MSB3027/MSB3021 because a Java.Interop MSBuild task process locks Xamarin.Android.Tools.AndroidSdk.dll. Full SDK and device validation remain blocked.
  • git diff --cached --check: passed before commit.

Pull Request
title and
description
should follow the
commit-messages.md workflow documentation, and in particular should include:

  • Useful description of why the change is necessary.
  • Links to issues fixed
  • Unit tests

Port the linker-cache fix from #13158 to main.  Runtime switches share
RID-specific linked outputs, but ILLink does not track build.props.
Delete each RID's link semaphore when the Android property cache is
newer so a CoreCLR-to-Mono switch cannot reuse incompatible assemblies.

Keep unchanged builds incremental and leave MSBuildAllProjects alone.
Add focused MSBuild coverage using the Android cache target and the
SDK's linker incremental contract for both arm64 and x64.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 2766caf5-8f62-405b-be06-72cebd330d0c
Copilot AI balanced review requested due to automatic review settings October 20, 2026 19:19

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.

🔵 Needs a closer look

Reported standalone tests pass, but the blocked SDK build leaves actual trimming and Mono AOT integration unverified.

No open issues 🎉

What changed in this PR

Prevents stale linked assemblies from being reused when Android build properties change, including switches between CoreCLR and MonoVM.

Changes:

  • Invalidates each RID’s linker semaphore when the Android property cache is newer.
  • Adds regression coverage for runtime switches, first builds, and unchanged-build skips across two RIDs.
File Description
src/​Xamarin.Android.Build.Tasks/​Microsoft.Android.Sdk/​targets/​Microsoft.Android.Sdk.AssemblyResolution.targets Adds property-cache-driven linker invalidation.
src/​Microsoft.Android.Build.Tasks/​Tests/​Microsoft.Android.Build.Tasks.Tests/​LinkerCacheTargetsTests.cs Tests runtime-switch invalidation and incremental skips.

Review effort: Balanced

Remove the separate target test and extend the existing post-trimming
incremental build test.  Check cached property changes and unchanged
builds for arm64 and x64 using the real app build pipeline.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 2766caf5-8f62-405b-be06-72cebd330d0c
@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Oct 21, 2026
@jonathanpeppers

Copy link
Copy Markdown
Member Author

@dalexsoto review

@dalexsoto dalexsoto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The pre-link target invalidates each RID's linker semaphore when Android's property cache is newer, while unchanged property sets retain incremental skips. The extended CoreCLR regression covers changed and unchanged builds for arm64 and x64, and the actual SDK import/order and NativeAOT exclusion contracts remain consistent. Source review only; no linking or AOT execution is certified.

@jonathanpeppers
jonathanpeppers merged commit f7debd5 into main Oct 21, 2026
41 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers-main-linker-cache-fix branch October 21, 2026 21:35
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants