[dotnet-linker] Use [DynamicDependency] attributes instead of manual marking when preserving smart enum methods.#24934
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the dotnet-linker integration to preserve smart-enum conversion methods by injecting [DynamicDependency] attributes instead of manually marking methods in a custom mark handler, supporting the longer-term goal of removing custom linker steps (issue #17693).
Changes:
- Added a new
PreserveSmartEnumConversionsStepthat scans assemblies forBindAsAttributeusage and addsDynamicDependencyattributes to keepGetConstant/GetValue. - Refactored the existing
PreserveSmartEnumConversionsHandlerto reuse shared preservation logic. - Extended
AppBundleRewriterwith a helper to addDynamicDependencyattributes, and wired the new step intoXamarin.Shared.Sdk.targetsbehind a property toggle.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tools/linker/MonoTouch.Tuner/PreserveSmartEnumConversions.cs | Refactors mark handler to delegate smart-enum detection/preservation to shared helper logic. |
| tools/dotnet-linker/PreserveSmartEnumConversionsStep.cs | Introduces a new pre-mark linker step that injects DynamicDependency attributes for smart-enum conversions. |
| tools/dotnet-linker/AppBundleRewriter.cs | Adds a DynamicDependencyAttribute ctor reference and a convenience method to attach the attribute based on type/module location. |
| dotnet/targets/Xamarin.Shared.Sdk.targets | Adds a property toggle and registers the new step conditionally, keeping the old handler as fallback. |
You can also share your feedback on Copilot code review. Take the survey.
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.
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…marking when preserving smart enum methods. This makes it easier to move this code out of a custom linker step in the future. Contributes towards #17693.
2d2685d to d4e05fb Compare 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.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR updates the dotnet-linker pipeline to preserve smart enum conversion methods by injecting DynamicDependency attributes (when enabled) instead of relying solely on manual marking in a custom mark handler, helping reduce reliance on custom linker steps (issue #17693).
Changes:
- Introduces a new
PreserveSmartEnumConversionsStep(anAssemblyModifierStep) that addsDynamicDependencyattributes to root smart enum conversion methods. - Refactors the existing
PreserveSmartEnumConversionsHandlerto reuse shared preservation logic. - Extends
AppBundleRewriterwith helpers to addDynamicDependencyattributes (including a guard to only add dependencies targeting trimmed assemblies) and wires the new step intoXamarin.Shared.Sdk.targets.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/linker/MonoTouch.Tuner/PreserveSmartEnumConversions.cs | Refactors the mark handler to delegate logic to a shared preserver helper. |
| tools/dotnet-linker/PreserveSmartEnumConversionsStep.cs | Adds a new assembly-modifier step that preserves smart enum conversions via DynamicDependency attributes. |
| tools/dotnet-linker/PreserveProtocolsStep.cs | Adds clarifying comment about only processing linked assemblies. |
| tools/dotnet-linker/AppBundleRewriter.cs | Adds DynamicDependency ctor lookup + helper to apply dependency attributes (and trims-only guard). |
| dotnet/targets/Xamarin.Shared.Sdk.targets | Adds MSBuild switches and wires in the new step, keeping the legacy handler as fallback. |
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…dependency-attributes-preservesmartenumconversion
✅ [CI Build #a92fbe4] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #a92fbe4] Build passed (Detect API changes) ✅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 |
✅ [CI Build #a92fbe4] Build passed (Build macOS tests) ✅Pipeline on Agent |
🔥 [CI Build #a92fbe4] Test results 🔥Test results❌ Tests failed on VSTS: test results 0 tests crashed, 32 tests failed, 124 tests passed. Failures❌ linker tests1 tests failed, 43 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (iOS)9 tests failed, 2 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (MacCatalyst)12 tests failed, 3 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (macOS)9 tests failed, 3 tests passed.Failed tests
Html Report (VSDrops) Download ❌ Tests on macOS Tahoe (26) tests1 tests failed, 4 tests passed.Failed tests
Html Report (VSDrops) Download Successes✅ cecil: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
This makes it easier to move this code out of a custom linker step in the future.
Contributes towards #17693.