Skip to content

Re-enable Release AOT by excluding only OpenCvSharp.dll - #9

Merged
shimat merged 3 commits into
mainfrom
experiment/partial-aot-exclude-opencvsharp
Jul 11, 2026
Merged

Re-enable Release AOT by excluding only OpenCvSharp.dll#9
shimat merged 3 commits into
mainfrom
experiment/partial-aot-exclude-opencvsharp

Conversation

@shimat

@shimat shimat commented Jul 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • Full AOT-compiling the app in Release currently crashes mono-aot-cross while precompiling OpenCvSharp.dll (native GC assertion, sgen-alloc.c:409) — see shimat/opencvsharp_blazor_sample#8. A minimal repro isolated the trigger to OpenCvSharp.dll's own P/Invoke surface (~3100 LibraryImport declarations), not native lib size or NativeFileReference in general — a tiny test app referencing the same large native .a but only 3 fake LibraryImport methods AOT-compiled fine.
  • Since the actual OpenCV computation happens in native C++ regardless of whether this thin C# marshalling layer is AOT-compiled or interpreted, this PR shadows the SDK's internal _WasmAotCompileApp target to exclude just OpenCvSharp.dll from the AOT set (it still ships as plain IL, executed by the interpreter at runtime) while the rest of the app gets full AOT.
  • RunAOTCompilation is back to true (default) for Release — was false since Add GitHub Pages deploy workflow #7, as a stopgap while full AOT was completely broken.

Test plan

Caveat

This shadows an internal, undocumented SDK target (_WasmAotCompileApp) by name — its shape may change in a future wasm-tools workload update. If a future SDK bump breaks this (build error, or the exclusion silently stops working), fall back to <RunAOTCompilation>False</RunAOTCompilation> for Release as before.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Performance
    • Enabled Ahead-of-Time (AOT) compilation for Release builds to improve application startup and runtime performance.
    • Added compatibility handling so OpenCvSharp continues to work correctly when AOT compilation is enabled.

shima and others added 3 commits July 11, 2026 23:36
…ot-cross crash

Shadows the SDK's internal _WasmAotCompileApp target to remove
OpenCvSharp.dll from the AOT input list, then re-adds it to the app's
assembly set afterward so it still ships (as plain IL, interpreted at
runtime instead of AOT-compiled). If this works, the rest of the app gets
full AOT while sidestepping the crash entirely - not waiting on an
upstream dotnet/runtime fix.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The partial-AOT exclusion experiment confirmed: 38 assemblies AOT-compile
successfully, OpenCvSharp.dll still ships as plain IL (verified in the
published output), no mono-aot-cross crash. Full app now gets AOT'd
except this one assembly, sidestepping the crash without waiting on an
upstream dotnet/runtime fix.

Temporarily add this branch to deploy-pages.yml's push trigger to verify
the full deploy pipeline end-to-end with AOT back on; will drop before
merging.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
build succeeded on this branch (run 29157608898) with RunAOTCompilation
back on and OpenCvSharp.dll excluded; deploy only failed due to the
github-pages environment's main-only protection rule, as expected.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Release builds now enable WebAssembly AOT compilation. MSBuild temporarily removes OpenCvSharp from the AOT assembly list during compilation, then restores it afterward.

Changes

AOT handling

Layer / File(s) Summary
Configure AOT assembly handling
BlazorApp/BlazorApp.csproj
Release enables RunAOTCompilation; new targets exclude OpenCvSharp before wasm AOT compilation and re-add it afterward.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • Issue #8 — Re-enables AOT while excluding OpenCvSharp to avoid its AOT compilation failure.

Poem

I’m a bunny with builds that now hop,
AOT runs while OpenCvSharp stops.
Removed for the flight,
Restored after the byte,
Clean wasm paths make my ears flop.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: re-enabling Release AOT while excluding only OpenCvSharp.dll.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch experiment/partial-aot-exclude-opencvsharp

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
BlazorApp/BlazorApp.csproj (1)

81-87: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Add a warning when OpenCvSharp is not found in the AOT assembly list.

If a future SDK update renames _WasmAssembliesInternal or changes its item metadata, _OpenCvSharpAssemblyToSkipAOT would be empty. The Message on line 86 would print "Excluding from AOT: " (nothing after the colon), which looks like success but means the workaround is silently inactive — OpenCvSharp would then be AOT'd and crash mono-aot-cross. Adding a conditional warning when the captured item is empty makes this failure mode loud instead of silent.

⚠️ Proposed fix: warn when the item is empty
   <Target Name="ExcludeOpenCvSharpFromAOT" BeforeTargets="_WasmAotCompileApp" Condition="'$(_WasmShouldAOT)' == 'true'">
     <ItemGroup>
       <_OpenCvSharpAssemblyToSkipAOT Include="@(_WasmAssembliesInternal)" Condition="'%(FileName)' == 'OpenCvSharp'" />
       <_WasmAssembliesInternal Remove="@(_OpenCvSharpAssemblyToSkipAOT)" />
     </ItemGroup>
-    <Message Importance="High" Text="Excluding from AOT: @(_OpenCvSharpAssemblyToSkipAOT)" />
+    <Message Importance="High" Text="Excluding from AOT: @(_OpenCvSharpAssemblyToSkipAOT)" Condition="'@(_OpenCvSharpAssemblyToSkipAOT)' != ''" />
+    <Warning Text="OpenCvSharp was not found in _WasmAssembliesInternal — the AOT exclusion workaround may be inactive. Check if the SDK changed the internal item name/metadata." Condition="'@(_OpenCvSharpAssemblyToSkipAOT)' == ''" />
   </Target>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@BlazorApp/BlazorApp.csproj` around lines 81 - 87, Update the
ExcludeOpenCvSharpFromAOT target to emit a warning when
_OpenCvSharpAssemblyToSkipAOT is empty, while preserving the existing
high-importance exclusion message and removal behavior when OpenCvSharp is
found. Use a condition on the warning so the inactive workaround is reported
clearly without adding an unconditional warning.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@BlazorApp/BlazorApp.csproj`:
- Around line 81-87: Update the ExcludeOpenCvSharpFromAOT target to emit a
warning when _OpenCvSharpAssemblyToSkipAOT is empty, while preserving the
existing high-importance exclusion message and removal behavior when OpenCvSharp
is found. Use a condition on the warning so the inactive workaround is reported
clearly without adding an unconditional warning.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6fc83de0-4571-407a-aa98-5849055eae72

📥 Commits

Reviewing files that changed from the base of the PR and between 028beb1 and 8efd32c.

📒 Files selected for processing (1)
  • BlazorApp/BlazorApp.csproj

@shimat shimat self-assigned this Jul 11, 2026
@shimat
shimat merged commit d003e86 into main Jul 11, 2026
1 check passed
@shimat
shimat deleted the experiment/partial-aot-exclude-opencvsharp branch July 12, 2026 02:42
shimat added a commit that referenced this pull request Jul 12, 2026
…cvsharp

Re-enable Release AOT by excluding only OpenCvSharp.dll
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