flutter/packages
Daco Harkes 3cb2f5f6a5
[native assets] Remove KernelSnapshot dependency in build (#168742)
The link hooks (`hook/link.dart`) in Flutter have no access to the
resource identifier experiment for tree-shaking yet. That means we can
start running hooks earlier in the flutter build.

When we do get around to adding tree-shaking information, we should only
have a dependency on `KernelSnapshot` for AOT builds in which the Dart
tree-shaker runs. Likely achieved by splitting the `DartBuildForNative`
into two targets, one for Debug and one for Release. (Note, the names
for these targets are somewhat weird, so we should address that in
another PR as well. It should probably be called `RunDartHooks` or
something.)

I don't expect this PR to have any performance effect for fast hooks.
Other targets already run concurrently with this target:

```
$ flutter build -d macos --verbose
[        ] [ +278 ms] compile_macos_framework: Starting due to {InvalidatedReasonKind.inputChanged: The following inputs have updated contents: /Users/dacoharkes/flt/flutter/examples/hello_world/.dart_tool/flutter_build/ce2ba8b9e7204bce6beba11f20d6df36/app.dill,/Users/dacoharkes/flt/flutter/packages/flutter_tools/lib/src/build_system/targets/macos.dart,/Users/dacoharkes/flt/flutter/bin/cache/engine.stamp}
[...]
[        ] [        ] dart_build: Starting due to {}
[        ] [  +20 ms] No packages with native assets. Skipping native assets compilation.
[        ] [   +1 ms] dart_build: Complete
[        ] [   +1 ms] install_code_assets: Starting due to {}
[        ] [   +1 ms] Writing native assets json to file:///Users/dacoharkes/flt/flutter/examples/hello_world/.dart_tool/flutter_build/ce2ba8b9e7204bce6beba11f20d6df36/native_assets.json.
[        ] [   +1 ms] Writing /Users/dacoharkes/flt/flutter/examples/hello_world/.dart_tool/flutter_build/ce2ba8b9e7204bce6beba11f20d6df36/native_assets.json done.
[        ] [        ] install_code_assets: Complete
[        ] [+1376 ms] Building App.framework for x86_64...
[...]
[        ] [  +41 ms] compile_macos_framework: Complete
```

However, this PR makes the hooks already run concurrently with kernel
compilation, which always takes quite a while.

```
[        ] [   +2 ms] kernel_snapshot_program: Starting due to {}
[...]
[        ] [+2515 ms] release_unpack_macos: Complete
[        ] [+2425 ms] kernel_snapshot_program: Complete
```

This means that if the hooks do actual work, and enough cores on the
host are available for Dart compilation and hook execution, the result
will be quicker than before.

### Context

* https://github.com/dart-lang/native/issues/2236

### Testing

Existing native assets integration tests

### Benchmarks

Currently _not_ benchmarked. This will be benchmarked by the `flutter
build` and flutter-time-to-first-frame benchmarks once the experiment
flag is removed.
2025-05-15 05:17:23 +00:00
..
flutter CupertinoSliverNavigationBar respects accessibility text scaling (#168866) 2025-05-15 02:28:18 +00:00
flutter_driver Roll pub packages (#168509) 2025-05-08 00:50:25 +00:00
flutter_goldens Increase pinned version of leak tracker to enable access to experimental tracking on web. (#167502) 2025-04-21 23:48:15 +00:00
flutter_localizations Update date localizations for ga (#168008) 2025-04-29 23:57:49 +00:00
flutter_test Reverts "Use live region in error text input decorator for Android (#165531)" (#168848) 2025-05-14 17:47:38 +00:00
flutter_tools [native assets] Remove KernelSnapshot dependency in build (#168742) 2025-05-15 05:17:23 +00:00
flutter_web_plugins Increase pinned version of leak tracker to enable access to experimental tracking on web. (#167502) 2025-04-21 23:48:15 +00:00
fuchsia_remote_debug_protocol Roll pub packages (#168509) 2025-05-08 00:50:25 +00:00
integration_test Roll pub packages (#168509) 2025-05-08 00:50:25 +00:00
analysis_options.yaml Update old wiki links (#149544) 2024-06-17 17:26:08 +00:00