Skip to content

[dotnet-linker] Use [DynamicDependency] attributes instead of manual marking when preserving smart enum methods.#24934

Merged
rolfbjarne merged 8 commits intomainfrom
dev/rolf/use-dynamic-dependency-attributes-preservesmartenumconversion
Mar 27, 2026
Merged

[dotnet-linker] Use [DynamicDependency] attributes instead of manual marking when preserving smart enum methods.#24934
rolfbjarne merged 8 commits intomainfrom
dev/rolf/use-dynamic-dependency-attributes-preservesmartenumconversion

Conversation

@rolfbjarne
Copy link
Copy Markdown
Member

This makes it easier to move this code out of a custom linker step in the future.

Contributes towards #17693.

@rolfbjarne rolfbjarne requested a review from Copilot March 19, 2026 13:32
Copy link
Copy Markdown
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 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 PreserveSmartEnumConversionsStep that scans assemblies for BindAsAttribute usage and adds DynamicDependency attributes to keep GetConstant/GetValue.
  • Refactored the existing PreserveSmartEnumConversionsHandler to reuse shared preservation logic.
  • Extended AppBundleRewriter with a helper to add DynamicDependency attributes, and wired the new step into Xamarin.Shared.Sdk.targets behind 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.

Comment thread tools/dotnet-linker/PreserveSmartEnumConversionsStep.cs Outdated
Comment thread tools/linker/MonoTouch.Tuner/PreserveSmartEnumConversions.cs Outdated
Comment thread tools/dotnet-linker/PreserveSmartEnumConversionsStep.cs
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

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.
@rolfbjarne rolfbjarne force-pushed the dev/rolf/use-dynamic-dependency-attributes-preservesmartenumconversion branch from 2d2685d to d4e05fb Compare March 23, 2026 18:39
@rolfbjarne rolfbjarne changed the base branch from dev/rolf/use-dynamic-dependency-attributes-markiprotocolhandler to main March 23, 2026 18:40
@rolfbjarne rolfbjarne marked this pull request as ready for review March 23, 2026 18:41
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

Copy link
Copy Markdown
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 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 (an AssemblyModifierStep) that adds DynamicDependency attributes to root smart enum conversion methods.
  • Refactors the existing PreserveSmartEnumConversionsHandler to reuse shared preservation logic.
  • Extends AppBundleRewriter with helpers to add DynamicDependency attributes (including a guard to only add dependencies targeting trimmed assemblies) and wires the new step into Xamarin.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.

Comment thread tools/dotnet-linker/PreserveSmartEnumConversionsStep.cs Outdated
Comment thread tools/dotnet-linker/PreserveSmartEnumConversionsStep.cs Outdated
@rolfbjarne rolfbjarne enabled auto-merge (squash) March 23, 2026 19:39
@vs-mobiletools-engineering-service2

This comment has been minimized.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #54cf0f6] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 54cf0f64c18cf2df463d82300d3bc263a54fcfa4 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 54cf0f64c18cf2df463d82300d3bc263a54fcfa4 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #54cf0f6] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 54cf0f64c18cf2df463d82300d3bc263a54fcfa4 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #54cf0f6] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 54cf0f64c18cf2df463d82300d3bc263a54fcfa4 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

🚀 [CI Build #54cf0f6] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 156 tests passed 🎉

Tests counts

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 12 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 11 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: 54cf0f64c18cf2df463d82300d3bc263a54fcfa4 [PR build]

@rolfbjarne rolfbjarne merged commit cc7cc5d into main Mar 27, 2026
48 checks passed
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.

4 participants