Skip to content

feat: Make icon libraries AOT- and trim-compatible - #25

Merged
valentino-saitz-optris merged 1 commit into
mainfrom
aot-compliance
Jun 16, 2026
Merged

feat: Make icon libraries AOT- and trim-compatible#25
valentino-saitz-optris merged 1 commit into
mainfrom
aot-compliance

Conversation

@valentino-saitz-optris

Copy link
Copy Markdown
Collaborator

Summary

Makes the four shipping libraries AOT- and trim-compatible — and enforced as such on every build.

The libraries were already AOT-safe by design (source-generated JSON, manifest-resource loading, compiled XAML, no Reflection.Emit, no RegexOptions.Compiled). This PR declares that contract so the trim/AOT/single-file analyzers run continuously and catch any regression.

Changes

  • src/Directory.Build.props<IsAotCompatible>true</IsAotCompatible>, scoped via MSBuildProjectName to the four Optris.Icons.Avalonia* libraries (excludes tests, Demo, IconGenerator). No per-TFM guard needed — all targets are ≥ net8.0. IsAotCompatible implies IsTrimmable + EnableTrimAnalyzer + EnableAotAnalyzer + EnableSingleFileAnalyzer.
  • MaterialDesignIconProvider.cs — the two runtime new Regex(...)[GeneratedRegex] source-generated partials. Zero-reflection guarantee, no per-process pattern parsing.
  • Demo/MainView.axaml — the lone {ReflectionBinding} → compiled {Binding} via x:DataType on the style.
  • Demo.Desktop.csproj<PublishAot>true</PublishAot> by default, as an end-to-end proof.

Verification

  • ✅ Full Release build with trim/AOT analyzers active: 0 IL2xxx / 0 IL3xxx warnings across all libraries (incl. the new pro stream-provider classes).
  • ✅ Real Native AOT publish (win-x64) links cleanly → self-contained ~31 MB native binary (no CoreCLR/JIT/managed app DLL).
  • ✅ The native exe runs: opens, renders FontAwesome + FontAwesome7 + Material Design icons (source-gen JSON, embedded resources, [GeneratedRegex] all working under AOT).
  • ✅ All tests pass on net8.0 / net9.0 / net10.0.

Consumer note

A clean library ≠ a clean app. App authors still need Avalonia's standard AOT setup (PublishAot=true, native C++ toolchain, CompiledBindings in their own XAML) and must register providers via the generic IconProvider.Current.Register<…>() (already the documented, AOT-safe pattern). No ILLink.Descriptors.xml is needed for these libraries.

🤖 Generated with Claude Code

Declare <IsAotCompatible> on the four shipping libraries (scoped via
MSBuildProjectName in src/Directory.Build.props) so the trim/AOT/single-file
analyzers run on every build and enforce compatibility. The libraries were
already AOT-safe (source-generated JSON, manifest-resource loading, compiled
XAML, no Reflection.Emit); this turns that into a maintained guarantee.

- MaterialDesign: convert the two runtime regexes to [GeneratedRegex] for a
  zero-reflection guarantee and to drop per-process pattern parsing.
- Demo: replace the lone {ReflectionBinding} with a compiled {Binding} via
  x:DataType on the style.
- Demo.Desktop: enable PublishAot by default as an end-to-end proof. A native
  publish links cleanly and the app runs with all three providers rendering.

Verified: trim/AOT analyzer build is warning-clean (0 IL2xxx/IL3xxx), the
Native AOT publish produces a working self-contained native binary, and all
tests pass on net8.0/net9.0/net10.0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant