feat: Make icon libraries AOT- and trim-compatible - #25
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, noRegexOptions.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 viaMSBuildProjectNameto the fourOptris.Icons.Avalonia*libraries (excludes tests, Demo, IconGenerator). No per-TFM guard needed — all targets are ≥ net8.0.IsAotCompatibleimpliesIsTrimmable+EnableTrimAnalyzer+EnableAotAnalyzer+EnableSingleFileAnalyzer.MaterialDesignIconProvider.cs— the two runtimenew Regex(...)→[GeneratedRegex]source-generated partials. Zero-reflection guarantee, no per-process pattern parsing.Demo/MainView.axaml— the lone{ReflectionBinding}→ compiled{Binding}viax:DataTypeon the style.Demo.Desktop.csproj—<PublishAot>true</PublishAot>by default, as an end-to-end proof.Verification
win-x64) links cleanly → self-contained ~31 MB native binary (no CoreCLR/JIT/managed app DLL).[GeneratedRegex]all working under AOT).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 genericIconProvider.Current.Register<…>()(already the documented, AOT-safe pattern). NoILLink.Descriptors.xmlis needed for these libraries.🤖 Generated with Claude Code