Skip to content

[NativeAOT] Remove std::format from host compilation - #12446

Merged
jonathanpeppers merged 4 commits into
mainfrom
dev/simonrozsival/nativeaot-remove-std-format
Aug 20, 2026
Merged

[NativeAOT] Remove std::format from host compilation#12446
jonathanpeppers merged 4 commits into
mainfrom
dev/simonrozsival/nativeaot-remove-std-format

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Aug 19, 2026

Copy link
Copy Markdown
Member

Summary

Remove <format> from the Android NativeAOT host compilation without changing CoreCLR-only implementations or introducing a string_view logging surface.

This is the next implementation step from #12139. Code compiled by both NativeAOT and CoreCLR uses the existing printf-style logging APIs, while CoreCLR-specific code keeps its current std::format implementation for the later libc++ removal effort.

Changes

  • add NativeAOT-specific lightweight logging and internal-pinvoke headers, selected through the existing NativeAOT include-path precedence;
  • migrate formatting only in host sources compiled by both NativeAOT and CoreCLR;
  • use printf precision for bounded shared messages instead of a string_view logging overload;
  • have shared host code depend directly on HostCommon instead of the CoreCLR-specific Host declaration;
  • allow the shared Android system header to resolve the host-specific logging surface;
  • preserve existing category filtering and message behavior.

No CoreCLR-only implementation files differ from main, and the PR introduces no new string_view usage.

Validation

  • built the arm64 Release NativeAOT and CoreCLR native targets;
  • confirmed the NativeAOT Ninja dependency graph contains no libc++ <format> header;
  • confirmed the NativeAOT static archive has no unresolved formatting, to_chars, locale, or charconv symbols;
  • confirmed the final PR diff contains no changes under CoreCLR-only implementations or common code not compiled by NativeAOT.

Keep the std::format logging surface available to CoreCLR while compiling it out of the NativeAOT host. Avoid pulling timing implementation headers into NativeAOT declarations and migrate the remaining shared call sites to printf or direct logging.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings August 19, 2026 15:15
@simonrozsival simonrozsival added drop-libcpp Work to remove the libc++ dependency from Android NativeAOT ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). copilot `copilot-cli` or other AIs were used to author this labels Aug 19, 2026

Copilot AI 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.

Pull request overview

This PR advances the NativeAOT host-dependency reduction work by compiling the std::format-based logging surface only for non-NativeAOT builds (CoreCLR), while migrating remaining NativeAOT-reachable logging to printf-style / direct logging and reducing timing-related header inclusion.

Changes:

  • Gate <format> / std::format macros & templates behind !XA_HOST_NATIVEAOT while keeping CoreCLR’s existing std::format logging surface.
  • Switch several call sites to *_f (printf-style) or log_write to avoid std::format usage in NativeAOT-reachable paths.
  • Avoid pulling full timing implementation into NativeAOT host declarations via conditional include and forward declarations.
Show a summary per file
File Description
src/native/clr/include/shared/log_types.hh Conditionalize <format> usage and logging macro/templates for non-NativeAOT builds; introduce a string_view log_write overload.
src/native/clr/include/runtime-base/internal-pinvokes.hh Avoid including timing headers for NativeAOT by forward-declaring managed_timing_sequence.
src/native/clr/include/host/host.hh Avoid timing include and timing accessor/state for NativeAOT builds.
src/native/clr/host/os-bridge.cc Replace non-printf logging calls with log_warnf for NativeAOT compatibility.
src/native/clr/host/internal-pinvokes-shared.cc Route managed log messages through log_write instead of format-based wrappers.
src/native/clr/host/gc-bridge.cc Replace std::format-surface logging with log_errorf.
src/native/clr/host/bridge-processing.cc Replace std::format-surface logging with log_errorf.

Review details

  • Files reviewed: 7/7 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread src/native/clr/include/shared/log_types.hh
Use the existing printf-style logging APIs throughout code shared by CoreCLR and NativeAOT. Keep timing implementation dependencies out of shared declarations so NativeAOT does not pull in libc++ formatting support.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 99f3f0fa-70d4-4920-a0e5-798643faac81
@simonrozsival simonrozsival changed the title [NativeAOT] Remove std::format from host compilation [Native] Remove std::format from shared CLR code Aug 19, 2026
Restore all CoreCLR-only implementation changes. Give NativeAOT lightweight logging and internal-pinvoke headers through its existing include-path precedence, and update only host code compiled by both runtimes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 99f3f0fa-70d4-4920-a0e5-798643faac81
@simonrozsival simonrozsival changed the title [Native] Remove std::format from shared CLR code [NativeAOT] Remove std::format from host compilation Aug 19, 2026
Keep the NativeAOT logging header limited to the printf-style declarations and log bounded shared messages directly with a precision specifier.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 99f3f0fa-70d4-4920-a0e5-798643faac81
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #12446

@github-actions github-actions 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.

Review summary

No actionable findings in the changed native host code. The NativeAOT compatibility headers and shared printf-style logging changes preserve the existing CoreCLR behavior and keep the host-specific include-path split intact.

CI is still in progress; all completed checks observed so far are passing.

Generated by Android PR Reviewer for #12446 · gpt56 · 141.2 AIC · ⌖ 17.3 AIC · ⊞ 25.7K
Comment /review to run again

@jonathanpeppers
jonathanpeppers merged commit 32d5f87 into main Aug 20, 2026
44 checks passed
@jonathanpeppers
jonathanpeppers deleted the dev/simonrozsival/nativeaot-remove-std-format branch August 20, 2026 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot `copilot-cli` or other AIs were used to author this drop-libcpp Work to remove the libc++ dependency from Android NativeAOT ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants