Skip to content

Move StripEmbeddedLibraries to MSBuild task#10894

Open
sbomer wants to merge 5 commits intomainfrom
dev/sbomer/stripembedded-innerbuild
Open

Move StripEmbeddedLibraries to MSBuild task#10894
sbomer wants to merge 5 commits intomainfrom
dev/sbomer/stripembedded-innerbuild

Conversation

@sbomer
Copy link
Member

@sbomer sbomer commented Mar 5, 2026

(Trying as an alternative to #10695 that should have fewer build changes, and avoids stripping R2R info from assemblies.)

Move embedded resource stripping out of the ILLink custom step so it runs after ILLink but before ReadyToRun/crossgen2 in the inner build, ensuring R2R images are generated from already-stripped assemblies.

  • Trimmed builds: new StripEmbeddedLibraries MSBuild task runs via _StripEmbeddedLibraries target (AfterTargets="ILLink") in the inner build, processing assemblies in-place with temp-write-copy-back.
  • Non-trimmed builds: new StripEmbeddedLibrariesStep added to LinkAssembliesNoShrink pipeline.
  • Shared ShouldStripResource() logic between both paths.
  • Removed old _TrimmerCustomSteps registration and deleted the ILLink StripEmbeddedLibraries.cs (now dead code).

sbomer added 4 commits March 5, 2026 15:50
…one MSBuild task and pipeline step

Move embedded resource stripping out of the ILLink custom step so it
runs after ILLink but before ReadyToRun/crossgen2 in the inner build,
ensuring R2R images are generated from already-stripped assemblies.

- Trimmed builds: new StripEmbeddedLibraries MSBuild task runs via
  _StripEmbeddedLibraries target (AfterTargets="ILLink") in the inner
  build, processing assemblies in-place with temp-write-copy-back.
- Non-trimmed builds: new StripEmbeddedLibrariesStep added to
  LinkAssembliesNoShrink pipeline.
- Shared ShouldStripResource() logic between both paths.
- Removed old _TrimmerCustomSteps registration and deleted the ILLink
  StripEmbeddedLibraries.cs (now dead code).
…er with search directories

When Cecil writes a modified assembly, it resolves type references during
metadata building (MetadataBuilder.GetConstantType). Without an assembly
resolver configured with search directories, this fails with
AssemblyResolutionException for references like Mono.Android.

Add a DefaultAssemblyResolver populated with unique directories from the
assembly list, matching the pattern used by AssemblyModifierPipeline.
@sbomer sbomer marked this pull request as ready for review March 12, 2026 17:18
Copilot AI review requested due to automatic review settings March 12, 2026 17:19
@sbomer sbomer requested a review from simonrozsival as a code owner March 12, 2026 17:19
Copy link
Contributor

Copilot AI left a comment

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 moves the StripEmbeddedLibraries logic from an ILLink custom step to a standalone MSBuild task that runs after ILLink but before ReadyToRun/crossgen2, ensuring R2R images are generated from already-stripped assemblies. For non-trimmed builds, a new StripEmbeddedLibrariesStep pipeline step handles stripping in LinkAssembliesNoShrink.

Changes:

  • New StripEmbeddedLibraries MSBuild task and _StripEmbeddedLibraries target for trimmed builds
  • New StripEmbeddedLibrariesStep pipeline step for non-trimmed builds, reusing shared ShouldStripResource() logic
  • Removed old ILLink StripEmbeddedLibraries custom step and its _TrimmerCustomSteps registration

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Xamarin.Android.Build.Tasks/Tasks/StripEmbeddedLibraries.cs New MSBuild task for stripping embedded resources from trimmed assemblies
src/Xamarin.Android.Build.Tasks/Linker/MonoDroid.Tuner/StripEmbeddedLibrariesStep.cs New pipeline step for non-trimmed builds
src/Xamarin.Android.Build.Tasks/Tasks/LinkAssembliesNoShrink.cs Adds the new step to the non-trimmed pipeline
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.TypeMap.LlvmIr.targets Registers task, adds target, removes old custom step
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj Includes new step source file
src/Microsoft.Android.Sdk.ILLink/StripEmbeddedLibraries.cs Deleted old ILLink step

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

🤖 AI Review Summary

Verdict: ⚠️ Needs Changes

Found 3 issues (3 warnings, 1 suggestion):

  • ⚠️ Nullable: StripEmbeddedLibrariesStep.cs missing #nullable enable (StripEmbeddedLibrariesStep.cs:1)
  • ⚠️ Error handling: Empty catch block silently swallows Exception (StripEmbeddedLibraries.cs:113)
  • ⚠️ Error codes: Log.LogWarning should use Log.LogCodedWarning with XA code (StripEmbeddedLibraries.cs:173)
  • 💡 MSBuild targets: AfterTargets="ILLink" should check $(MSBuildLastTaskResult) (TypeMap.LlvmIr.targets:260)

👍 Clean architecture — splitting the ILLink custom step into a shared ShouldStripResource() with both a pipeline step (non-trimmed) and MSBuild task (trimmed) is well-designed. The temp-write-copy-back pattern in the task avoids file locking issues. Good documentation in the target comments explaining when each path runs.


Review generated by android-reviewer from review guidelines.

…ition

- Add #nullable enable to StripEmbeddedLibrariesStep.cs
- Log exceptions in catch blocks instead of silently swallowing them
- Downgrade RemoveFile warning to LogDebugMessage (matches prevailing
  pattern for temp file cleanup failures)
- Add MSBuildLastTaskResult check to _StripEmbeddedLibraries target
  to skip when ILLink fails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants