Skip to content

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

Open
rolfbjarne wants to merge 8 commits intomainfrom
dev/rolf/use-dynamic-dependency-attributes-preservesmartenumconversion
Open

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

Conversation

@rolfbjarne
Copy link
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
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.

@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
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.

@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
Copy link
Collaborator

🔥 [CI Build #9cfacc0] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 12 tests failed, 144 tests passed.

Failures

❌ linker tests

1 tests failed, 43 tests passed.

Failed tests

  • link all/iOS - simulator/Release: LaunchFailure

Html Report (VSDrops) Download

❌ monotouch tests (tvOS)

11 tests failed, 0 tests passed.

Failed tests

  • monotouch-test/tvOS - simulator/Debug: BuildFailure
  • monotouch-test/tvOS - simulator/Debug (LinkSdk): BuildFailure
  • monotouch-test/tvOS - simulator/Debug (static registrar): BuildFailure
  • monotouch-test/tvOS - simulator/Release (all optimizations): BuildFailure
  • monotouch-test/tvOS - simulator/Debug (ARM64): BuildFailure
  • monotouch-test/tvOS - simulator/Release (NativeAOT, ARM64): BuildFailure
  • monotouch-test/tvOS - simulator/Debug (managed static registrar): BuildFailure
  • monotouch-test/tvOS - simulator/Release (managed static registrar, all optimizations): BuildFailure
  • monotouch-test/tvOS - simulator/Release (NativeAOT, x64): BuildFailure
  • monotouch-test/tvOS - simulator/Debug (interpreter): BuildFailure
  • monotouch-test/tvOS - simulator/Release (interpreter): BuildFailure

Html Report (VSDrops) Download

Successes

✅ 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
✅ 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
✅ 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: 9cfacc05e341669a97a6ff423c28cfb2fbc49ffd [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

Pipeline on Agent
Hash: 54cf0f64c18cf2df463d82300d3bc263a54fcfa4 [PR build]

@vs-mobiletools-engineering-service2
Copy link
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
Collaborator

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

Pipeline on Agent
Hash: 54cf0f64c18cf2df463d82300d3bc263a54fcfa4 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

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

Pipeline on Agent
Hash: 54cf0f64c18cf2df463d82300d3bc263a54fcfa4 [PR build]

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