Repository navigation
feat: Add Native AOT support for attached properties via unified LinkerDescriptorGeneratorTask - #23134
Conversation
…t of attached properties Agent-Logs-Url: https://github.com/unoplatform/uno/sessions/2295d33c-bfd3-4a2c-b5b3-cdde5c5e1272 Co-authored-by: jonpryor <[email protected]>
|
|
|
@Copilot: on further consideration, having every referenced assembly loaded into two (or more?) separate tasks is going to slow the build down. Please rename We want to produce multiple |
Done in 9555092. The two separate tasks ( The new design:
The targets file now has a single |
|
@copilot: PR #23148 updated |
…d-properties-support Co-authored-by: jonpryor <[email protected]>
Done — merged master into the branch in commit |
|
@copilot: the reason for this previous request was to share loaded Cecil instances across the new "subtasks" such as What you implemented might not share anything! Consider All assembly and type loading should be done within |
…nerators in LinkerDescriptorGeneratorTask Agent-Logs-Url: https://github.com/unoplatform/uno/sessions/720f96b1-d5d6-4544-8178-cdab44c3db02 Co-authored-by: jonpryor <[email protected]>
Done in
|
The fix from
You can verify with |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23134/wasm-skia-net9/index.html |
There was a problem hiding this comment.
Pull request overview
This PR updates the Uno.UI.Tasks linker-hints tooling to better support Native AOT/trimming by generating ILLink descriptor files that preserve (1) bindable-type referenced property metadata and (2) attached-property GetX/SetX accessors, while loading the assembly closure only once.
Changes:
- Replaces the prior bindable-only task with a unified
LinkerDescriptorGeneratorTask_v0that builds a shared flatList<TypeDefinition>and sharedTypeDefinitionCache, then runs multiple descriptor generators. - Adds an
AttachedPropertiesDescriptorGeneratorthat emitsUno.AttachedProperties.Descriptor.xmlby scanning forDependencyPropertymembers ending inPropertyand preserving matchingGet<Name>/Set<Name>static methods. - Updates
Uno.UI.Tasks.targetsto run the unified task and register both produced descriptor files asTrimmerRootDescriptorinputs.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/SourceGenerators/Uno.UI.Tasks/LinkerHintsGenerator/LinkerDescriptorGeneratorTask.cs | Introduces the unified MSBuild task, shared type enumeration/cache, and the new attached-properties descriptor generator. |
| src/SourceGenerators/Uno.UI.Tasks/Content/Uno.UI.Tasks.targets | Switches MSBuild wiring to the unified task and includes both generated descriptor outputs for ILLink. |
Comments suppressed due to low confidence (1)
src/SourceGenerators/Uno.UI.Tasks/LinkerHintsGenerator/LinkerDescriptorGeneratorTask.cs:249
- When a generator has no results,
WriteDescriptorIfResultsonly logs and skips writing, leaving any previous descriptor file on disk. Because the MSBuild target later includes the descriptor based onExists(...), a stale file from an earlier build can keep trimming roots that are no longer valid. Consider deleting the existing output file (if present) whenHasResultsis false, or always rewriting an empty descriptor to avoid stale artifacts in incremental builds.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-23134/wasm-skia-net9/index.html |
PR Type:
✨ Feature / 🔄 Refactoring
What changed? 🚀
In Native AOT / trimming scenarios,
Get<Name>/Set<Name>accessors for attachedDependencyPropertymembers are silently removed by the linker because no static reference connects them to the property registration — requiring manual[DynamicDependency]annotations on every accessor.Previously,
BindableTypeLinkerGeneratorTask_v0handled bindable-type descriptor generation as a standalone task. A separateAttachedPropertiesLinkerGeneratorTask_v0would have loaded the full transitive assembly closure a second time, slowing down builds.Now, a single unified
LinkerDescriptorGeneratorTask_v0(inLinkerDescriptorGeneratorTask.cs) replaces both tasks. It loads the assembly closure once, builds a shared flatList<TypeDefinition>and a sharedTypeDefinitionCache, then runs both generators against that pre-built data:BindableTypeDescriptorGenerator— preserves public properties on types referenced by[Bindable]types, emittingUno.Bindable.Descriptor.xmlAttachedPropertiesDescriptorGenerator— scans forstaticfields/properties of typeMicrosoft.UI.Xaml.DependencyPropertywhose names end inProperty, derives the attached property name, and preserves matchingGet<Name>/Set<Name>static methods on the same type, emittingUno.AttachedProperties.Descriptor.xmlBoth generators share a common
LinkerDescriptorGeneratorabstract base class. TheirAnalyze(IReadOnlyList<TypeDefinition> allTypes, TypeDefinitionCache typeCache)method receives the pre-built type list and shared cache from the task — no generator independently enumerates assemblies or creates its own cache.Sharing strategy
LinkerDescriptorGeneratorTask_v0.Execute()callsBuildAllTypes(assemblyList)once to produce a singleList<TypeDefinition>(including all nested types) and creates oneTypeDefinitionCacheinstanceBuildAllTypesand type-cache creation happen in the task before any generator is calledTypeReference→TypeDefinitionresolution done byBindableTypeDescriptorGeneratoris cached and shared with any future generatorsStack overflow prevention
The two-step registration pattern from the master fix is incorporated into
BindableTypeDescriptorGenerator.AddDeclaredPropertyTypes(): a type is immediately registered intypesToPropertieswith an empty property set as soon as it is first seen, before its generic arguments and base type are processed. This breaks cycles in self-referencing type hierarchies (e.g.class MyInfo : SomeInfo<MyInfo>), preventing MSB4217 task host crashes during AOT publish. The corresponding regression test (SomeInfo<T>/MyInfo : SomeInfo<MyInfo>inSampleChooserCategory) is also included.Example —
XamlDisplayExtensions.HeaderPropertyproduces inUno.AttachedProperties.Descriptor.xml:MSBuild integration (
Uno.UI.Tasks.targets)<UsingTask>registration forLinkerDescriptorGeneratorTask_v0_UnoGenerateLinkerDescriptorstarget (replaces_UnoGenerateBindableTypeLinkerDescriptor): runsAfterTargets="CoreCompile"/BeforeTargets="PrepareForILLink", gated on$(IsUnoHead)==trueand$(PublishAot)==true<TrimmerRootDescriptor>and<FileWrites>The heuristic (strip
Propertysuffix, matchGet/Setprefix on the same type) covers the standard attached-property pattern without requiring IL method-body scanning. Edge cases where custom names deviate from convention still need manual[DynamicDependency]annotations.PR Checklist ✅
Screenshots Compare Test Runresults.