[msbuild/tools] Move post-trimming custom trimmer steps to a post-ILLink MSBuild task.#25742
[msbuild/tools] Move post-trimming custom trimmer steps to a post-ILLink MSBuild task.#25742rolfbjarne wants to merge 12 commits into
Conversation
…embly in the AssemblyPreparerInfo.
There was a problem hiding this comment.
Pull request overview
This PR is a WIP step toward replacing custom ILLink linker steps by moving the “post-trimming” work into an MSBuild task (assembly preparer mode), enabling a trimmer-agnostic pipeline (ILLink and future NativeAOT scenarios).
Changes:
- Introduces an MSBuild-driven post-processing phase for prepared assemblies (
PostProcessAssemblies+_PostprocessAssembliestarget). - Refactors/extends assembly-preparer to load assemblies, run pre/post steps, and save results (new steps + expanded pipeline).
- Adapts several linker steps to run both in the traditional linker pipeline and in assembly-preparer mode; adds a Windows remote test for assembly preparer.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/linker/RemoveUserResourcesSubStep.cs | Updates the step to work in both linker and assembly-preparer pipelines. |
| tools/linker/MonoTouch.Tuner/ListExportedSymbols.cs | Adds ASSEMBLY_PREPARER support for the step. |
| tools/dotnet-linker/Steps/RegistrarStep.cs | Adjusts registrar filtering behavior for assembly-preparer mode. |
| tools/dotnet-linker/Steps/GenerateReferencesStep.cs | Switches to StringUtils.IsNullOrEmpty for consistency. |
| tools/dotnet-linker/Steps/ExtractBindingLibrariesStep.cs | Uses PathUtils.AbsoluteToRelative instead of Path.GetRelativePath. |
| tools/dotnet-linker/LinkerConfiguration.cs | Extends configuration for assembly-preparer mode (AssemblyInfos, etc). |
| tools/common/Application.cs | Adds an explicit IsPostProcessingAssemblies flag for assembly-preparer mode. |
| tools/assembly-preparer/SaveAssembliesStep.cs | New step to write assemblies after processing (and strip crossgen markers). |
| tools/assembly-preparer/LoadAssembliesStep.cs | New step to load assemblies + determine trimming action. |
| tools/assembly-preparer/ComputeMethodOverridesStep.cs | New step to precompute method overrides into annotations. |
| tools/assembly-preparer/CollectFieldsStep.cs | New step to collect exported field symbols (compat for InlineDlfcn). |
| tools/assembly-preparer/AssemblyPreparer.cs | Splits pipeline into Prepare vs PostProcess and runs step lists accordingly. |
| tools/assembly-preparer/assembly-preparer.csproj | Wires additional steps and dependencies into the assembly-preparer tool. |
| tests/dotnet/UnitTests/WindowsTest.cs | Adds a remote Windows test validating assembly-preparer behavior/artifacts. |
| msbuild/Xamarin.Shared/Xamarin.Shared.targets | Adds PostProcessAssemblies and introduces _PostprocessAssemblies target. |
| msbuild/Xamarin.MacDev.Tasks/Tasks/PrepareAssemblies.cs | Adds a post-processing mode invocation path for AssemblyPreparer. |
| dotnet/targets/Xamarin.Shared.Sdk.targets | Avoids running existing custom trimmer steps when post-processing is enabled. |
| @@ -44,6 +54,7 @@ protected override void EndProcess () | |||
| base.EndProcess (); | |||
| } | |||
| <Target | ||
| Name="_PostprocessAssemblies" | ||
| Condition="'$(PrepareAssemblies)' == 'true'" | ||
| Inputs="@(_PreparedAssemblies)" | ||
| Outputs="$(_PrepareAssembliesStampFile)" | ||
| BeforeTargets="_LoadLinkerOutput" | ||
| > | ||
| <PrepareAssemblies | ||
| InputAssemblies="@(_PreparedAssemblies)" | ||
| MakeReproPath="$(_PostprocessAssembliesMakeReproPath)" | ||
| OptionsFile="$(_CustomLinkerOptionsFile)" | ||
| OriginalAssemblies="$(_AssembliesToPrepare)" | ||
| Postprocessing="true" | ||
| TargetFrameworkMoniker="$(_ComputedTargetFrameworkMoniker)" | ||
| > | ||
| <Output TaskParameter="OutputAssemblies" ItemName="_PostProcessedAssemblies" /> | ||
| </PrepareAssemblies> | ||
|
|
||
| <ItemGroup> | ||
| <ResolvedFileToPublish Remove="@(_PreparedAssemblies)" /> | ||
| <ResolvedFileToPublish Include="@(_PostProcessedAssemblies)" /> | ||
| <FileWrites Include="@(_PostProcessedAssemblies)" /> | ||
| </ItemGroup> | ||
| </Target> |
| foreach (var assembly in configuration.AssemblyInfos) { | ||
| var assemblyDefinition = assembly.Assembly; | ||
| if (assemblyDefinition is null) { | ||
| exceptions.Add (ErrorHelper.CreateError (99, $"Assembly definition is null for {assembly.InputPath}")); | ||
| return; | ||
| } |
| try { | ||
| assemblyDefinition.Write (assembly.OutputPath, writerParameters); | ||
| ModuleAttributes m = assemblyDefinition.MainModule.Attributes; | ||
| } catch (Exception e) { |
| @@ -0,0 +1,89 @@ | |||
| // Copilot: add license | |||
| @@ -0,0 +1,124 @@ | |||
| // Copilot: add license | |||
| @@ -0,0 +1,57 @@ | |||
| // Copilot: add license | |||
| @@ -0,0 +1,14 @@ | |||
| // Copilot: add license | |||
| using var memoryStream = new MemoryStream ((int) infoPlistEntry!.Length); | ||
| using var plistStream = infoPlistEntry.Open (); | ||
| plistStream.CopyTo (memoryStream); | ||
|
|
||
| var infoPlist = (PDictionary) PDictionary.FromStream (memoryStream)!; |
| public ITaskItem [] OriginalAssemblies { get; set; } = []; | ||
|
|
||
| public bool PostProcessing { get; set; } |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #8a3a11e] Build passed (Detect API changes) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #8a3a11e] Build passed (Build packages) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #8a3a11e] Build passed (Build macOS tests) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🔥 [CI Build #8a3a11e] Test results 🔥Test results❌ Tests failed on VSTS: test results 0 tests crashed, 61 tests failed, 159 tests passed. Failures❌ dotnettests tests (iOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (MacCatalyst)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (macOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (Multiple platforms)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (tvOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ generator tests1 tests failed, 4 tests passed.Failed tests
Html Report (VSDrops) Download ❌ interdependent-binding-projects tests2 tests failed, 2 tests passed.Failed tests
Html Report (VSDrops) Download ❌ linker tests (iOS)5 tests failed, 10 tests passed.Failed tests
Html Report (VSDrops) Download ❌ linker tests (MacCatalyst)4 tests failed, 11 tests passed.Failed tests
Html Report (VSDrops) Download ❌ linker tests (macOS)10 tests failed, 11 tests passed.Failed tests
Html Report (VSDrops) Download ❌ linker tests (tvOS)4 tests failed, 11 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (iOS)21 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (MacCatalyst)1 tests failed, 23 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (macOS)2 tests failed, 22 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (tvOS)1 tests failed, 20 tests passed.Failed tests
Html Report (VSDrops) Download ❌ windows tests3 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ xcframework tests2 tests failed, 2 tests passed.Failed tests
Html Report (VSDrops) [Download](https://devdiv.visualstudio.com/DevDiv/_apis/build/builds/14417896/artif\n\nThe message from CI is too large for the GitHub comments. You can find the full results here. |
WIP WIP WIP.
Contributes towards #17693.