Skip to content

[dotnet-linker] Use [DynamicDependency] attributes instead of manual marking when marking static registrar methods.#25018

Merged
rolfbjarne merged 1 commit intomainfrom
dev/rolf/use-dynamic-dependency-attributes-markstaticregistrar
Apr 14, 2026
Merged

[dotnet-linker] Use [DynamicDependency] attributes instead of manual marking when marking static registrar methods.#25018
rolfbjarne merged 1 commit intomainfrom
dev/rolf/use-dynamic-dependency-attributes-markstaticregistrar

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.

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

Updates the dotnet-linker pipeline to preserve static-registrar-related delegate proxy Invoke methods by injecting [DynamicDependency] attributes, moving away from manual marking to support future removal of custom linker steps (per #17693).

Changes:

  • Add MarkForStaticRegistrarStep (an AssemblyModifierStep) that adds dynamic dependency attributes for delegate proxy Invoke methods.
  • Disable the existing MarkForStaticRegistrar mark substep when the new step runs (via a flag in DerivedLinkContext).
  • Wire the new step into the MSBuild trimmer custom steps behind a new _UseDynamicDependenciesForMarkStaticRegistrar property.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tools/dotnet-linker/MarkForStaticRegistrarStep.cs New assembly-modifier step that injects dynamic dependency attributes to preserve delegate proxy Invoke methods for the static registrar.
tools/dotnet-linker/MarkForStaticRegistrar.cs Skips the existing mark substep when the new pre-MarkStep custom step has run.
tools/common/DerivedLinkContext.cs Adds a DidRunMarkForStaticRegistrarStep flag to coordinate between the two implementations.
dotnet/targets/Xamarin.Shared.Sdk.targets Adds a new build property and enables the new step before MarkStep when dynamic dependencies are enabled.

Comment thread tools/dotnet-linker/MarkForStaticRegistrarStep.cs
Comment thread tools/dotnet-linker/MarkForStaticRegistrarStep.cs
Comment thread dotnet/targets/Xamarin.Shared.Sdk.targets Outdated
@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.

@rolfbjarne rolfbjarne force-pushed the dev/rolf/use-dynamic-dependency-attributes-applypreserveattribute branch 3 times, most recently from d8b772e to d7fde5c Compare April 1, 2026 10:02
…marking when marking static registrar 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-markstaticregistrar branch from 653b289 to 4655a1a Compare April 14, 2026 10:17
@rolfbjarne rolfbjarne changed the base branch from dev/rolf/use-dynamic-dependency-attributes-applypreserveattribute to main April 14, 2026 10:18
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
2 pipeline(s) require an authorized user to comment /azp run to run.

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

✅ [CI Build #4655a1a] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 4655a1a56d8087c9d602ee6c3d442efd2bf1105b [PR build]

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

✅ [PR Build #4655a1a] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 4655a1a56d8087c9d602ee6c3d442efd2bf1105b [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: 4655a1a56d8087c9d602ee6c3d442efd2bf1105b [PR build]

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

✅ [CI Build #4655a1a] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 4655a1a56d8087c9d602ee6c3d442efd2bf1105b [PR build]

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

🚀 [CI Build #4655a1a] 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: 4655a1a56d8087c9d602ee6c3d442efd2bf1105b [PR build]

@rolfbjarne rolfbjarne marked this pull request as ready for review April 14, 2026 14:24
@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines:
2 pipeline(s) require an authorized user to comment /azp run to run.

@rolfbjarne rolfbjarne enabled auto-merge (squash) April 14, 2026 14:24
@rolfbjarne rolfbjarne merged commit b16c025 into main Apr 14, 2026
46 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