Skip to content

Switch release publish to Native AOT#53

Merged
jamescrosswell merged 2 commits into
mainfrom
milestone-aot
May 31, 2026
Merged

Switch release publish to Native AOT#53
jamescrosswell merged 2 commits into
mainfrom
milestone-aot

Conversation

@jamescrosswell
Copy link
Copy Markdown
Contributor

Closes #42.

Summary

  • Release publish is now Native AOT — a 12MB native binary on osx-arm64 (vs 87MB self-contained single-file before). dotnet build/dotnet run are unaffected and still JIT.
  • IsAotCompatible=true on all src/ projects so trim/AOT analyzers run on every Debug build. Any regression breaks the build, not just publish.
  • One warning surfaced and is fixed: DefaultSettingsService.SaveKeybindings was hitting JsonArray.Add<T>(T) (RequiresUnreferencedCode + RequiresDynamicCode). Cast to JsonNode to pick the non-generic overload.
  • Drop unused Microsoft.Extensions.Hosting package reference. Only ServiceCollection from DI is used.

The risks the issue flagged didn't materialize: Terminal.Gui v2.1.0 and System.IO.Abstractions produce no AOT warnings.

Scope explicitly not in this PR

  • Wiring AOT into a release workflow — separate issue per AOT compilation for release binaries #42's plan.
  • AOT-compatible test framework investigation — filed as a separate issue. Tests still run under JIT here.

Release builds now publish as a single native binary (~12MB on
osx-arm64) instead of a 87MB self-contained single-file. Startup
no longer pays JIT cost — relevant for a TUI editor launched
frequently.

- `PublishAot=true` on TuiCode (only affects `dotnet publish`;
  `dotnet build`/`run` still JIT).
- `IsAotCompatible=true` on all src projects so trim/AOT
  analyzers run on every Debug build — regressions caught at
  compile time, not at publish time.
- Fix the one warning that surfaced: `JsonArray.Add(JsonNode?)`
  in `DefaultSettingsService.SaveKeybindings` instead of the
  generic `Add<T>(T)`, which is flagged RequiresUnreferencedCode
  + RequiresDynamicCode.
- Drop the unused `Microsoft.Extensions.Hosting` package
  reference (only `ServiceCollection` from DI is used).

Terminal.Gui v2.1.0 and System.IO.Abstractions produce no AOT
warnings. All 93 tests still pass; AOT publish is clean (0
warnings).

Tests still run under JIT — AOT-compatible test tooling will be
investigated separately.
`dotnet test` runs under JIT, so trim-stripped paths and missing
metadata only blow up against the published native binary —
classes of failure neither the JIT test suite nor the publish-time
analyzers catch.

- `--smoke` in Program.cs: hooks the first Iteration to call
  RequestStop, so the app boots through Application.Init, paints
  one frame, exits 0.
- CI workflow step publishes AOT for linux-x64 and runs the
  binary under `script` (pty allocation — TG needs a terminal)
  with a 20s timeout.

Validated locally: `script -q /dev/null TuiCode --smoke` returns
exit 0 with a full first paint in the log.
@jamescrosswell jamescrosswell marked this pull request as ready for review May 31, 2026 00:14
@jamescrosswell jamescrosswell merged commit ec21e90 into main May 31, 2026
2 checks passed
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.

AOT compilation for release binaries

1 participant