Skip to content

Add IsAotCompatible for net8.0 and later targets - #963

Merged
xoofx merged 2 commits into
xoofx:mainfrom
StefanGreve:aot-compatible
Oct 19, 2026
Merged

xoofx merged 2 commits into
xoofx:mainfrom
StefanGreve:aot-compatible

Conversation

@StefanGreve

Copy link
Copy Markdown
Contributor

AGENTS.md asks for Markdig to stay AOT- and trimmer-friendly, but nothing in the build checks it today: the trim, AOT and single-file analyzers only run in a library that opts in. Setting IsAotCompatible turns them on for every net8.0+ build, so a change that introduces reflection shows up as a warning in Markdig's own CI instead of in a consumer's PublishAot output, and apps that set VerifyReferenceAotCompatibility no longer get IL3058 for Markdig.

The property goes into Markdig.targets, so Markdig.Signed gets it too, and it is limited to net8.0+ with the condition from the Native AOT docs. No source changes were needed: both targets build with no IL2xxx/IL3xxx warnings, and a PublishAot app against this branch builds without IL3058 and renders correctly. The new tests check the emitted assembly metadata; IsAotCompatible is only asserted on net10.0, because the ILLink version the SDK uses for net8.0 only emits IsTrimmable.

* Enable the trim, AOT and single-file analyzers in Markdig's own build, so
  CI catches an AOT regression before it ships to consumers
* Limit the property to net8.0+, since the analyzers do not run on
  netstandard and net462 targets
* Test the assembly metadata, asserting IsAotCompatible only on net10.0,
  because the ILLink 8 build tasks used for net8.0 emit just IsTrimmable

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@MihaZupan

Copy link
Copy Markdown
Collaborator

Thanks.
Looks like the netstandard tests aren't happy about this one yet

@StefanGreve

Copy link
Copy Markdown
Contributor Author

I am looking into this, and check how other project verify project settings reliably.

* Replace the assembly metadata unit tests, which failed in the netstandard
  workflow because it builds Markdig for netstandard2.x only
* Add Markdig.AotTests with VerifyReferenceAotCompatibility and IL3058 as an
  error, so the CI solution build fails if Markdig loses the AOT marking
* Leave PublishAot unset, so the check restores no package beyond the
  ILLink.Tasks package the IsAotCompatible property already requires

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@StefanGreve

Copy link
Copy Markdown
Contributor Author

Rather than asserting that a project setting is correctly configured, I opted for a small Markdig.AotTests project, along the lines of Tomlyn.AotTests, that checks the result the way a consumer's build does: it references Markdig with VerifyReferenceAotCompatibility and treats IL3058 as an error, so the CI build of markdig.slnx fails if Markdig is ever no longer marked AOT-compatible.

The unit tests introduced in the first commit would have been slightly harder to maintain, because they would have had to account for which Markdig build a test run loads, and for net8.0, where the ILLink 8 tasks emit IsTrimmable but not IsAotCompatible. IL3058, on the other hand, is reported by the same ILLink package that writes that metadata, so Markdig no longer has to know which SDK version emits what.

@xoofx

xoofx commented Oct 19, 2026

Copy link
Copy Markdown
Owner

Thanks @StefanGreve, this is a welcome change! 🙏

I checked it locally: Markdig builds on all targets with no IL2xxx/IL3xxx warnings. I also removed the IsAotCompatible line temporarily, and Markdig.AotTests then fails with IL3058 as expected, so the guard works. net462/netstandard* are left alone by the IsTargetFrameworkCompatible condition, and Markdig.Signed picks it up through Markdig.targets. (Small note: the PR description still mentions metadata tests, which the second commit replaced with the IL3058 build check.) Merging.

Review done via CodeAlta / Opus 5.5.

@xoofx
xoofx merged commit 55e9ec7 into xoofx:main Oct 19, 2026
3 checks passed
@StefanGreve
StefanGreve deleted the aot-compatible branch October 19, 2026 19:44
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