Skip to content

Support standalone AOT compilation and embed resources in html_resources.g.dart - #4298

Merged
sigurdm merged 5 commits into
dart-lang:mainfrom
sigurdm:aot-resources-and-cli-util
Nov 2, 2026
Merged

sigurdm merged 5 commits into
dart-lang:mainfrom
sigurdm:aot-resources-and-cli-util

Conversation

@sigurdm

@sigurdm sigurdm commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Support compiling dartdoc to a standalone AOT executable (e.g. via dart install dartdoc or dart compile exe):

  • Resolve the Dart SDK and dart executable via package:cli_util (cli_util.sdkPath / cli_util.dartExecutable).
  • Avoid interpolating Platform.script.path into _dartdocFailedMessage (which in AOT mode resolves to a file:/// URI for the compiled binary).
  • Generate bundledResourcesBase64 in lib/src/generator/html_resources.g.dart via dart tool/task.dart build (buildResources), and fall back to decoding from html_resources.g.dart in ResourceLoader.loadResourceBytes when Isolate.resolvePackageUri returns null in AOT mode.

Part of dart-lang/sdk#63210
Part of dart-lang/sdk#63186

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for standalone AOT compilation in dartdoc by resolving the Dart SDK via package:cli_util and bundling lib/resources/ into a native asset compiled via hook/build.dart. Feedback on these changes suggests optimizing resource loading by caching the package URI resolution, avoiding the newly introduced C compiler dependency by utilizing a pure-Dart resource generation approach, avoiding fragile direct modifications to output.json in the build hook, and ensuring integration tests do not fail in environments lacking a C compiler.

Comment thread lib/src/generator/resource_loader.dart Resolved
Comment thread hook/build.dart Outdated
Comment on lines +11 to +12
void main(List<String> args) async {
await build(args, (input, output) async {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using hook/build.dart with CBuilder introduces a dependency on a C compiler (e.g., GCC, Clang, MSVC) for anyone compiling dartdoc to a standalone AOT executable (via dart build cli or dart install). This is a significant new requirement for a package that was previously pure Dart.

An alternative, pure-Dart approach would be to generate a Dart file containing the resource bytes (e.g., as base64-encoded strings or Uint8List literals) during development or as part of a code-generation step (similar to how html_resources.g.dart is generated). This would allow both JIT and AOT modes to load resources directly from Dart code without needing FFI, hook/build.dart, or a C compiler.

Comment thread hook/build.dart Outdated
Comment on lines +69 to +71
(output.json['dependencies'] as List<Object?>?)?.remove(
cFile.uri.toFilePath(),
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Modifying output.json directly to remove cFile from dependencies is fragile and relies on the internal JSON schema of BuildOutput, which is not guaranteed to be stable across minor/patch versions of package:native_assets_cli or package:hooks.

If the C-compilation approach is kept, it would be safer to check if there is a public API or if the dependency can be tolerated, rather than directly manipulating the underlying JSON map.

@szakarias szakarias left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks Sigurd — I agree this is a real problem, and the package:cli_util changes for locating the SDK look good to me.

I'm a bit hesitant about bundling the resources through a C build hook and FFI, though. It makes dart install dartdoc need a C compiler, adds hooks and native_toolchain_c as runtime dependencies of a package that ships in the SDK.

Let's have a quick chat before going further. Maybe we can explore some alternatives.

@sigurdm sigurdm changed the title Support standalone AOT compilation and bundle resources via hook/build.dart Support standalone AOT compilation and embed resources in html_resources.g.dart Nov 2, 2026
@sigurdm

sigurdm commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Good point — since dart tool/task.dart build already generates lib/src/generator/templates.aot_renderers_for_html.dart and lists lib/src/generator/html_resources.g.dart in _generatedFilesList, I replaced hook/build.dart with generating bundledResourcesBase64 directly into lib/src/generator/html_resources.g.dart during dart tool/task.dart build (and dropped hooks, native_toolchain_c, and dart:ffi). PTAL!

@szakarias szakarias left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, much better.

Comment thread pubspec.yaml
dartdoc: null

dependency_overrides:
cli_util: ^0.6.0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

could you perhaps add a short comment here on why the override is needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done — added a comment explaining that dev_dependency sass (via cli_pkg 2.16.0) still constrains cli_util to ^0.5.0 until cli_pkg 2.16.1 (google/dart_cli_pkg#268) is published.

@sigurdm
sigurdm merged commit cd8bf52 into dart-lang:main Nov 2, 2026
19 checks passed
copybara-service Bot pushed a commit to dart-lang/sdk that referenced this pull request Nov 12, 2026
Revisions updated by `dart tools/rev_sdk_deps.dart`.

dartdoc (https://github.com/dart-lang/dartdoc/compare/2f6847b..03ec6df):
  03ec6df6  Thu Nov 5 11:12:45 2026 +0200  Sergey G. Grekhov  Add tests for type parameters (dart-lang/dartdoc#4308)
  14a91302  Tue Nov 3 04:24:32 2026 +0100  Moritz  Migrate to ecosystem health publish check and setup-dart publish workflow (dart-lang/dartdoc#4310)
  cd8bf52c  Mon Nov 2 14:19:25 2026 +0100  Sigurd Meldgaard  Support standalone AOT compilation and embed resources in html_resources.g.dart (dart-lang/dartdoc#4298)
  cb1b1b2f  Mon Nov 2 14:39:28 2026 +0200  Sergey G. Grekhov  Add tests for parameters (dart-lang/dartdoc#4304)
  07506415  Mon Nov 2 12:14:22 2026 +0100  dependabot[bot]  Bump the github-actions group across 1 directory with 3 updates (dart-lang/dartdoc#4311)
  494aec7f  Mon Nov 2 12:14:05 2026 +0100  Sarah Zakarias  Add a "Documentation inherited from" note to inherited doc comments (dart-lang/dartdoc#4309)
  527502a9  Mon Nov 2 11:21:46 2026 +0100  Sarah Zakarias  Give the mock SDK the version of the SDK running the tests (dart-lang/dartdoc#4312)

http (https://github.com/dart-lang/http/compare/1f869d0..4646fe6):
  4646fe6  Thu Nov 5 02:41:04 2026 +0530  Chandra ObulaReddy  [http] Don't throw in RetryClient when `when` has read the response stream (dart-lang/http#2040)

native (https://github.com/dart-lang/native/compare/1838637..6287745):
  6287745ca  Thu Nov 5 20:37:11 2026 +0800  Dz  [hooks_runner] Fix UTF-8 decoding of hook output on Windows (dart-lang/native#3772)
  0eada93f9  Thu Nov 5 19:18:09 2026 +0800  Dz  [native_toolchain_c] Decode vswhere UTF-8 output correctly on Windows (dart-lang/native#3773)

Change-Id: If15b14dac054320ded19f0633a71b77463b9b718
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/574640
Auto-Submit: Nate Bosch <[email protected]>
Commit-Queue: Nicholas Shahan <[email protected]>
Reviewed-by: Nicholas Shahan <[email protected]>
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.

2 participants