Skip to content

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

Draft
rolfbjarne wants to merge 2 commits intodev/rolf/use-dynamic-dependency-attributes-markiprotocolhandlerfrom
dev/rolf/use-dynamic-dependency-attributes-preservesmartenumconversion
Draft

[dotnet-linker] Use [DynamicDependency] attributes instead of manual marking when preserving smart enum methods.#24934
rolfbjarne wants to merge 2 commits intodev/rolf/use-dynamic-dependency-attributes-markiprotocolhandlerfrom
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.

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

}
}

protected override void ProcessAssembly(AssemblyDefinition assembly)
Comment on lines 29 to 33
bool Mark (Tuple<MethodDefinition, MethodDefinition> pair, bool alreadyProcessed, params MethodDefinition?[] conditions)
{
if (alreadyProcessed)
return false;
Context.Annotations.Mark (pair.Item1);
Comment on lines +1 to +12
// Copyright 2017 Xamarin Inc.

using System.Linq;

using Mono.Cecil;
using Mono.Linker;
using Mono.Linker.Steps;
using Mono.Tuner;

using Xamarin.Bundler;
using Xamarin.Tuner;

@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 #2d2685d] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 2d2685dd7f0d2c3efa40971c3a9a639badaa547c [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [PR Build #2d2685d] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 2d2685dd7f0d2c3efa40971c3a9a639badaa547c [PR build]

@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

✅ 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: 2d2685dd7f0d2c3efa40971c3a9a639badaa547c [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ [CI Build #2d2685d] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 2d2685dd7f0d2c3efa40971c3a9a639badaa547c [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

🔥 [CI Build #2d2685d] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

0 tests crashed, 15 tests failed, 141 tests passed.

Failures

❌ monotouch tests (iOS)

2 tests failed, 9 tests passed.

Failed tests

  • monotouch-test/iOS - simulator/Debug (static registrar): BuildFailure
  • monotouch-test/iOS - simulator/Release (all optimizations): BuildFailure

Html Report (VSDrops) Download

❌ monotouch tests (MacCatalyst)

7 tests failed, 8 tests passed.

Failed tests

  • monotouch-test/Mac Catalyst/Debug: Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • monotouch-test/Mac Catalyst/Debug (ARM64): Failed (Test run crashed (exit code: 134).
    No test log file was produced)
  • monotouch-test/Mac Catalyst/Debug (static registrar): BuildFailure
  • monotouch-test/Mac Catalyst/Debug (static registrar, ARM64): BuildFailure
  • monotouch-test/Mac Catalyst/Release (static registrar): BuildFailure
  • monotouch-test/Mac Catalyst/Release (static registrar, all optimizations): BuildFailure
  • monotouch-test/Mac Catalyst/Debug (interpreter): Failed (Test run crashed (exit code: 134).
    No test log file was produced)

Html Report (VSDrops) Download

❌ monotouch tests (tvOS)

2 tests failed, 9 tests passed.

Failed tests

  • monotouch-test/tvOS - simulator/Debug (static registrar): BuildFailure
  • monotouch-test/tvOS - simulator/Release (all optimizations): BuildFailure

Html Report (VSDrops) Download

❌ Tests on macOS Monterey (12) tests

1 tests failed, 4 tests passed.

Failed tests

  • monotouch-test: Failed

Html Report (VSDrops) Download

❌ Tests on macOS Ventura (13) tests

1 tests failed, 4 tests passed.

Failed tests

  • monotouch-test: Failed

Html Report (VSDrops) Download

❌ Tests on macOS Sequoia (15) tests

1 tests failed, 4 tests passed.

Failed tests

  • monotouch-test: Failed

Html Report (VSDrops) Download

❌ Tests on macOS Tahoe (26) tests

1 tests failed, 4 tests passed.

Failed tests

  • monotouch-test: Failed

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
✅ linker: All 44 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 Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download

Pipeline on Agent
Hash: 2d2685dd7f0d2c3efa40971c3a9a639badaa547c [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.

3 participants